LLVM  9.0.0svn
RISCVTargetMachine.cpp
Go to the documentation of this file.
1 //===-- RISCVTargetMachine.cpp - Define TargetMachine for RISCV -----------===//
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 RISCV target spec.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "RISCV.h"
14 #include "RISCVTargetMachine.h"
15 #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() {
32 }
33 
35  if (TT.isArch64Bit()) {
36  return "e-m:e-p:64:64-i64:64-i128:128-n64-S128";
37  } else {
38  assert(TT.isArch32Bit() && "only RV32 and RV64 are currently supported");
39  return "e-m:e-p:32:32-i64:64-n32-S128";
40  }
41 }
42 
45  if (!RM.hasValue())
46  return Reloc::Static;
47  return *RM;
48 }
49 
51  StringRef CPU, StringRef FS,
52  const TargetOptions &Options,
55  CodeGenOpt::Level OL, bool JIT)
56  : LLVMTargetMachine(T, computeDataLayout(TT), TT, CPU, FS, Options,
57  getEffectiveRelocModel(TT, RM),
58  getEffectiveCodeModel(CM, CodeModel::Small), OL),
60  Subtarget(TT, CPU, FS, Options.MCOptions.getABIName(), *this) {
61  initAsmInfo();
62 }
63 
64 namespace {
65 class RISCVPassConfig : public TargetPassConfig {
66 public:
67  RISCVPassConfig(RISCVTargetMachine &TM, PassManagerBase &PM)
68  : TargetPassConfig(TM, PM) {}
69 
70  RISCVTargetMachine &getRISCVTargetMachine() const {
71  return getTM<RISCVTargetMachine>();
72  }
73 
74  void addIRPasses() override;
75  bool addInstSelector() override;
76  void addPreEmitPass() override;
77  void addPreEmitPass2() override;
78  void addPreRegAlloc() override;
79 };
80 }
81 
83  return new RISCVPassConfig(*this, PM);
84 }
85 
86 void RISCVPassConfig::addIRPasses() {
87  addPass(createAtomicExpandPass());
89 }
90 
91 bool RISCVPassConfig::addInstSelector() {
92  addPass(createRISCVISelDag(getRISCVTargetMachine()));
93 
94  return false;
95 }
96 
97 void RISCVPassConfig::addPreEmitPass() { addPass(&BranchRelaxationPassID); }
98 
99 void RISCVPassConfig::addPreEmitPass2() {
100  // Schedule the expansion of AMOs at the last possible moment, avoiding the
101  // possibility for other passes to break the requirements for forward
102  // progress in the LR/SC block.
103  addPass(createRISCVExpandPseudoPass());
104 }
105 
106 void RISCVPassConfig::addPreRegAlloc() {
108 }
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:23
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
void initializeRISCVExpandPseudoPass(PassRegistry &)
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:1437
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:1294
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:43
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
bool isArch64Bit() const
Test whether the architecture is 64-bit.
Definition: Triple.cpp:1290
static StringRef computeDataLayout(const Triple &TT)
FunctionPass * createRISCVMergeBaseOffsetOptPass()
Returns an instance of the Merge Base Offset Optimization pass.
FunctionPass * createRISCVExpandPseudoPass()
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:48
This implementation is used for RISCV ELF targets.
FunctionPass * createAtomicExpandPass()