LLVM  7.0.0
LanaiTargetMachine.cpp
Go to the documentation of this file.
1 //===-- LanaiTargetMachine.cpp - Define TargetMachine for Lanai ---------===//
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 // Implements the info about Lanai target spec.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "LanaiTargetMachine.h"
15 
16 #include "Lanai.h"
17 #include "LanaiTargetObjectFile.h"
20 #include "llvm/CodeGen/Passes.h"
26 
27 using namespace llvm;
28 
29 namespace llvm {
31 } // namespace llvm
32 
33 extern "C" void LLVMInitializeLanaiTarget() {
34  // Register the target.
37 }
38 
39 static std::string computeDataLayout() {
40  // Data layout (keep in sync with clang/lib/Basic/Targets.cpp)
41  return "E" // Big endian
42  "-m:e" // ELF name manging
43  "-p:32:32" // 32-bit pointers, 32 bit aligned
44  "-i64:64" // 64 bit integers, 64 bit aligned
45  "-a:0:32" // 32 bit alignment of objects of aggregate type
46  "-n32" // 32 bit native integer width
47  "-S64"; // 64 bit natural stack alignment
48 }
49 
51  if (!RM.hasValue())
52  return Reloc::PIC_;
53  return *RM;
54 }
55 
57  if (CM)
58  return *CM;
59  return CodeModel::Medium;
60 }
61 
63  StringRef Cpu, StringRef FeatureString,
64  const TargetOptions &Options,
67  CodeGenOpt::Level OptLevel, bool JIT)
68  : LLVMTargetMachine(T, computeDataLayout(), TT, Cpu, FeatureString, Options,
70  getEffectiveCodeModel(CodeModel), OptLevel),
71  Subtarget(TT, Cpu, FeatureString, *this, Options, getCodeModel(),
72  OptLevel),
73  TLOF(new LanaiTargetObjectFile()) {
74  initAsmInfo();
75 }
76 
79  return TargetTransformInfo(LanaiTTIImpl(this, F));
80 }
81 
82 namespace {
83 // Lanai Code Generator Pass Configuration Options.
84 class LanaiPassConfig : public TargetPassConfig {
85 public:
87  : TargetPassConfig(TM, *PassManager) {}
88 
89  LanaiTargetMachine &getLanaiTargetMachine() const {
90  return getTM<LanaiTargetMachine>();
91  }
92 
93  bool addInstSelector() override;
94  void addPreSched2() override;
95  void addPreEmitPass() override;
96 };
97 } // namespace
98 
101  return new LanaiPassConfig(*this, &PassManager);
102 }
103 
104 // Install an instruction selector pass.
105 bool LanaiPassConfig::addInstSelector() {
106  addPass(createLanaiISelDag(getLanaiTargetMachine()));
107  return false;
108 }
109 
110 // Implemented by targets that want to run passes immediately before
111 // machine code is emitted.
112 void LanaiPassConfig::addPreEmitPass() {
113  addPass(createLanaiDelaySlotFillerPass(getLanaiTargetMachine()));
114 }
115 
116 // Run passes after prolog-epilog insertion and before the second instruction
117 // scheduling pass.
118 void LanaiPassConfig::addPreSched2() {
120 }
static std::string computeDataLayout()
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
Target & getTheLanaiTarget()
void initializeLanaiMemAluCombinerPass(PassRegistry &)
LanaiTargetMachine(const Target &TheTarget, const Triple &TargetTriple, StringRef Cpu, StringRef FeatureString, const TargetOptions &Options, Optional< Reloc::Model > RelocationModel, Optional< CodeModel::Model > CodeModel, CodeGenOpt::Level OptLevel, bool JIT)
F(f)
FunctionPass * createLanaiMemAluCombinerPass()
TargetPassConfig * createPassConfig(PassManagerBase &pass_manager) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
Target-Independent Code Generator Pass Configuration Options.
void LLVMInitializeLanaiTarget()
RegisterTargetMachine - Helper template for registering a target machine implementation, for use in the target machine initialization function.
FunctionPass * createLanaiDelaySlotFillerPass(const LanaiTargetMachine &TM)
static CodeModel::Model getEffectiveCodeModel(Optional< CodeModel::Model > CM)
static Reloc::Model getEffectiveRelocModel(Optional< Reloc::Model > RM)
This class describes a target machine that is implemented with the LLVM target-independent code gener...
FunctionPass * createLanaiISelDag(LanaiTargetMachine &TM)
TargetTransformInfo getTargetTransformInfo(const Function &F) override
Get a TargetTransformInfo implementation for the target.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
Target - Wrapper for Target specific information.
bool hasValue() const
Definition: Optional.h:183
Manages a sequence of passes over a particular unit of IR.
Definition: PassManager.h:420
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:39
This pass exposes codegen information to IR-level passes.