blob: 78d9cf53b5d6ee422cfbc401bffe0468cee569b7 [file] [log] [blame]
Alex Bradburyb2e54722016-11-01 17:27:54 +00001//===-- 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 "RISCVTargetMachine.h"
15#include "llvm/ADT/STLExtras.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000016#include "llvm/CodeGen/Passes.h"
Alex Bradburyb2e54722016-11-01 17:27:54 +000017#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
18#include "llvm/CodeGen/TargetPassConfig.h"
19#include "llvm/IR/LegacyPassManager.h"
Alex Bradburyb2e54722016-11-01 17:27:54 +000020#include "llvm/Support/FormattedStream.h"
21#include "llvm/Support/TargetRegistry.h"
22#include "llvm/Target/TargetOptions.h"
23using namespace llvm;
24
25extern "C" void LLVMInitializeRISCVTarget() {
26 RegisterTargetMachine<RISCVTargetMachine> X(getTheRISCV32Target());
27 RegisterTargetMachine<RISCVTargetMachine> Y(getTheRISCV64Target());
28}
29
30static std::string computeDataLayout(const Triple &TT) {
31 if (TT.isArch64Bit()) {
32 return "e-m:e-i64:64-n32:64-S128";
33 } else {
34 assert(TT.isArch32Bit() && "only RV32 and RV64 are currently supported");
Alex Bradburye4f731b2017-02-14 05:20:20 +000035 return "e-m:e-p:32:32-i64:64-n32-S128";
Alex Bradburyb2e54722016-11-01 17:27:54 +000036 }
37}
38
39static Reloc::Model getEffectiveRelocModel(const Triple &TT,
40 Optional<Reloc::Model> RM) {
41 if (!RM.hasValue())
42 return Reloc::Static;
43 return *RM;
44}
45
Rafael Espindola79e238a2017-08-03 02:16:21 +000046static CodeModel::Model getEffectiveCodeModel(Optional<CodeModel::Model> CM) {
47 if (CM)
48 return *CM;
49 return CodeModel::Small;
50}
51
Alex Bradburyb2e54722016-11-01 17:27:54 +000052RISCVTargetMachine::RISCVTargetMachine(const Target &T, const Triple &TT,
53 StringRef CPU, StringRef FS,
54 const TargetOptions &Options,
55 Optional<Reloc::Model> RM,
Rafael Espindola79e238a2017-08-03 02:16:21 +000056 Optional<CodeModel::Model> CM,
57 CodeGenOpt::Level OL, bool JIT)
Alex Bradburyb2e54722016-11-01 17:27:54 +000058 : LLVMTargetMachine(T, computeDataLayout(TT), TT, CPU, FS, Options,
Rafael Espindola79e238a2017-08-03 02:16:21 +000059 getEffectiveRelocModel(TT, RM),
60 getEffectiveCodeModel(CM), OL),
Alex Bradburye4f731b2017-02-14 05:20:20 +000061 TLOF(make_unique<TargetLoweringObjectFileELF>()) {
62 initAsmInfo();
63}
Alex Bradburyb2e54722016-11-01 17:27:54 +000064
65TargetPassConfig *RISCVTargetMachine::createPassConfig(PassManagerBase &PM) {
Matthias Braun5e394c32017-05-30 21:36:41 +000066 return new TargetPassConfig(*this, PM);
Alex Bradburyb2e54722016-11-01 17:27:54 +000067}