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"
24#include "llvm/IR/Module.h"
26#include <optional>
27
28using namespace llvm;
29
37
39 StringRef CPU, StringRef FS,
41 std::optional<Reloc::Model> RM,
42 std::optional<CodeModel::Model> CM,
43 CodeGenOptLevel OL, bool JIT)
44 : CodeGenTargetMachineImpl(T, TT, CPU, FS, Options,
45 RM.value_or(Reloc::Static),
46 getEffectiveCodeModel(CM, CodeModel::Small), OL),
47 TLOF(std::make_unique<CSKYELFTargetObjectFile>()) {
49}
50
51const CSKYSubtarget *
53 AttributeSet FnAttrs = F.getAttributes().getFnAttrs();
54 const Module *M = F.getParent();
55 if (const CSKYSubtarget *ST = LastSubtarget.lookup(FnAttrs, M))
56 return ST;
57
58 SubtargetAttrs Attrs;
59 Attrs.CPU = FnAttrs.getAttribute("target-cpu");
60 Attrs.TuneCPU = FnAttrs.getAttribute("tune-cpu");
61 Attrs.FS = FnAttrs.getAttribute("target-features");
62 Attrs.FloatABI = M->getFloatABI();
63
64 if (const CSKYSubtarget *ST = LastSubtarget.lookup(FnAttrs, M, Attrs))
65 return ST;
66
67 StringRef CPU =
68 Attrs.CPU.isValid() ? Attrs.CPU.getValueAsString() : StringRef(TargetCPU);
69 StringRef TuneCPU =
70 Attrs.TuneCPU.isValid() ? Attrs.TuneCPU.getValueAsString() : CPU;
71 StringRef FS =
72 Attrs.FS.isValid() ? Attrs.FS.getValueAsString() : StringRef(TargetFS);
73
74 SmallString<256> Key({CPU, TuneCPU, FS});
75 Key +=
76 Attrs.FloatABI == FloatABI::Hard ? "+hard-float-abi" : "+soft-float-abi";
77 std::unique_ptr<CSKYSubtarget> &I = SubtargetMap[Key];
78 if (!I) {
79 I = std::make_unique<CSKYSubtarget>(TargetTriple, CPU, TuneCPU, FS,
80 Attrs.FloatABI, *this);
81 if (I->useHardFloat() && !I->hasAnyFloatExt())
82 errs() << "Hard-float can't be used with current CPU,"
83 " set to Soft-float\n";
84 }
85 LastSubtarget.set(FnAttrs, M, Attrs, I.get());
86 return I.get();
87}
88
95
96namespace {
97class CSKYPassConfig : public TargetPassConfig {
98public:
99 CSKYPassConfig(CSKYTargetMachine &TM, PassManagerBase &PM)
100 : TargetPassConfig(TM, PM) {}
101
102 CSKYTargetMachine &getCSKYTargetMachine() const {
104 }
105
106 void addIRPasses() override;
107 bool addInstSelector() override;
108 void addPreEmitPass() override;
109};
110
111} // namespace
112
114 return new CSKYPassConfig(*this, PM);
115}
116
117void CSKYPassConfig::addIRPasses() {
120}
121
122bool CSKYPassConfig::addInstSelector() {
123 addPass(createCSKYISelDag(getCSKYTargetMachine(), getOptLevel()));
124
125 return false;
126}
127
128void CSKYPassConfig::addPreEmitPass() {
130}
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
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)
This file defines the SmallString class.
Target-Independent Code Generator Pass Configuration Options pass.
This class holds the attributes for a particular argument, parameter, function, or return value.
Definition Attributes.h:448
LLVM_ABI Attribute getAttribute(Attribute::AttrKind Kind) const
Return the attribute object.
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, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Reloc::Model RM, CodeModel::Model CM, CodeGenOptLevel OL)
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
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
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition SmallString.h:28
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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:280
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:391
FunctionPass * createCSKYISelDag(CSKYTargetMachine &TM, CodeGenOptLevel OptLevel)
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
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,...