Skip to content

Commit 3f7b4ce

Browse files
committed
[PowerPC] Add support for embedded devices with EFPU2
PowerPC cores like e200z759n3 [1] using an efpu2 only support single precision hardware floating point instructions. The single precision instructions efs* and evfs* are identical to the spe float instructions while efd* and evfd* instructions trigger a not implemented exception. This patch introduces a new command line option -mefpu2 which leads to single-hardware / double-software code generation. [1] Core reference: https://www.nxp.com/files-static/32bit/doc/ref_manual/e200z759CRM.pdf Differential revision: https://reviews.llvm.org/D92935
1 parent dd07d60 commit 3f7b4ce

File tree

9 files changed

+1338
-716
lines changed

9 files changed

+1338
-716
lines changed

clang/docs/ClangCommandLineReference.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3145,6 +3145,8 @@ PowerPC
31453145

31463146
.. option:: -mdirect-move, -mno-direct-move
31473147

3148+
.. option:: -mefpu2
3149+
31483150
.. option:: -mfloat128, -mno-float128
31493151

31503152
.. option:: -mfprnd, -mno-fprnd

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3040,6 +3040,7 @@ def mpcrel: Flag<["-"], "mpcrel">, Group<m_ppc_Features_Group>;
30403040
def mno_pcrel: Flag<["-"], "mno-pcrel">, Group<m_ppc_Features_Group>;
30413041
def mspe : Flag<["-"], "mspe">, Group<m_ppc_Features_Group>;
30423042
def mno_spe : Flag<["-"], "mno-spe">, Group<m_ppc_Features_Group>;
3043+
def mefpu2 : Flag<["-"], "mefpu2">, Group<m_ppc_Features_Group>;
30433044
def mabi_EQ_vec_extabi : Flag<["-"], "mabi=vec-extabi">, Group<m_Group>, Flags<[CC1Option]>,
30443045
HelpText<"Enable the extended Altivec ABI on AIX (AIX only). Uses volatile and nonvolatile vector registers">;
30453046
def mabi_EQ_vec_default : Flag<["-"], "mabi=vec-default">, Group<m_Group>, Flags<[CC1Option]>,

clang/lib/Basic/Targets/PPC.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ bool PPCTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
5656
HasP10Vector = true;
5757
} else if (Feature == "+pcrelative-memops") {
5858
HasPCRelativeMemops = true;
59-
} else if (Feature == "+spe") {
59+
} else if (Feature == "+spe" || Feature == "+efpu2") {
6060
HasSPE = true;
6161
LongDoubleWidth = LongDoubleAlign = 64;
6262
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
@@ -402,6 +402,8 @@ bool PPCTargetInfo::hasFeature(StringRef Feature) const {
402402
void PPCTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
403403
StringRef Name, bool Enabled) const {
404404
if (Enabled) {
405+
if (Name == "efpu2")
406+
Features["spe"] = true;
405407
// If we're enabling any of the vsx based features then enable vsx and
406408
// altivec. We'll diagnose any problems later.
407409
bool FeatureHasVSX = llvm::StringSwitch<bool>(Name)
@@ -425,6 +427,8 @@ void PPCTargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
425427
else
426428
Features[Name] = true;
427429
} else {
430+
if (Name == "spe")
431+
Features["efpu2"] = false;
428432
// If we're disabling altivec or vsx go ahead and disable all of the vsx
429433
// features.
430434
if ((Name == "altivec") || (Name == "vsx"))

clang/test/Driver/ppc-features.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@
155155
// CHECK-SPE: "-target-feature" "+spe"
156156
// CHECK-NOSPE: "-target-feature" "-spe"
157157

158+
// RUN: %clang -target powerpc %s -mefpu2 -c -### 2>&1 | FileCheck -check-prefix=CHECK-EFPU2 %s
159+
// CHECK-EFPU2: "-target-feature" "+efpu2"
160+
158161
// Assembler features
159162
// RUN: %clang -target powerpc-unknown-linux-gnu %s -### -o %t.o -no-integrated-as 2>&1 | FileCheck -check-prefix=CHECK_32_BE_AS_ARGS %s
160163
// CHECK_32_BE_AS_ARGS: "-mppc"

llvm/lib/Target/PowerPC/PPC.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ def FeatureAltivec : SubtargetFeature<"altivec","HasAltivec", "true",
7272
def FeatureSPE : SubtargetFeature<"spe","HasSPE", "true",
7373
"Enable SPE instructions",
7474
[FeatureHardFloat]>;
75+
def FeatureEFPU2 : SubtargetFeature<"efpu2", "HasEFPU2", "true",
76+
"Enable Embedded Floating-Point APU 2 instructions",
77+
[FeatureSPE]>;
7578
def FeatureMFOCRF : SubtargetFeature<"mfocrf","HasMFOCRF", "true",
7679
"Enable the MFOCRF instruction">;
7780
def FeatureFSqrt : SubtargetFeature<"fsqrt","HasFSQRT", "true",

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
151151
if (!useSoftFloat()) {
152152
if (hasSPE()) {
153153
addRegisterClass(MVT::f32, &PPC::GPRCRegClass);
154-
addRegisterClass(MVT::f64, &PPC::SPERCRegClass);
154+
// EFPU2 APU only supports f32
155+
if (!Subtarget.hasEFPU2())
156+
addRegisterClass(MVT::f64, &PPC::SPERCRegClass);
155157
} else {
156158
addRegisterClass(MVT::f32, &PPC::F4RCRegClass);
157159
addRegisterClass(MVT::f64, &PPC::F8RCRegClass);

llvm/lib/Target/PowerPC/PPCSubtarget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void PPCSubtarget::initializeEnvironment() {
7777
HasHardFloat = false;
7878
HasAltivec = false;
7979
HasSPE = false;
80+
HasEFPU2 = false;
8081
HasFPU = false;
8182
HasVSX = false;
8283
NeedsTwoConstNR = false;

llvm/lib/Target/PowerPC/PPCSubtarget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class PPCSubtarget : public PPCGenSubtargetInfo {
100100
bool HasAltivec;
101101
bool HasFPU;
102102
bool HasSPE;
103+
bool HasEFPU2;
103104
bool HasVSX;
104105
bool NeedsTwoConstNR;
105106
bool HasP8Vector;
@@ -257,6 +258,7 @@ class PPCSubtarget : public PPCGenSubtargetInfo {
257258
bool hasFPCVT() const { return HasFPCVT; }
258259
bool hasAltivec() const { return HasAltivec; }
259260
bool hasSPE() const { return HasSPE; }
261+
bool hasEFPU2() const { return HasEFPU2; }
260262
bool hasFPU() const { return HasFPU; }
261263
bool hasVSX() const { return HasVSX; }
262264
bool needsTwoConstNR() const { return NeedsTwoConstNR; }

0 commit comments

Comments
 (0)