LLVM  13.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 = "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8";
29 
30 /// Processes a CPU name.
31 static StringRef getCPU(StringRef CPU) {
32  if (CPU.empty() || CPU == "generic") {
33  return "avr2";
34  }
35 
36  return CPU;
37 }
38 
40  return RM.getValueOr(Reloc::Static);
41 }
42 
44  StringRef CPU, StringRef FS,
45  const TargetOptions &Options,
48  CodeGenOpt::Level OL, bool JIT)
49  : LLVMTargetMachine(T, AVRDataLayout, TT, getCPU(CPU), FS, Options,
51  getEffectiveCodeModel(CM, CodeModel::Small), OL),
52  SubTarget(TT, std::string(getCPU(CPU)), std::string(FS), *this) {
53  this->TLOF = std::make_unique<AVRTargetObjectFile>();
54  initAsmInfo();
55 }
56 
57 namespace {
58 /// AVR Code Generator Pass Configuration Options.
59 class AVRPassConfig : public TargetPassConfig {
60 public:
61  AVRPassConfig(AVRTargetMachine &TM, PassManagerBase &PM)
62  : TargetPassConfig(TM, PM) {}
63 
64  AVRTargetMachine &getAVRTargetMachine() const {
65  return getTM<AVRTargetMachine>();
66  }
67 
68  bool addInstSelector() override;
69  void addPreSched2() override;
70  void addPreEmitPass() override;
71  void addPreRegAlloc() override;
72 };
73 } // namespace
74 
76  return new AVRPassConfig(*this, PM);
77 }
78 
80  // Register the target.
82 
83  auto &PR = *PassRegistry::getPassRegistry();
86 }
87 
89  return &SubTarget;
90 }
91 
93  return &SubTarget;
94 }
95 
96 //===----------------------------------------------------------------------===//
97 // Pass Pipeline Configuration
98 //===----------------------------------------------------------------------===//
99 
100 bool AVRPassConfig::addInstSelector() {
101  // Install an instruction selector.
102  addPass(createAVRISelDag(getAVRTargetMachine(), getOptLevel()));
103  // Create the frame analyzer pass used by the PEI pass.
104  addPass(createAVRFrameAnalyzerPass());
105 
106  return false;
107 }
108 
109 void AVRPassConfig::addPreRegAlloc() {
110  // Create the dynalloc SP save/restore pass to handle variable sized allocas.
111  addPass(createAVRDynAllocaSRPass());
112 }
113 
114 void AVRPassConfig::addPreSched2() {
115  addPass(createAVRRelaxMemPass());
116  addPass(createAVRExpandPseudoPass());
117 }
118 
119 void AVRPassConfig::addPreEmitPass() {
120  // Must run branch selection immediately preceding the asm printer.
121  addPass(&BranchRelaxationPassID);
122 }
123 
124 } // end of namespace llvm
llvm
Definition: AllocatorList.h:23
llvm::StringRef::empty
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:156
llvm::SystemZISD::TM
@ TM
Definition: SystemZISelLowering.h:65
llvm::TargetOptions
Definition: TargetOptions.h:119
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:124
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
llvm::X86AS::FS
@ FS
Definition: X86.h:183
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:75
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:43
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:1133
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:525
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:531
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:31
llvm::AArch64::RM
@ RM
Definition: AArch64ISelLowering.h:468
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
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:548
AVRTargetObjectFile.h
llvm::CodeGenOpt::Level
Level
Definition: CodeGen.h:52
llvm::getEffectiveRelocModel
static Reloc::Model getEffectiveRelocModel(Optional< Reloc::Model > RM)
Definition: AVRTargetMachine.cpp:39
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:474
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:479
llvm::LLVMTargetMachine
This class describes a target machine that is implemented with the LLVM target-independent code gener...
Definition: TargetMachine.h:386
llvm::LLVMInitializeAVRTarget
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAVRTarget()
Definition: AVRTargetMachine.cpp:79
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
llvm::AVRDataLayout
static const char * AVRDataLayout
Definition: AVRTargetMachine.cpp:28
llvm::AVRTargetMachine::getSubtargetImpl
const AVRSubtarget * getSubtargetImpl() const
Definition: AVRTargetMachine.cpp:88
TargetRegistry.h
llvm::createAVRExpandPseudoPass
FunctionPass * createAVRExpandPseudoPass()
llvm::createAVRRelaxMemPass
FunctionPass * createAVRRelaxMemPass()
SpecialSubKind::string
@ string