diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2022-03-20 11:40:34 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2022-05-14 11:43:05 +0000 |
commit | 349cc55c9796c4596a5b9904cd3281af295f878f (patch) | |
tree | 410c5a785075730a35f1272ca6a7adf72222ad03 /contrib/llvm-project/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp | |
parent | cb2ae6163174b90e999326ecec3699ee093a5d43 (diff) | |
parent | c0981da47d5696fe36474fcf86b4ce03ae3ff818 (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp index 1c13796e84b6..8f61feb6506d 100644 --- a/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp +++ b/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp @@ -11,10 +11,13 @@ //===----------------------------------------------------------------------===// #include "CSKYTargetMachine.h" +#include "CSKY.h" +#include "CSKYSubtarget.h" #include "TargetInfo/CSKYTargetInfo.h" #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" #include "llvm/CodeGen/TargetPassConfig.h" -#include "llvm/Support/TargetRegistry.h" +#include "llvm/CodeGen/TargetSubtargetInfo.h" +#include "llvm/MC/TargetRegistry.h" using namespace llvm; @@ -50,6 +53,34 @@ CSKYTargetMachine::CSKYTargetMachine(const Target &T, const Triple &TT, initAsmInfo(); } +const CSKYSubtarget * +CSKYTargetMachine::getSubtargetImpl(const Function &F) const { + Attribute CPUAttr = F.getFnAttribute("target-cpu"); + Attribute TuneAttr = F.getFnAttribute("tune-cpu"); + Attribute FSAttr = F.getFnAttribute("target-features"); + + std::string CPU = + CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU; + std::string TuneCPU = + TuneAttr.isValid() ? TuneAttr.getValueAsString().str() : CPU; + std::string FS = + FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS; + + std::string Key = CPU + TuneCPU + FS; + auto &I = SubtargetMap[Key]; + if (!I) { + // This needs to be done before we create a new subtarget since any + // creation will depend on the TM and the code generation flags on the + // function that reside in TargetOptions. + resetTargetOptions(F); + I = std::make_unique<CSKYSubtarget>(TargetTriple, CPU, TuneCPU, FS, *this); + if (I->useHardFloat() && !I->hasAnyFloatExt()) + errs() << "Hard-float can't be used with current CPU," + " set to Soft-float\n"; + } + return I.get(); +} + namespace { class CSKYPassConfig : public TargetPassConfig { public: @@ -59,6 +90,8 @@ public: CSKYTargetMachine &getCSKYTargetMachine() const { return getTM<CSKYTargetMachine>(); } + + bool addInstSelector() override; }; } // namespace @@ -66,3 +99,9 @@ public: TargetPassConfig *CSKYTargetMachine::createPassConfig(PassManagerBase &PM) { return new CSKYPassConfig(*this, PM); } + +bool CSKYPassConfig::addInstSelector() { + addPass(createCSKYISelDag(getCSKYTargetMachine())); + + return false; +} |