summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Target/AArch64/AArch64GISelAccessor.h33
-rw-r--r--llvm/lib/Target/AArch64/AArch64Subtarget.cpp12
-rw-r--r--llvm/lib/Target/AArch64/AArch64Subtarget.h13
-rw-r--r--llvm/lib/Target/AArch64/AArch64TargetMachine.cpp28
4 files changed, 80 insertions, 6 deletions
diff --git a/llvm/lib/Target/AArch64/AArch64GISelAccessor.h b/llvm/lib/Target/AArch64/AArch64GISelAccessor.h
new file mode 100644
index 00000000000..b5f22c7f380
--- /dev/null
+++ b/llvm/lib/Target/AArch64/AArch64GISelAccessor.h
@@ -0,0 +1,33 @@
+//===-- AArch64GISelAccessor.h - AArch64 GISel Accessor ---------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+/// This file declares the API to access the various APIs related
+/// to GlobalISel.
+//
+//===----------------------------------------------------------------------===/
+
+#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64GISELACCESSOR_H
+#define LLVM_LIB_TARGET_AARCH64_AARCH64GISELACCESSOR_H
+
+namespace llvm {
+class CallLowering;
+class RegisterBankInfo;
+
+/// The goal of this helper class is to gather the accessor to all
+/// the APIs related to GlobalISel.
+/// It should be derived to feature an actual accessor to the GISel APIs.
+/// The reason why this is not simply done into the subtarget is to avoid
+/// spreading ifdefs around.
+struct AArch64GISelAccessor {
+ virtual ~AArch64GISelAccessor() {}
+ virtual const CallLowering *getCallLowering() const { return nullptr;}
+ virtual const RegisterBankInfo *getRegBankInfo() const { return nullptr;}
+};
+} // End namespace llvm;
+#endif
diff --git a/llvm/lib/Target/AArch64/AArch64Subtarget.cpp b/llvm/lib/Target/AArch64/AArch64Subtarget.cpp
index f2c4569c553..72c16638cc6 100644
--- a/llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ b/llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -57,12 +57,16 @@ AArch64Subtarget::AArch64Subtarget(const Triple &TT, const std::string &CPU,
StrictAlign(false), ReserveX18(TT.isOSDarwin()), IsLittle(LittleEndian),
CPUString(CPU), TargetTriple(TT), FrameLowering(),
InstrInfo(initializeSubtargetDependencies(FS)), TSInfo(),
- TLInfo(TM, *this), CallLoweringInfo(nullptr) {}
+ TLInfo(TM, *this), GISelAccessor() {}
const CallLowering *AArch64Subtarget::getCallLowering() const {
- if (!CallLoweringInfo)
- CallLoweringInfo.reset(new AArch64CallLowering(TLInfo));
- return CallLoweringInfo.get();
+ assert(GISelAccessor && "Access to GlobalISel APIs not set");
+ return GISelAccessor->getCallLowering();
+}
+
+const RegisterBankInfo *AArch64Subtarget::getRegBankInfo() const {
+ assert(GISelAccessor && "Access to GlobalISel APIs not set");
+ return GISelAccessor->getRegBankInfo();
}
/// ClassifyGlobalReference - Find the target operand flags that describe
diff --git a/llvm/lib/Target/AArch64/AArch64Subtarget.h b/llvm/lib/Target/AArch64/AArch64Subtarget.h
index d33807adb15..32c4199ee85 100644
--- a/llvm/lib/Target/AArch64/AArch64Subtarget.h
+++ b/llvm/lib/Target/AArch64/AArch64Subtarget.h
@@ -14,8 +14,8 @@
#ifndef LLVM_LIB_TARGET_AARCH64_AARCH64SUBTARGET_H
#define LLVM_LIB_TARGET_AARCH64_AARCH64SUBTARGET_H
-#include "AArch64CallLowering.h"
#include "AArch64FrameLowering.h"
+#include "AArch64GISelAccessor.h"
#include "AArch64ISelLowering.h"
#include "AArch64InstrInfo.h"
#include "AArch64RegisterInfo.h"
@@ -82,7 +82,10 @@ protected:
AArch64InstrInfo InstrInfo;
AArch64SelectionDAGInfo TSInfo;
AArch64TargetLowering TLInfo;
- mutable std::unique_ptr<AArch64CallLowering> CallLoweringInfo;
+ /// Gather the accessor points to GlobalISel-related APIs.
+ /// This is used to avoid ifndefs spreading around while GISel is
+ /// an optional library.
+ std::unique_ptr<AArch64GISelAccessor> GISelAccessor;
private:
/// initializeSubtargetDependencies - Initializes using CPUString and the
@@ -97,6 +100,11 @@ public:
const std::string &FS, const TargetMachine &TM,
bool LittleEndian);
+ /// This object will take onwership of \p GISelAccessor.
+ void setGISelAccessor(AArch64GISelAccessor &GISelAccessor) {
+ this->GISelAccessor.reset(&GISelAccessor);
+ }
+
const AArch64SelectionDAGInfo *getSelectionDAGInfo() const override {
return &TSInfo;
}
@@ -111,6 +119,7 @@ public:
return &getInstrInfo()->getRegisterInfo();
}
const CallLowering *getCallLowering() const override;
+ const RegisterBankInfo *getRegBankInfo() const override;
const Triple &getTargetTriple() const { return TargetTriple; }
bool enableMachineScheduler() const override { return true; }
bool enablePostRAScheduler() const override {
diff --git a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
index a2638aacf94..9712d0ee88e 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -11,6 +11,8 @@
//===----------------------------------------------------------------------===//
#include "AArch64.h"
+#include "AArch64CallLowering.h"
+#include "AArch64RegisterBankInfo.h"
#include "AArch64TargetMachine.h"
#include "AArch64TargetObjectFile.h"
#include "AArch64TargetTransformInfo.h"
@@ -154,6 +156,21 @@ AArch64TargetMachine::AArch64TargetMachine(const Target &T, const Triple &TT,
AArch64TargetMachine::~AArch64TargetMachine() {}
+#ifdef LLVM_BUILD_GLOBAL_ISEL
+namespace {
+struct AArch64GISelActualAccessor : public AArch64GISelAccessor {
+ std::unique_ptr<CallLowering> CallLoweringInfo;
+ std::unique_ptr<RegisterBankInfo> RegBankInfo;
+ const CallLowering *getCallLowering() const override {
+ return CallLoweringInfo.get();
+ }
+ const RegisterBankInfo *getRegBankInfo() const override {
+ return RegBankInfo.get();
+ }
+};
+} // End anonymous namespace.
+#endif
+
const AArch64Subtarget *
AArch64TargetMachine::getSubtargetImpl(const Function &F) const {
Attribute CPUAttr = F.getFnAttribute("target-cpu");
@@ -174,6 +191,17 @@ AArch64TargetMachine::getSubtargetImpl(const Function &F) const {
resetTargetOptions(F);
I = llvm::make_unique<AArch64Subtarget>(TargetTriple, CPU, FS, *this,
isLittle);
+#ifndef LLVM_BUILD_GLOBAL_ISEL
+ AArch64GISelAccessor *GISelAccessor = new AArch64GISelAccessor();
+#else
+ AArch64GISelActualAccessor *GISelAccessor =
+ new AArch64GISelActualAccessor();
+ GISelAccessor->CallLoweringInfo.reset(
+ new AArch64CallLowering(*I->getTargetLowering()));
+ GISelAccessor->RegBankInfo.reset(
+ new AArch64RegisterBankInfo(*I->getRegisterInfo()));
+#endif
+ I->setGISelAccessor(*GISelAccessor);
}
return I.get();
}
OpenPOWER on IntegriCloud