LLVM 24.0.0git
CSKYTargetMachine.cpp
Go to the documentation of this file.
1//===--- CSKYTargetMachine.cpp - Define TargetMachine for CSKY ------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Implements the info about CSKY target spec.
10//
11//===----------------------------------------------------------------------===//
12
13#include "CSKYTargetMachine.h"
14#include "CSKY.h"
16#include "CSKYSubtarget.h"
23#include "llvm/IR/Module.h"
25#include <optional>
26
27using namespace llvm;
28
36
38 StringRef CPU, StringRef FS,
40 std::optional<Reloc::Model> RM,
41 std::optional<CodeModel::Model> CM,
42 CodeGenOptLevel OL, bool JIT)
43 : CodeGenTargetMachineImpl(T, TT.computeDataLayout(), TT, CPU, FS, Options,
44 RM.value_or(Reloc::Static),
45 getEffectiveCodeModel(CM, CodeModel::Small), OL),
46 TLOF(std::make_unique<CSKYELFTargetObjectFile>()) {
48}
49
50const CSKYSubtarget *
52 Attribute CPUAttr = F.getFnAttribute("target-cpu");
53 Attribute TuneAttr = F.getFnAttribute("tune-cpu");
54 Attribute FSAttr = F.getFnAttribute("target-features");
55
56 std::string CPU =
57 CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
58 std::string TuneCPU =
59 TuneAttr.isValid() ? TuneAttr.getValueAsString().str() : CPU;
60 std::string FS =
61 FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
62
63 FloatABI::ABIType FloatABI = F.getParent()->getFloatABI();
65 FloatABI = Options.FloatABIType;
66
67 std::string Key = CPU + TuneCPU + FS;
68 Key += FloatABI == FloatABI::Hard ? "+hard-float-abi" : "+soft-float-abi";
69 auto &I = SubtargetMap[Key];
70 if (!I) {
71 I = std::make_unique<CSKYSubtarget>(TargetTriple, CPU, TuneCPU, FS,
72 FloatABI, *this);
73 if (I->useHardFloat() && !I->hasAnyFloatExt())
74 errs() << "Hard-float can't be used with current CPU,"
75 " set to Soft-float\n";
76 }
77 return I.get();
78}
79
86
87namespace {
88class CSKYPassConfig : public TargetPassConfig {
89public:
90 CSKYPassConfig(CSKYTargetMachine &TM, PassManagerBase &PM)
91 : TargetPassConfig(TM, PM) {}
92
93 CSKYTargetMachine &getCSKYTargetMachine() const {
95 }
96
97 void addIRPasses() override;
98 bool addInstSelector() override;
99 void addPreEmitPass() override;
100};
101
102} // namespace
103
105 return new CSKYPassConfig(*this, PM);
106}
107
108void CSKYPassConfig::addIRPasses() {
111}
112
113bool CSKYPassConfig::addInstSelector() {
114 addPass(createCSKYISelDag(getCSKYTargetMachine(), getOptLevel()));
115
116 return false;
117}
118
119void CSKYPassConfig::addPreEmitPass() {
121}
#define X(NUM, ENUM, NAME)
Definition ELF.h:856
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeCSKYTarget()
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define T
const GCNTargetMachine & getTM(const GCNSubtarget *STI)
Target-Independent Code Generator Pass Configuration Options pass.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
Definition Attributes.h:105
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition Attributes.h:261
const CSKYSubtarget * getSubtargetImpl() const =delete
CSKYTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOptLevel OL, bool JIT)
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override
Create the target's instance of MachineFunctionInfo.
CodeGenTargetMachineImpl(const Target &T, StringRef DataLayoutString, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOptLevel OL)
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
A global registry used in conjunction with static constructors to make pluggable components (like tar...
Definition Registry.h:116
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
std::string str() const
Get the contents as an std::string.
Definition StringRef.h:222
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
std::unique_ptr< const MCSubtargetInfo > STI
TargetOptions Options
Target-Independent Code Generator Pass Configuration Options.
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
TargetSubtargetInfo - Generic base class for all target subtargets.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
This is an optimization pass for GlobalISel generic memory operations.
void initializeCSKYDAGToDAGISelLegacyPass(PassRegistry &)
void initializeCSKYConstantIslandsPass(PassRegistry &)
CodeModel::Model getEffectiveCodeModel(std::optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value.
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:149
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Target & getTheCSKYTarget()
FunctionPass * createCSKYConstantIslandPass()
Returns a pass that converts branches to long branches.
LLVM_ABI FunctionPass * createAtomicExpandLegacyPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:390
FunctionPass * createCSKYISelDag(CSKYTargetMachine &TM, CodeGenOptLevel OptLevel)
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
static FuncInfoTy * create(BumpPtrAllocator &Allocator, const Function &F, const SubtargetTy *STI)
Factory function: default behavior is to call new using the supplied allocator.
RegisterTargetMachine - Helper template for registering a target machine implementation,...