LLVM 22.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 <optional>
25
26using namespace llvm;
27
35
37 StringRef CPU, StringRef FS,
39 std::optional<Reloc::Model> RM,
40 std::optional<CodeModel::Model> CM,
41 CodeGenOptLevel OL, bool JIT)
42 : CodeGenTargetMachineImpl(T, TT.computeDataLayout(), TT, CPU, FS, Options,
43 RM.value_or(Reloc::Static),
44 getEffectiveCodeModel(CM, CodeModel::Small), OL),
45 TLOF(std::make_unique<CSKYELFTargetObjectFile>()) {
47}
48
49const CSKYSubtarget *
51 Attribute CPUAttr = F.getFnAttribute("target-cpu");
52 Attribute TuneAttr = F.getFnAttribute("tune-cpu");
53 Attribute FSAttr = F.getFnAttribute("target-features");
54
55 std::string CPU =
56 CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
57 std::string TuneCPU =
58 TuneAttr.isValid() ? TuneAttr.getValueAsString().str() : CPU;
59 std::string FS =
60 FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
61
62 std::string Key = CPU + TuneCPU + FS;
63 auto &I = SubtargetMap[Key];
64 if (!I) {
65 // This needs to be done before we create a new subtarget since any
66 // creation will depend on the TM and the code generation flags on the
67 // function that reside in TargetOptions.
69 I = std::make_unique<CSKYSubtarget>(TargetTriple, CPU, TuneCPU, FS, *this);
70 if (I->useHardFloat() && !I->hasAnyFloatExt())
71 errs() << "Hard-float can't be used with current CPU,"
72 " set to Soft-float\n";
73 }
74 return I.get();
75}
76
83
84namespace {
85class CSKYPassConfig : public TargetPassConfig {
86public:
87 CSKYPassConfig(CSKYTargetMachine &TM, PassManagerBase &PM)
88 : TargetPassConfig(TM, PM) {}
89
90 CSKYTargetMachine &getCSKYTargetMachine() const {
92 }
93
94 void addIRPasses() override;
95 bool addInstSelector() override;
96 void addPreEmitPass() override;
97};
98
99} // namespace
100
102 return new CSKYPassConfig(*this, PM);
103}
104
105void CSKYPassConfig::addIRPasses() {
108}
109
110bool CSKYPassConfig::addInstSelector() {
111 addPass(createCSKYISelDag(getCSKYTargetMachine(), getOptLevel()));
112
113 return false;
114}
115
116void CSKYPassConfig::addPreEmitPass() {
118}
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeCSKYTarget()
#define LLVM_EXTERNAL_VISIBILITY
Definition Compiler.h:132
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
#define T
const GCNTargetMachine & getTM(const GCNSubtarget *STI)
static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")
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:69
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:223
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:44
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
std::string str() const
str - Get the contents as an std::string.
Definition StringRef.h:233
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
std::unique_ptr< const MCSubtargetInfo > STI
TargetOptions Options
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
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:47
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.
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:82
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,...
FunctionPass * createCSKYISelDag(CSKYTargetMachine &TM, CodeGenOptLevel OptLevel)
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:851
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,...