forked from OSchip/llvm-project
[AArch64] Teach the subtarget how to get to the RegisterBankInfo.
Rework the access to GlobalISel APIs to contain how much of the APIs we need to access for the final executable to build when GlobalISel is not built. This prevents massive usage of ifdefs in various places. Now, all the GlobalISel ifdefs will be happing only in AArch64TargetMachine.cpp. llvm-svn: 265567
This commit is contained in:
parent
33fd854584
commit
c17f744001
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue