Alex Bradbury | b2e5472 | 2016-11-01 17:27:54 +0000 | [diff] [blame] | 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 "RISCVTargetMachine.h" |
| 15 | #include "llvm/ADT/STLExtras.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/Passes.h" |
Alex Bradbury | b2e5472 | 2016-11-01 17:27:54 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" |
| 18 | #include "llvm/CodeGen/TargetPassConfig.h" |
| 19 | #include "llvm/IR/LegacyPassManager.h" |
Alex Bradbury | b2e5472 | 2016-11-01 17:27:54 +0000 | [diff] [blame] | 20 | #include "llvm/Support/FormattedStream.h" |
| 21 | #include "llvm/Support/TargetRegistry.h" |
| 22 | #include "llvm/Target/TargetOptions.h" |
| 23 | using namespace llvm; |
| 24 | |
| 25 | extern "C" void LLVMInitializeRISCVTarget() { |
| 26 | RegisterTargetMachine<RISCVTargetMachine> X(getTheRISCV32Target()); |
| 27 | RegisterTargetMachine<RISCVTargetMachine> Y(getTheRISCV64Target()); |
| 28 | } |
| 29 | |
| 30 | static 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 Bradbury | e4f731b | 2017-02-14 05:20:20 +0000 | [diff] [blame] | 35 | return "e-m:e-p:32:32-i64:64-n32-S128"; |
Alex Bradbury | b2e5472 | 2016-11-01 17:27:54 +0000 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
| 39 | static 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 Espindola | 79e238a | 2017-08-03 02:16:21 +0000 | [diff] [blame^] | 46 | static CodeModel::Model getEffectiveCodeModel(Optional<CodeModel::Model> CM) { |
| 47 | if (CM) |
| 48 | return *CM; |
| 49 | return CodeModel::Small; |
| 50 | } |
| 51 | |
Alex Bradbury | b2e5472 | 2016-11-01 17:27:54 +0000 | [diff] [blame] | 52 | RISCVTargetMachine::RISCVTargetMachine(const Target &T, const Triple &TT, |
| 53 | StringRef CPU, StringRef FS, |
| 54 | const TargetOptions &Options, |
| 55 | Optional<Reloc::Model> RM, |
Rafael Espindola | 79e238a | 2017-08-03 02:16:21 +0000 | [diff] [blame^] | 56 | Optional<CodeModel::Model> CM, |
| 57 | CodeGenOpt::Level OL, bool JIT) |
Alex Bradbury | b2e5472 | 2016-11-01 17:27:54 +0000 | [diff] [blame] | 58 | : LLVMTargetMachine(T, computeDataLayout(TT), TT, CPU, FS, Options, |
Rafael Espindola | 79e238a | 2017-08-03 02:16:21 +0000 | [diff] [blame^] | 59 | getEffectiveRelocModel(TT, RM), |
| 60 | getEffectiveCodeModel(CM), OL), |
Alex Bradbury | e4f731b | 2017-02-14 05:20:20 +0000 | [diff] [blame] | 61 | TLOF(make_unique<TargetLoweringObjectFileELF>()) { |
| 62 | initAsmInfo(); |
| 63 | } |
Alex Bradbury | b2e5472 | 2016-11-01 17:27:54 +0000 | [diff] [blame] | 64 | |
| 65 | TargetPassConfig *RISCVTargetMachine::createPassConfig(PassManagerBase &PM) { |
Matthias Braun | 5e394c3 | 2017-05-30 21:36:41 +0000 | [diff] [blame] | 66 | return new TargetPassConfig(*this, PM); |
Alex Bradbury | b2e5472 | 2016-11-01 17:27:54 +0000 | [diff] [blame] | 67 | } |