LLVM  9.0.0svn
LanaiTargetMachine.cpp
Go to the documentation of this file.
1 //===-- LanaiTargetMachine.cpp - Define TargetMachine for Lanai ---------===//
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 // Implements the info about Lanai target spec.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "LanaiTargetMachine.h"
14 
15 #include "Lanai.h"
16 #include "LanaiTargetObjectFile.h"
19 #include "llvm/CodeGen/Passes.h"
25 
26 using namespace llvm;
27 
28 namespace llvm {
30 } // namespace llvm
31 
32 extern "C" void LLVMInitializeLanaiTarget() {
33  // Register the target.
36 }
37 
38 static std::string computeDataLayout() {
39  // Data layout (keep in sync with clang/lib/Basic/Targets.cpp)
40  return "E" // Big endian
41  "-m:e" // ELF name manging
42  "-p:32:32" // 32-bit pointers, 32 bit aligned
43  "-i64:64" // 64 bit integers, 64 bit aligned
44  "-a:0:32" // 32 bit alignment of objects of aggregate type
45  "-n32" // 32 bit native integer width
46  "-S64"; // 64 bit natural stack alignment
47 }
48 
50  if (!RM.hasValue())
51  return Reloc::PIC_;
52  return *RM;
53 }
54 
56  StringRef Cpu, StringRef FeatureString,
57  const TargetOptions &Options,
60  CodeGenOpt::Level OptLevel, bool JIT)
61  : LLVMTargetMachine(T, computeDataLayout(), TT, Cpu, FeatureString, Options,
63  getEffectiveCodeModel(CodeModel, CodeModel::Medium),
64  OptLevel),
65  Subtarget(TT, Cpu, FeatureString, *this, Options, getCodeModel(),
66  OptLevel),
67  TLOF(new LanaiTargetObjectFile()) {
68  initAsmInfo();
69 }
70 
73  return TargetTransformInfo(LanaiTTIImpl(this, F));
74 }
75 
76 namespace {
77 // Lanai Code Generator Pass Configuration Options.
78 class LanaiPassConfig : public TargetPassConfig {
79 public:
81  : TargetPassConfig(TM, *PassManager) {}
82 
83  LanaiTargetMachine &getLanaiTargetMachine() const {
84  return getTM<LanaiTargetMachine>();
85  }
86 
87  bool addInstSelector() override;
88  void addPreSched2() override;
89  void addPreEmitPass() override;
90 };
91 } // namespace
92 
95  return new LanaiPassConfig(*this, &PassManager);
96 }
97 
98 // Install an instruction selector pass.
99 bool LanaiPassConfig::addInstSelector() {
100  addPass(createLanaiISelDag(getLanaiTargetMachine()));
101  return false;
102 }
103 
104 // Implemented by targets that want to run passes immediately before
105 // machine code is emitted.
106 void LanaiPassConfig::addPreEmitPass() {
107  addPass(createLanaiDelaySlotFillerPass(getLanaiTargetMachine()));
108 }
109 
110 // Run passes after prolog-epilog insertion and before the second instruction
111 // scheduling pass.
112 void LanaiPassConfig::addPreSched2() {
114 }
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 std::string computeDataLayout()
This class represents lattice values for constants.
Definition: AllocatorList.h:23
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 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:43
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:166
Manages a sequence of passes over a particular unit of IR.
Definition: PassManager.h:457
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:38
This pass exposes codegen information to IR-level passes.