LLVM  8.0.0svn
AVRTargetMachine.cpp
Go to the documentation of this file.
1 //===-- AVRTargetMachine.cpp - Define TargetMachine for AVR ---------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the AVR specific subclass of TargetMachine.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "AVRTargetMachine.h"
15 
16 #include "llvm/CodeGen/Passes.h"
19 #include "llvm/IR/Module.h"
21 
22 #include "AVR.h"
23 #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.hasValue() ? *RM : 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, getCPU(CPU), FS, *this) {
53  this->TLOF = 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 
79 extern "C" void LLVMInitializeAVRTarget() {
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
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
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...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
Definition: AllocatorList.h:24
char & BranchRelaxationPassID
BranchRelaxation - This pass replaces branches that need to jump further than is supported by a branc...
const AVRSubtarget * getSubtargetImpl() const
Target & getTheAVRTarget()
FunctionPass * createAVRRelaxMemPass()
Target-Independent Code Generator Pass Configuration Options.
A generic AVR implementation.
RegisterTargetMachine - Helper template for registering a target machine implementation, for use in the target machine initialization function.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:133
void LLVMInitializeAVRTarget()
void initializeAVRRelaxMemPass(PassRegistry &)
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
static Reloc::Model getEffectiveRelocModel(Optional< Reloc::Model > RM)
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)
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
This class describes a target machine that is implemented with the LLVM target-independent code gener...
FunctionPass * createAVRISelDag(AVRTargetMachine &TM, CodeGenOpt::Level OptLevel)
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 ...
Module.h This file contains the declarations for the Module class.
Target - Wrapper for Target specific information.
A specific AVR target MCU.
Definition: AVRSubtarget.h:32
FunctionPass * createAVRExpandPseudoPass()
bool hasValue() const
Definition: Optional.h:165
static const char * AVRDataLayout
static StringRef getCPU(StringRef CPU)
Processes a CPU name.
FunctionPass * createAVRFrameAnalyzerPass()
Creates instance of the frame analyzer pass.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void initializeAVRExpandPseudoPass(PassRegistry &)
FunctionPass * createAVRDynAllocaSRPass()
createAVRDynAllocaSRPass - returns an instance of the dynalloca stack pointer save/restore pass...