LLVM 20.0.0git
AVRTargetMachine.cpp
Go to the documentation of this file.
1//===-- AVRTargetMachine.cpp - Define TargetMachine for AVR ---------------===//
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// This file defines the AVR specific subclass of TargetMachine.
10//
11//===----------------------------------------------------------------------===//
12
13#include "AVRTargetMachine.h"
14
15#include "llvm/CodeGen/Passes.h"
17#include "llvm/IR/Module.h"
19
20#include "AVR.h"
22#include "AVRTargetObjectFile.h"
25
26#include <optional>
27
28namespace llvm {
29
30static const char *AVRDataLayout =
31 "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8";
32
33/// Processes a CPU name.
35 if (CPU.empty() || CPU == "generic") {
36 return "avr2";
37 }
38
39 return CPU;
40}
41
42static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
43 return RM.value_or(Reloc::Static);
44}
45
47 StringRef CPU, StringRef FS,
49 std::optional<Reloc::Model> RM,
50 std::optional<CodeModel::Model> CM,
51 CodeGenOptLevel OL, bool JIT)
54 getEffectiveCodeModel(CM, CodeModel::Small), OL),
55 SubTarget(TT, std::string(getCPU(CPU)), std::string(FS), *this) {
56 this->TLOF = std::make_unique<AVRTargetObjectFile>();
58}
59
60namespace {
61/// AVR Code Generator Pass Configuration Options.
62class AVRPassConfig : public TargetPassConfig {
63public:
64 AVRPassConfig(AVRTargetMachine &TM, PassManagerBase &PM)
65 : TargetPassConfig(TM, PM) {}
66
67 AVRTargetMachine &getAVRTargetMachine() const {
68 return getTM<AVRTargetMachine>();
69 }
70
71 void addIRPasses() override;
72 bool addInstSelector() override;
73 void addPreSched2() override;
74 void addPreEmitPass() override;
75};
76} // namespace
77
79 return new AVRPassConfig(*this, PM);
80}
81
82void AVRPassConfig::addIRPasses() {
83 // Expand instructions like
84 // %result = shl i32 %n, %amount
85 // to a loop so that library calls are avoided.
86 addPass(createAVRShiftExpandPass());
87
89}
90
92 // Register the target.
94
99}
100
102 return &SubTarget;
103}
104
106 return &SubTarget;
107}
108
111 const TargetSubtargetInfo *STI) const {
112 return AVRMachineFunctionInfo::create<AVRMachineFunctionInfo>(Allocator, F,
113 STI);
114}
115
116//===----------------------------------------------------------------------===//
117// Pass Pipeline Configuration
118//===----------------------------------------------------------------------===//
119
120bool AVRPassConfig::addInstSelector() {
121 // Install an instruction selector.
122 addPass(createAVRISelDag(getAVRTargetMachine(), getOptLevel()));
123 // Create the frame analyzer pass used by the PEI pass.
125
126 return false;
127}
128
129void AVRPassConfig::addPreSched2() {
130 addPass(createAVRExpandPseudoPass());
131}
132
133void AVRPassConfig::addPreEmitPass() {
134 // Must run branch selection immediately preceding the asm printer.
135 addPass(&BranchRelaxationPassID);
136}
137
138} // end of namespace llvm
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:131
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
static LVOptions Options
Definition: LVOptions.cpp:25
#define F(x, y, z)
Definition: MD5.cpp:55
Module.h This file contains the declarations for the Module class.
Basic Register Allocator
Target-Independent Code Generator Pass Configuration Options pass.
A specific AVR target MCU.
Definition: AVRSubtarget.h:32
A generic AVR implementation.
const AVRSubtarget * getSubtargetImpl() const
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
AVRTargetMachine(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)
MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override
Create the target's instance of MachineFunctionInfo.
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
This class describes a target machine that is implemented with the LLVM target-independent code gener...
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:50
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
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.
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
void initializeAVRShiftExpandPass(PassRegistry &)
void initializeAVRExpandPseudoPass(PassRegistry &)
Target & getTheAVRTarget()
static StringRef getCPU(StringRef CPU)
Processes a CPU name.
FunctionPass * createAVRFrameAnalyzerPass()
Creates instance of the frame analyzer pass.
FunctionPass * createAVRISelDag(AVRTargetMachine &TM, CodeGenOptLevel OptLevel)
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.
FunctionPass * createAVRExpandPseudoPass()
char & BranchRelaxationPassID
BranchRelaxation - This pass replaces branches that need to jump further than is supported by a branc...
void initializeAVRDAGToDAGISelLegacyPass(PassRegistry &)
CodeGenOptLevel
Code generation optimization level.
Definition: CodeGen.h:54
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAVRTarget()
static const char * AVRDataLayout
Pass * createAVRShiftExpandPass()
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,...