diff --git a/llvm/lib/Target/PowerPC/PPCSubtarget.cpp b/llvm/lib/Target/PowerPC/PPCSubtarget.cpp --- a/llvm/lib/Target/PowerPC/PPCSubtarget.cpp +++ b/llvm/lib/Target/PowerPC/PPCSubtarget.cpp @@ -182,9 +182,7 @@ StackAlignment = getPlatformStackAlignment(); // Determine endianness. - // FIXME: Part of the TargetMachine. - IsLittleEndian = (TargetTriple.getArch() == Triple::ppc64le || - TargetTriple.getArch() == Triple::ppcle); + IsLittleEndian = TM.isLittleEndian(); } bool PPCSubtarget::enableMachineScheduler() const { return true; } diff --git a/llvm/lib/Target/PowerPC/PPCTargetMachine.h b/llvm/lib/Target/PowerPC/PPCTargetMachine.h --- a/llvm/lib/Target/PowerPC/PPCTargetMachine.h +++ b/llvm/lib/Target/PowerPC/PPCTargetMachine.h @@ -25,6 +25,8 @@ class PPCTargetMachine final : public LLVMTargetMachine { public: enum PPCABI { PPC_ABI_UNKNOWN, PPC_ABI_ELFv1, PPC_ABI_ELFv2 }; + enum Endian { NOT_DETECTED, LITTLE, BIG }; + Endian Endianness = Endian::NOT_DETECTED; private: std::unique_ptr TLOF; PPCABI TargetABI; @@ -63,6 +65,8 @@ // Addrspacecasts are always noops. return true; } + + bool isLittleEndian() const; }; } // end namespace llvm diff --git a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp --- a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp +++ b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp @@ -127,15 +127,20 @@ } /// Return the datalayout string of a subtarget. -static std::string getDataLayoutString(const Triple &T) { +static std::string getDataLayoutString(const Triple &T, + PPCTargetMachine *TM) { bool is64Bit = T.getArch() == Triple::ppc64 || T.getArch() == Triple::ppc64le; std::string Ret; // Most PPC* platforms are big endian, PPC(64)LE is little endian. - if (T.getArch() == Triple::ppc64le || T.getArch() == Triple::ppcle) + if (T.getArch() == Triple::ppc64le || T.getArch() == Triple::ppcle){ Ret = "e"; - else + TM->Endianness = TM->Endian::LITTLE; + } + else{ Ret = "E"; + TM->Endianness = TM->Endian::BIG; + } Ret += DataLayout::getManglingComponent(T); @@ -312,7 +317,7 @@ Optional RM, Optional CM, CodeGenOpt::Level OL, bool JIT) - : LLVMTargetMachine(T, getDataLayoutString(TT), TT, CPU, + : LLVMTargetMachine(T, getDataLayoutString(TT, this), TT, CPU, computeFSAdditions(FS, OL, TT), Options, getEffectiveRelocModel(TT, RM), getEffectivePPCCodeModel(TT, CM, JIT), OL), @@ -540,6 +545,10 @@ return TargetTransformInfo(PPCTTIImpl(this, F)); } +bool PPCTargetMachine::isLittleEndian() const { + return Endianness == Endian::LITTLE; +} + static MachineSchedRegistry PPCPreRASchedRegistry("ppc-prera", "Run PowerPC PreRA specific scheduler",