LLVM  10.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"
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  StringRef Cpu, StringRef FeatureString,
58  const TargetOptions &Options,
61  CodeGenOpt::Level OptLevel, bool JIT)
62  : LLVMTargetMachine(T, computeDataLayout(), TT, Cpu, FeatureString, Options,
64  getEffectiveCodeModel(CodeModel, CodeModel::Medium),
65  OptLevel),
66  Subtarget(TT, Cpu, FeatureString, *this, Options, getCodeModel(),
67  OptLevel),
68  TLOF(new LanaiTargetObjectFile()) {
69  initAsmInfo();
70 }
71 
74  return TargetTransformInfo(LanaiTTIImpl(this, F));
75 }
76 
77 namespace {
78 // Lanai Code Generator Pass Configuration Options.
79 class LanaiPassConfig : public TargetPassConfig {
80 public:
82  : TargetPassConfig(TM, *PassManager) {}
83 
84  LanaiTargetMachine &getLanaiTargetMachine() const {
85  return getTM<LanaiTargetMachine>();
86  }
87 
88  bool addInstSelector() override;
89  void addPreSched2() override;
90  void addPreEmitPass() override;
91 };
92 } // namespace
93 
96  return new LanaiPassConfig(*this, &PassManager);
97 }
98 
99 // Install an instruction selector pass.
100 bool LanaiPassConfig::addInstSelector() {
101  addPass(createLanaiISelDag(getLanaiTargetMachine()));
102  return false;
103 }
104 
105 // Implemented by targets that want to run passes immediately before
106 // machine code is emitted.
107 void LanaiPassConfig::addPreEmitPass() {
108  addPass(createLanaiDelaySlotFillerPass(getLanaiTargetMachine()));
109 }
110 
111 // Run passes after prolog-epilog insertion and before the second instruction
112 // scheduling pass.
113 void LanaiPassConfig::addPreSched2() {
115 }
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:259
Manages a sequence of passes over a particular unit of IR.
Definition: PassManager.h:465
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.