[PATCH] D98674: Resolved a FIXME in PowerPC SubTarget

Anshil Gandhi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 15 17:53:32 PDT 2021


gandhi21299 created this revision.
gandhi21299 added reviewers: echristo, nemanjai.
Herald added subscribers: shchenz, kbarton, hiraditya.
gandhi21299 requested review of this revision.
Herald added a project: LLVM.

Added a member in PPCTargetMachine class which stores the endianness of the target. The endianness is detected from triple which is passed into the static function `getDataLayoutString()`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D98674

Files:
  llvm/lib/Target/PowerPC/PPCSubtarget.cpp
  llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
  llvm/lib/Target/PowerPC/PPCTargetMachine.h


Index: llvm/lib/Target/PowerPC/PPCTargetMachine.h
===================================================================
--- llvm/lib/Target/PowerPC/PPCTargetMachine.h
+++ 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<TargetLoweringObjectFile> TLOF;
   PPCABI TargetABI;
@@ -63,6 +65,8 @@
     // Addrspacecasts are always noops.
     return true;
   }
+
+  bool isLittleEndian() const;
 };
 } // end namespace llvm
 
Index: llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ 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<Reloc::Model> RM,
                                    Optional<CodeModel::Model> 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",
Index: llvm/lib/Target/PowerPC/PPCSubtarget.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCSubtarget.cpp
+++ 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; }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98674.330855.patch
Type: text/x-patch
Size: 3095 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210316/a1e477ab/attachment.bin>


More information about the llvm-commits mailing list