LLVM 24.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"
19#include "llvm/CodeGen/Passes.h"
23#include "llvm/PassRegistry.h"
25#include <optional>
26
27using namespace llvm;
28
35
37 std::optional<Reloc::Model> RM) {
38 if (!RM || JIT)
39 return Reloc::Static;
40 return *RM;
41}
42
44 StringRef CPU, StringRef FS,
46 std::optional<Reloc::Model> RM,
47 std::optional<CodeModel::Model> CM,
48 CodeGenOptLevel OL, bool JIT,
49 bool IsLittle)
50 : CodeGenTargetMachineImpl(T, TT, CPU, FS, Options,
52 getEffectiveCodeModel(CM, CodeModel::Small), OL),
53 TLOF(std::make_unique<TargetLoweringObjectFileELF>()) {
55}
56
58 StringRef CPU, StringRef FS,
60 std::optional<Reloc::Model> RM,
61 std::optional<CodeModel::Model> CM,
62 CodeGenOptLevel OL, bool JIT)
63 : XtensaTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT, true) {}
64
65const XtensaSubtarget *
67 AttributeSet FnAttrs = F.getAttributes().getFnAttrs();
68 const Module *M = F.getParent();
69 if (const XtensaSubtarget *ST = LastSubtarget.lookup(FnAttrs, M))
70 return ST;
71
72 SubtargetAttrs Attrs;
73 Attrs.CPU = FnAttrs.getAttribute("target-cpu");
74 Attrs.FS = FnAttrs.getAttribute("target-features");
75
76 if (const XtensaSubtarget *ST = LastSubtarget.lookup(FnAttrs, M, Attrs))
77 return ST;
78
79 StringRef CPU =
80 Attrs.CPU.isValid() ? Attrs.CPU.getValueAsString() : StringRef(TargetCPU);
81 StringRef FS =
82 Attrs.FS.isValid() ? Attrs.FS.getValueAsString() : StringRef(TargetFS);
83
84 SmallString<256> Key({CPU, FS});
85 std::unique_ptr<XtensaSubtarget> &I = SubtargetMap[Key];
86 if (!I)
87 I = std::make_unique<XtensaSubtarget>(TargetTriple, CPU, FS, *this);
88 LastSubtarget.set(FnAttrs, M, Attrs, I.get());
89 return I.get();
90}
91
98
99namespace {
100/// Xtensa Code Generator Pass Configuration Options.
101class XtensaPassConfig : public TargetPassConfig {
102public:
103 XtensaPassConfig(XtensaTargetMachine &TM, PassManagerBase &PM)
104 : TargetPassConfig(TM, PM) {}
105
106 XtensaTargetMachine &getXtensaTargetMachine() const {
108 }
109
110 bool addInstSelector() override;
111 void addIRPasses() override;
112 void addPreEmitPass() override;
113};
114} // end anonymous namespace
115
116bool XtensaPassConfig::addInstSelector() {
117 addPass(createXtensaISelDag(getXtensaTargetMachine(), getOptLevel()));
118 return false;
119}
120
121void XtensaPassConfig::addIRPasses() {
124}
125
126void XtensaPassConfig::addPreEmitPass() { addPass(&BranchRelaxationPassID); }
127
129 return new XtensaPassConfig(*this, PM);
130}
static Reloc::Model getEffectiveRelocModel()
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: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.
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeXtensaTarget()
This class holds the attributes for a particular argument, parameter, function, or return value.
Definition Attributes.h:445
LLVM_ABI Attribute getAttribute(Attribute::AttrKind Kind) const
Return the attribute object.
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...
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
LastSubtargetCache< XtensaSubtarget, SubtargetAttrs > LastSubtarget
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()
CodeGenOptLevel
Code generation optimization level.
Definition CodeGen.h:280
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
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
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,...
The attributes that select a subtarget.