LLVM 19.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"
17#include "llvm/CodeGen/Passes.h"
22#include <optional>
23
24using namespace llvm;
25
27 // Register the target.
29}
30
31static std::string computeDataLayout(const Triple &TT, StringRef CPU,
33 bool IsLittle) {
34 std::string Ret = "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32";
35 return Ret;
36}
37
39 std::optional<Reloc::Model> RM) {
40 if (!RM || JIT)
41 return Reloc::Static;
42 return *RM;
43}
44
46 StringRef CPU, StringRef FS,
48 std::optional<Reloc::Model> RM,
49 std::optional<CodeModel::Model> CM,
50 CodeGenOptLevel OL, bool JIT,
51 bool IsLittle)
52 : LLVMTargetMachine(T, computeDataLayout(TT, CPU, Options, IsLittle), TT,
53 CPU, FS, Options, getEffectiveRelocModel(JIT, RM),
54 getEffectiveCodeModel(CM, CodeModel::Small), OL),
55 TLOF(std::make_unique<TargetLoweringObjectFileELF>()) {
57}
58
60 StringRef CPU, StringRef FS,
62 std::optional<Reloc::Model> RM,
63 std::optional<CodeModel::Model> CM,
64 CodeGenOptLevel OL, bool JIT)
65 : XtensaTargetMachine(T, TT, CPU, FS, Options, RM, CM, OL, JIT, true) {}
66
67const XtensaSubtarget *
69 Attribute CPUAttr = F.getFnAttribute("target-cpu");
70 Attribute FSAttr = F.getFnAttribute("target-features");
71
72 auto CPU = CPUAttr.isValid() ? CPUAttr.getValueAsString().str() : TargetCPU;
73 auto FS = FSAttr.isValid() ? FSAttr.getValueAsString().str() : TargetFS;
74
75 auto &I = SubtargetMap[CPU + FS];
76 if (!I) {
77 // This needs to be done before we create a new subtarget since any
78 // creation will depend on the TM and the code generation flags on the
79 // function that reside in TargetOptions.
81 I = std::make_unique<XtensaSubtarget>(TargetTriple, CPU, FS, *this);
82 }
83 return I.get();
84}
85
86namespace {
87/// Xtensa Code Generator Pass Configuration Options.
88class XtensaPassConfig : public TargetPassConfig {
89public:
90 XtensaPassConfig(XtensaTargetMachine &TM, PassManagerBase &PM)
91 : TargetPassConfig(TM, PM) {}
92
93 XtensaTargetMachine &getXtensaTargetMachine() const {
94 return getTM<XtensaTargetMachine>();
95 }
96
97 bool addInstSelector() override;
98};
99} // end anonymous namespace
100
101bool XtensaPassConfig::addInstSelector() {
102 addPass(createXtensaISelDag(getXtensaTargetMachine(), getOptLevel()));
103 return false;
104}
105
107 return new XtensaPassConfig(*this, PM);
108}
basic Basic Alias true
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:135
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
const char LLVMTargetMachineRef TM
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:318
bool isValid() const
Return true if the attribute is any kind of attribute.
Definition: Attributes.h:184
This class describes a target machine that is implemented with the LLVM target-independent code gener...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:222
Triple TargetTriple
Triple string, CPU name, and target feature strings the TargetMachine instance is created with.
Definition: TargetMachine.h:95
std::string TargetFS
Definition: TargetMachine.h:97
std::string TargetCPU
Definition: TargetMachine.h:96
void resetTargetOptions(const Function &F) const
Reset the target options based on the function's attributes.
Target-Independent Code Generator Pass Configuration Options.
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 ...
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.
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
RegisterTargetMachine - Helper template for registering a target machine implementation,...