LLVM 20.0.0git
LanaiTargetMachine.cpp
Go to the documentation of this file.
1//===-- LanaiTargetMachine.cpp - Define TargetMachine for Lanai ---------===//
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 Lanai target spec.
10//
11//===----------------------------------------------------------------------===//
12
13#include "LanaiTargetMachine.h"
14
15#include "Lanai.h"
21#include "llvm/CodeGen/Passes.h"
25#include <optional>
26
27using namespace llvm;
28
29namespace llvm {
31} // namespace llvm
32
34 // Register the target.
39}
40
41static std::string computeDataLayout() {
42 // Data layout (keep in sync with clang/lib/Basic/Targets.cpp)
43 return "E" // Big endian
44 "-m:e" // ELF name manging
45 "-p:32:32" // 32-bit pointers, 32 bit aligned
46 "-i64:64" // 64 bit integers, 64 bit aligned
47 "-a:0:32" // 32 bit alignment of objects of aggregate type
48 "-n32" // 32 bit native integer width
49 "-S64"; // 64 bit natural stack alignment
50}
51
52static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
53 return RM.value_or(Reloc::PIC_);
54}
55
57 const Target &T, const Triple &TT, StringRef Cpu, StringRef FeatureString,
58 const TargetOptions &Options, std::optional<Reloc::Model> RM,
59 std::optional<CodeModel::Model> CodeModel, CodeGenOptLevel OptLevel,
60 bool JIT)
62 T, computeDataLayout(), TT, Cpu, FeatureString, Options,
64 getEffectiveCodeModel(CodeModel, CodeModel::Medium), OptLevel),
65 Subtarget(TT, Cpu, FeatureString, *this, Options, getCodeModel(),
66 OptLevel),
67 TLOF(new LanaiTargetObjectFile()) {
69}
70
73 return TargetTransformInfo(LanaiTTIImpl(this, F));
74}
75
77 BumpPtrAllocator &Allocator, const Function &F,
78 const TargetSubtargetInfo *STI) const {
79 return LanaiMachineFunctionInfo::create<LanaiMachineFunctionInfo>(Allocator,
80 F, STI);
81}
82
83namespace {
84// Lanai Code Generator Pass Configuration Options.
85class LanaiPassConfig : public TargetPassConfig {
86public:
89
90 LanaiTargetMachine &getLanaiTargetMachine() const {
91 return getTM<LanaiTargetMachine>();
92 }
93
94 void addIRPasses() override;
95 bool addInstSelector() override;
96 void addPreSched2() override;
97 void addPreEmitPass() override;
98};
99} // namespace
100
103 return new LanaiPassConfig(*this, &PassManager);
104}
105
106void LanaiPassConfig::addIRPasses() {
108
110}
111
112// Install an instruction selector pass.
113bool LanaiPassConfig::addInstSelector() {
114 addPass(createLanaiISelDag(getLanaiTargetMachine()));
115 return false;
116}
117
118// Implemented by targets that want to run passes immediately before
119// machine code is emitted.
120void LanaiPassConfig::addPreEmitPass() {
121 addPass(createLanaiDelaySlotFillerPass(getLanaiTargetMachine()));
122}
123
124// Run passes after prolog-epilog insertion and before the second instruction
125// scheduling pass.
126void LanaiPassConfig::addPreSched2() {
128}
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:128
static LVOptions Options
Definition: LVOptions.cpp:25
static std::string computeDataLayout()
static Reloc::Model getEffectiveRelocModel(std::optional< Reloc::Model > RM)
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeLanaiTarget()
#define F(x, y, z)
Definition: MD5.cpp:55
static CodeModel::Model getCodeModel(const PPCSubtarget &S, const TargetMachine &TM, const MachineOperand &MO)
Basic Register Allocator
Target-Independent Code Generator Pass Configuration Options pass.
This pass exposes codegen information to IR-level passes.
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...
TargetPassConfig * createPassConfig(PassManagerBase &pass_manager) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
LanaiTargetMachine(const Target &TheTarget, const Triple &TargetTriple, StringRef Cpu, StringRef FeatureString, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CodeModel, CodeGenOptLevel OptLevel, bool JIT)
MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override
Create the target's instance of MachineFunctionInfo.
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
Manages a sequence of passes over a particular unit of IR.
Definition: PassManager.h:162
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:37
static 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:51
std::unique_ptr< const MCSubtargetInfo > STI
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.
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
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
Target & getTheLanaiTarget()
FunctionPass * createLanaiMemAluCombinerPass()
FunctionPass * createLanaiISelDag(LanaiTargetMachine &TM)
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.
CodeGenOptLevel
Code generation optimization level.
Definition: CodeGen.h:54
void initializeLanaiDAGToDAGISelLegacyPass(PassRegistry &)
void initializeLanaiMemAluCombinerPass(PassRegistry &)
FunctionPass * createLanaiDelaySlotFillerPass(const LanaiTargetMachine &TM)
FunctionPass * createAtomicExpandLegacyPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
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,...