LLVM 22.0.0git
XtensaTargetMachine.cpp
Go to the documentation of this file.
1//===- XtensaTargetMachine.cpp - Define TargetMachine for Xtensa ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
6// See https://llvm.org/LICENSE.txt for license information.
7// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8//
9//===----------------------------------------------------------------------===//
10//
11// Implements the info about Xtensa target spec.
12//
13//===----------------------------------------------------------------------===//
14
15#include "XtensaTargetMachine.h"
18#include "llvm/CodeGen/Passes.h"
22#include "llvm/PassRegistry.h"
24#include <optional>
25
26using namespace llvm;
27
34
36 std::optional<Reloc::Model> RM) {
37 if (!RM || JIT)
38 return Reloc::Static;
39 return *RM;
40}
41
43 StringRef CPU, StringRef FS,
45 std::optional<Reloc::Model> RM,
46 std::optional<CodeModel::Model> CM,
47 CodeGenOptLevel OL, bool JIT,
48 bool IsLittle)
49 : CodeGenTargetMachineImpl(T, TT.computeDataLayout(), TT, CPU, FS, Options,
51 getEffectiveCodeModel(CM, CodeModel::Small), OL),
52 TLOF(std::make_unique<TargetLoweringObjectFileELF>()) {
54}
55
57 StringRef CPU, StringRef FS,
59 std::optional<Reloc::Model> RM,
60 std::optional<CodeModel::Model> CM,
61 CodeGenOptLevel OL, bool JIT)
62 : XtensaTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT, true) {}
63
64const XtensaSubtarget *
66 Attribute CPUAttr = F.getFnAttribute("target-cpu");
67 Attribute FSAttr = F.getFnAttribute("target-features");
68
69 auto CPU = CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
70 auto FS = FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
71
72 auto &I = SubtargetMap[CPU + FS];
73 if (!I) {
74 // This needs to be done before we create a new subtarget since any
75 // creation will depend on the TM and the code generation flags on the
76 // function that reside in TargetOptions.
78 I = std::make_unique<XtensaSubtarget>(TargetTriple, CPU, FS, *this);
79 }
80 return I.get();
81}
82
89
90namespace {
91/// Xtensa Code Generator Pass Configuration Options.
92class XtensaPassConfig : public TargetPassConfig {
93public:
94 XtensaPassConfig(XtensaTargetMachine &TM, PassManagerBase &PM)
95 : TargetPassConfig(TM, PM) {}
96
97 XtensaTargetMachine &getXtensaTargetMachine() const {
99 }
100
101 bool addInstSelector() override;
102 void addIRPasses() override;
103 void addPreEmitPass() override;
104};
105} // end anonymous namespace
106
107bool XtensaPassConfig::addInstSelector() {
108 addPass(createXtensaISelDag(getXtensaTargetMachine(), getOptLevel()));
109 return false;
110}
111
112void XtensaPassConfig::addIRPasses() {
115}
116
117void XtensaPassConfig::addPreEmitPass() { addPass(&BranchRelaxationPassID); }
118
120 return new XtensaPassConfig(*this, PM);
121}
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#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)
Target-Independent Code Generator Pass Configuration Options pass.
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeXtensaTarget()
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
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...
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
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.
StringMap< std::unique_ptr< XtensaSubtarget > > SubtargetMap
XtensaTargetMachine(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, bool isLittle)
const XtensaSubtarget * getSubtargetImpl(const Function &F) const override
Virtual method implemented by subclasses that returns a reference to that target's TargetSubtargetInf...
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.
FunctionPass * createXtensaISelDag(XtensaTargetMachine &TM, CodeGenOptLevel OptLevel)
void initializeXtensaAsmPrinterPass(PassRegistry &)
static Reloc::Model getEffectiveRelocModel(std::optional< Reloc::Model > RM)
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.
LLVM_ABI char & BranchRelaxationPassID
BranchRelaxation - This pass replaces branches that need to jump further than is supported by a branc...
Target & getTheXtensaTarget()
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_ABI FunctionPass * createAtomicExpandLegacyPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
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,...