[llvm] 697f90e - [NFC] [PowerPC] Determine Endianness in PPCTargetMachine
Nemanja Ivanovic via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 19 18:22:30 PDT 2021
Author: Anshil Gandhi
Date: 2021-03-19T20:22:16-05:00
New Revision: 697f90ebfa7c48d61e7ed0d627b91f369b5014bd
URL: https://github.com/llvm/llvm-project/commit/697f90ebfa7c48d61e7ed0d627b91f369b5014bd
DIFF: https://github.com/llvm/llvm-project/commit/697f90ebfa7c48d61e7ed0d627b91f369b5014bd.diff
LOG: [NFC] [PowerPC] Determine Endianness in PPCTargetMachine
The TargetMachine uses the triple to determine endianness. Just
use that logic rather than replicating it in PPCSubtarget.
Differential revision: https://reviews.llvm.org/D98674
Added:
Modified:
llvm/lib/Target/PowerPC/PPCSubtarget.cpp
llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
llvm/lib/Target/PowerPC/PPCTargetMachine.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/PowerPC/PPCSubtarget.cpp b/llvm/lib/Target/PowerPC/PPCSubtarget.cpp
index bf98ea8a01d0..51c80e14398c 100644
--- a/llvm/lib/Target/PowerPC/PPCSubtarget.cpp
+++ b/llvm/lib/Target/PowerPC/PPCSubtarget.cpp
@@ -182,9 +182,7 @@ void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
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.cpp b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
index 47fe65640417..32b19d5ddd10 100644
--- a/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
+++ b/llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -126,13 +126,17 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializePowerPCTarget() {
initializeGlobalISel(PR);
}
+static bool isLittleEndianTriple(const Triple &T) {
+ return T.getArch() == Triple::ppc64le || T.getArch() == Triple::ppcle;
+}
+
/// Return the datalayout string of a subtarget.
static std::string getDataLayoutString(const Triple &T) {
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 (isLittleEndianTriple(T))
Ret = "e";
else
Ret = "E";
@@ -317,7 +321,8 @@ PPCTargetMachine::PPCTargetMachine(const Target &T, const Triple &TT,
getEffectiveRelocModel(TT, RM),
getEffectivePPCCodeModel(TT, CM, JIT), OL),
TLOF(createTLOF(getTargetTriple())),
- TargetABI(computeTargetABI(TT, Options)) {
+ TargetABI(computeTargetABI(TT, Options)),
+ Endianness(isLittleEndianTriple(TT) ? Endian::LITTLE : Endian::BIG) {
initAsmInfo();
}
@@ -540,6 +545,12 @@ PPCTargetMachine::getTargetTransformInfo(const Function &F) {
return TargetTransformInfo(PPCTTIImpl(this, F));
}
+bool PPCTargetMachine::isLittleEndian() const {
+ assert(Endianness != Endian::NOT_DETECTED &&
+ "Unable to determine endianness");
+ return Endianness == Endian::LITTLE;
+}
+
static MachineSchedRegistry
PPCPreRASchedRegistry("ppc-prera",
"Run PowerPC PreRA specific scheduler",
diff --git a/llvm/lib/Target/PowerPC/PPCTargetMachine.h b/llvm/lib/Target/PowerPC/PPCTargetMachine.h
index 21faa4e710e3..ed9e74b72d1e 100644
--- a/llvm/lib/Target/PowerPC/PPCTargetMachine.h
+++ b/llvm/lib/Target/PowerPC/PPCTargetMachine.h
@@ -25,9 +25,12 @@ namespace llvm {
class PPCTargetMachine final : public LLVMTargetMachine {
public:
enum PPCABI { PPC_ABI_UNKNOWN, PPC_ABI_ELFv1, PPC_ABI_ELFv2 };
+ enum Endian { NOT_DETECTED, LITTLE, BIG };
+
private:
std::unique_ptr<TargetLoweringObjectFile> TLOF;
PPCABI TargetABI;
+ Endian Endianness = Endian::NOT_DETECTED;
mutable StringMap<std::unique_ptr<PPCSubtarget>> SubtargetMap;
@@ -63,6 +66,8 @@ class PPCTargetMachine final : public LLVMTargetMachine {
// Addrspacecasts are always noops.
return true;
}
+
+ bool isLittleEndian() const;
};
} // end namespace llvm
More information about the llvm-commits
mailing list