LLVM 20.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"
23#include <optional>
24
25using namespace llvm;
26
28 // Register the target.
30}
31
32static std::string computeDataLayout(const Triple &TT, StringRef CPU,
34 bool IsLittle) {
35 std::string Ret = "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32";
36 return Ret;
37}
38
40 std::optional<Reloc::Model> RM) {
41 if (!RM || JIT)
42 return Reloc::Static;
43 return *RM;
44}
45
47 StringRef CPU, StringRef FS,
49 std::optional<Reloc::Model> RM,
50 std::optional<CodeModel::Model> CM,
51 CodeGenOptLevel OL, bool JIT,
52 bool IsLittle)
54 TT, CPU, FS, Options,
56 getEffectiveCodeModel(CM, CodeModel::Small), OL),
57 TLOF(std::make_unique<TargetLoweringObjectFileELF>()) {
59}
60
62 StringRef CPU, StringRef FS,
64 std::optional<Reloc::Model> RM,
65 std::optional<CodeModel::Model> CM,
66 CodeGenOptLevel OL, bool JIT)
67 : XtensaTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT, true) {}
68
69const XtensaSubtarget *
71 Attribute CPUAttr = F.getFnAttribute("target-cpu");
72 Attribute FSAttr = F.getFnAttribute("target-features");
73
74 auto CPU = CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
75 auto FS = FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
76
77 auto &I = SubtargetMap[CPU + FS];
78 if (!I) {
79 // This needs to be done before we create a new subtarget since any
80 // creation will depend on the TM and the code generation flags on the
81 // function that reside in TargetOptions.
83 I = std::make_unique<XtensaSubtarget>(TargetTriple, CPU, FS, *this);
84 }
85 return I.get();
86}
87
89 BumpPtrAllocator &Allocator, const Function &F,
90 const TargetSubtargetInfo *STI) const {
91 return XtensaMachineFunctionInfo::create<XtensaMachineFunctionInfo>(Allocator,
92 F, STI);
93}
94
95namespace {
96/// Xtensa Code Generator Pass Configuration Options.
97class XtensaPassConfig : public TargetPassConfig {
98public:
99 XtensaPassConfig(XtensaTargetMachine &TM, PassManagerBase &PM)
100 : TargetPassConfig(TM, PM) {}
101
102 XtensaTargetMachine &getXtensaTargetMachine() const {
103 return getTM<XtensaTargetMachine>();
104 }
105
106 bool addInstSelector() override;
107 void addPreEmitPass() override;
108};
109} // end anonymous namespace
110
111bool XtensaPassConfig::addInstSelector() {
112 addPass(createXtensaISelDag(getXtensaTargetMachine(), getOptLevel()));
113 return false;
114}
115
116void XtensaPassConfig::addPreEmitPass() { addPass(&BranchRelaxationPassID); }
117
119 return new XtensaPassConfig(*this, PM);
120}
basic Basic Alias true
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:128
static LVOptions Options
Definition: LVOptions.cpp:25
static std::string computeDataLayout()
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
Basic Register Allocator
Target-Independent Code Generator Pass Configuration Options pass.
static Reloc::Model getEffectiveRelocModel(bool JIT, std::optional< Reloc::Model > RM)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeXtensaTarget()
StringRef getValueAsString() const
Return the attribute's value as a string.
Definition: Attributes.cpp:392
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition: Attributes.h:208
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
implements a set of functionality in the TargetMachine class for targets that make use of the indepen...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:229
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
Definition: TargetMachine.h:96
std::string TargetFS
Definition: TargetMachine.h:98
std::string TargetCPU
Definition: TargetMachine.h:97
std::unique_ptr< const MCSubtargetInfo > STI
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
Target-Independent Code Generator Pass Configuration Options.
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:44
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.
Definition: AddressRanges.h:18
FunctionPass * createXtensaISelDag(XtensaTargetMachine &TM, CodeGenOptLevel OptLevel)
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.
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:54
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
RegisterTargetMachine - Helper template for registering a target machine implementation,...