LLVM  14.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"
18 #include "llvm/IR/Module.h"
20 
21 #include "AVR.h"
22 #include "AVRTargetObjectFile.h"
25 
26 namespace llvm {
27 
28 static const char *AVRDataLayout =
29  "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8";
30 
31 /// Processes a CPU name.
32 static StringRef getCPU(StringRef CPU) {
33  if (CPU.empty() || CPU == "generic") {
34  return "avr2";
35  }
36 
37  return CPU;
38 }
39 
41  return RM.getValueOr(Reloc::Static);
42 }
43 
45  StringRef CPU, StringRef FS,
46  const TargetOptions &Options,
49  CodeGenOpt::Level OL, bool JIT)
52  getEffectiveCodeModel(CM, CodeModel::Small), OL),
53  SubTarget(TT, std::string(getCPU(CPU)), std::string(FS), *this) {
54  this->TLOF = std::make_unique<AVRTargetObjectFile>();
55  initAsmInfo();
56 }
57 
58 namespace {
59 /// AVR Code Generator Pass Configuration Options.
60 class AVRPassConfig : public TargetPassConfig {
61 public:
62  AVRPassConfig(AVRTargetMachine &TM, PassManagerBase &PM)
63  : TargetPassConfig(TM, PM) {}
64 
65  AVRTargetMachine &getAVRTargetMachine() const {
66  return getTM<AVRTargetMachine>();
67  }
68 
69  void addIRPasses() override;
70  bool addInstSelector() override;
71  void addPreSched2() override;
72  void addPreEmitPass() override;
73  void addPreRegAlloc() override;
74 };
75 } // namespace
76 
78  return new AVRPassConfig(*this, PM);
79 }
80 
81 void AVRPassConfig::addIRPasses() {
82  // Expand instructions like
83  // %result = shl i32 %n, %amount
84  // to a loop so that library calls are avoided.
85  addPass(createAVRShiftExpandPass());
86 
88 }
89 
91  // Register the target.
93 
94  auto &PR = *PassRegistry::getPassRegistry();
98 }
99 
101  return &SubTarget;
102 }
103 
105  return &SubTarget;
106 }
107 
108 //===----------------------------------------------------------------------===//
109 // Pass Pipeline Configuration
110 //===----------------------------------------------------------------------===//
111 
112 bool AVRPassConfig::addInstSelector() {
113  // Install an instruction selector.
114  addPass(createAVRISelDag(getAVRTargetMachine(), getOptLevel()));
115  // Create the frame analyzer pass used by the PEI pass.
116  addPass(createAVRFrameAnalyzerPass());
117 
118  return false;
119 }
120 
121 void AVRPassConfig::addPreRegAlloc() {
122  // Create the dynalloc SP save/restore pass to handle variable sized allocas.
123  addPass(createAVRDynAllocaSRPass());
124 }
125 
126 void AVRPassConfig::addPreSched2() {
127  addPass(createAVRRelaxMemPass());
128  addPass(createAVRExpandPseudoPass());
129 }
130 
131 void AVRPassConfig::addPreEmitPass() {
132  // Must run branch selection immediately preceding the asm printer.
133  addPass(&BranchRelaxationPassID);
134 }
135 
136 } // end of namespace llvm
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
llvm::TargetOptions
Definition: TargetOptions.h:124
llvm::Function
Definition: Function.h:61
llvm::AVRTargetMachine
A generic AVR implementation.
Definition: AVRTargetMachine.h:28
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:137
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
Module.h
llvm::Optional< Reloc::Model >
T
#define T
Definition: Mips16ISelLowering.cpp:341
LegacyPassManager.h
llvm::AVRTargetMachine::createPassConfig
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
Definition: AVRTargetMachine.cpp:77
llvm::Reloc::Model
Model
Definition: CodeGen.h:22
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::AVRTargetMachine::AVRTargetMachine
AVRTargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, Optional< Reloc::Model > RM, Optional< CodeModel::Model > CM, CodeGenOpt::Level OL, bool JIT)
Definition: AVRTargetMachine.cpp:44
llvm::AVRSubtarget
A specific AVR target MCU.
Definition: AVRSubtarget.h:31
llvm::getTheAVRTarget
Target & getTheAVRTarget()
Definition: AVRTargetInfo.cpp:12
llvm::CodeModel::Small
@ Small
Definition: CodeGen.h:28
llvm::RegisterTargetMachine
RegisterTargetMachine - Helper template for registering a target machine implementation,...
Definition: TargetRegistry.h:1275
Options
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Definition: PassBuilderBindings.cpp:48
AVRTargetInfo.h
llvm::initializeAVRExpandPseudoPass
void initializeAVRExpandPseudoPass(PassRegistry &)
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
Passes.h
llvm::TargetPassConfig
Target-Independent Code Generator Pass Configuration Options.
Definition: TargetPassConfig.h:84
llvm::EngineKind::JIT
@ JIT
Definition: ExecutionEngine.h:524
LLVM_EXTERNAL_VISIBILITY
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:132
llvm::createAVRDynAllocaSRPass
FunctionPass * createAVRDynAllocaSRPass()
createAVRDynAllocaSRPass - returns an instance of the dynalloca stack pointer save/restore pass.
Definition: AVRFrameLowering.cpp:535
llvm::TargetPassConfig::addIRPasses
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
Definition: TargetPassConfig.cpp:850
TargetPassConfig.h
AVRTargetMachine.h
AVRMCTargetDesc.h
llvm::initializeAVRRelaxMemPass
void initializeAVRRelaxMemPass(PassRegistry &)
llvm::getCPU
static StringRef getCPU(StringRef CPU)
Processes a CPU name.
Definition: AVRTargetMachine.cpp:32
llvm::initializeAVRShiftExpandPass
void initializeAVRShiftExpandPass(PassRegistry &)
llvm::AArch64::RM
@ RM
Definition: AArch64ISelLowering.h:472
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
this
Analysis the ScalarEvolution expression for r is this
Definition: README.txt:8
llvm::Reloc::Static
@ Static
Definition: CodeGen.h:22
llvm::createAVRISelDag
FunctionPass * createAVRISelDag(AVRTargetMachine &TM, CodeGenOpt::Level OptLevel)
Definition: AVRISelDAGToDAG.cpp:554
AVRTargetObjectFile.h
llvm::CodeGenOpt::Level
Level
Definition: CodeGen.h:52
llvm::getEffectiveRelocModel
static Reloc::Model getEffectiveRelocModel(Optional< Reloc::Model > RM)
Definition: AVRTargetMachine.cpp:40
llvm::getEffectiveCodeModel
CodeModel::Model getEffectiveCodeModel(Optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value.
Definition: TargetMachine.h:481
llvm::LLVMTargetMachine::initAsmInfo
void initAsmInfo()
Definition: LLVMTargetMachine.cpp:41
std
Definition: BitVector.h:838
llvm::createAVRFrameAnalyzerPass
FunctionPass * createAVRFrameAnalyzerPass()
Creates instance of the frame analyzer pass.
Definition: AVRFrameLowering.cpp:483
llvm::X86AS::FS
@ FS
Definition: X86.h:188
llvm::LLVMTargetMachine
This class describes a target machine that is implemented with the LLVM target-independent code gener...
Definition: TargetMachine.h:393
llvm::LLVMInitializeAVRTarget
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAVRTarget()
Definition: AVRTargetMachine.cpp:90
AVR.h
llvm::BranchRelaxationPassID
char & BranchRelaxationPassID
BranchRelaxation - This pass replaces branches that need to jump further than is supported by a branc...
Definition: BranchRelaxation.cpp:119
llvm::legacy::PassManagerBase
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
Definition: LegacyPassManager.h:39
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::AVRDataLayout
static const char * AVRDataLayout
Definition: AVRTargetMachine.cpp:28
llvm::createAVRShiftExpandPass
Pass * createAVRShiftExpandPass()
llvm::AVRTargetMachine::getSubtargetImpl
const AVRSubtarget * getSubtargetImpl() const
Definition: AVRTargetMachine.cpp:100
TargetRegistry.h
llvm::createAVRExpandPseudoPass
FunctionPass * createAVRExpandPseudoPass()
llvm::createAVRRelaxMemPass
FunctionPass * createAVRRelaxMemPass()
SpecialSubKind::string
@ string