LLVM  7.0.0
RISCVTargetMachine.cpp
Go to the documentation of this file.
1 //===-- RISCVTargetMachine.cpp - Define TargetMachine for RISCV -----------===//
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 RISCV target spec.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "RISCV.h"
15 #include "RISCVTargetMachine.h"
16 #include "RISCVTargetObjectFile.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/CodeGen/Passes.h"
25 using namespace llvm;
26 
27 extern "C" void LLVMInitializeRISCVTarget() {
30 }
31 
32 static std::string computeDataLayout(const Triple &TT) {
33  if (TT.isArch64Bit()) {
34  return "e-m:e-p:64:64-i64:64-i128:128-n64-S128";
35  } else {
36  assert(TT.isArch32Bit() && "only RV32 and RV64 are currently supported");
37  return "e-m:e-p:32:32-i64:64-n32-S128";
38  }
39 }
40 
43  if (!RM.hasValue())
44  return Reloc::Static;
45  return *RM;
46 }
47 
49  if (CM)
50  return *CM;
51  return CodeModel::Small;
52 }
53 
55  StringRef CPU, StringRef FS,
56  const TargetOptions &Options,
59  CodeGenOpt::Level OL, bool JIT)
60  : LLVMTargetMachine(T, computeDataLayout(TT), TT, CPU, FS, Options,
61  getEffectiveRelocModel(TT, RM),
62  getEffectiveCodeModel(CM), OL),
64  Subtarget(TT, CPU, FS, *this) {
65  initAsmInfo();
66 }
67 
68 namespace {
69 class RISCVPassConfig : public TargetPassConfig {
70 public:
71  RISCVPassConfig(RISCVTargetMachine &TM, PassManagerBase &PM)
72  : TargetPassConfig(TM, PM) {}
73 
74  RISCVTargetMachine &getRISCVTargetMachine() const {
75  return getTM<RISCVTargetMachine>();
76  }
77 
78  void addIRPasses() override;
79  bool addInstSelector() override;
80  void addPreEmitPass() override;
81  void addPreRegAlloc() override;
82 };
83 }
84 
86  return new RISCVPassConfig(*this, PM);
87 }
88 
89 void RISCVPassConfig::addIRPasses() {
90  addPass(createAtomicExpandPass());
92 }
93 
94 bool RISCVPassConfig::addInstSelector() {
95  addPass(createRISCVISelDag(getRISCVTargetMachine()));
96 
97  return false;
98 }
99 
100 void RISCVPassConfig::addPreEmitPass() { addPass(&BranchRelaxationPassID); }
101 
102 void RISCVPassConfig::addPreRegAlloc() {
104 }
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
char & BranchRelaxationPassID
BranchRelaxation - This pass replaces branches that need to jump further than is supported by a branc...
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&... args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
Definition: STLExtras.h:1069
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
Target & getTheRISCV32Target()
Target-Independent Code Generator Pass Configuration Options.
FunctionPass * createRISCVISelDag(RISCVTargetMachine &TM)
RegisterTargetMachine - Helper template for registering a target machine implementation, for use in the target machine initialization function.
bool isArch32Bit() const
Test whether the architecture is 32-bit.
Definition: Triple.cpp:1249
static CodeModel::Model getEffectiveCodeModel(Optional< CodeModel::Model > CM)
static Reloc::Model getEffectiveRelocModel(Optional< Reloc::Model > RM)
void LLVMInitializeRISCVTarget()
Target & getTheRISCV64Target()
This class describes a target machine that is implemented with the LLVM target-independent code gener...
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 ...
Target - Wrapper for Target specific information.
static std::string computeDataLayout(const Triple &TT)
bool hasValue() const
Definition: Optional.h:183
bool isArch64Bit() const
Test whether the architecture is 64-bit.
Definition: Triple.cpp:1245
FunctionPass * createRISCVMergeBaseOffsetOptPass()
Returns an instance of the Merge Base Offset Optimization pass.
RISCVTargetMachine(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)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
This implementation is used for RISCV ELF targets.
FunctionPass * createAtomicExpandPass()