xref: /freebsd/contrib/llvm-project/llvm/lib/Target/CSKY/CSKYTargetMachine.cpp (revision c1d255d3ffdbe447de3ab875bf4e7d7accc5bfc5)
1 //===--- CSKYTargetMachine.cpp - Define TargetMachine for CSKY ------------===//
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 CSKY target spec.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "CSKYTargetMachine.h"
14 #include "TargetInfo/CSKYTargetInfo.h"
15 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
16 #include "llvm/CodeGen/TargetPassConfig.h"
17 #include "llvm/Support/TargetRegistry.h"
18 
19 using namespace llvm;
20 
21 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeCSKYTarget() {
22   RegisterTargetMachine<CSKYTargetMachine> X(getTheCSKYTarget());
23 }
24 
25 static std::string computeDataLayout(const Triple &TT) {
26   std::string Ret;
27 
28   // Only support little endian for now.
29   // TODO: Add support for big endian.
30   Ret += "e";
31 
32   // CSKY is always 32-bit target with the CSKYv2 ABI as prefer now.
33   // It's a 4-byte aligned stack with ELF mangling only.
34   Ret += "-m:e-S32-p:32:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:32"
35          "-v128:32:32-a:0:32-Fi32-n32";
36 
37   return Ret;
38 }
39 
40 CSKYTargetMachine::CSKYTargetMachine(const Target &T, const Triple &TT,
41                                      StringRef CPU, StringRef FS,
42                                      const TargetOptions &Options,
43                                      Optional<Reloc::Model> RM,
44                                      Optional<CodeModel::Model> CM,
45                                      CodeGenOpt::Level OL, bool JIT)
46     : LLVMTargetMachine(T, computeDataLayout(TT), TT, CPU, FS, Options,
47                         RM.getValueOr(Reloc::Static),
48                         getEffectiveCodeModel(CM, CodeModel::Small), OL),
49       TLOF(std::make_unique<TargetLoweringObjectFileELF>()) {
50   initAsmInfo();
51 }
52 
53 namespace {
54 class CSKYPassConfig : public TargetPassConfig {
55 public:
56   CSKYPassConfig(CSKYTargetMachine &TM, PassManagerBase &PM)
57       : TargetPassConfig(TM, PM) {}
58 
59   CSKYTargetMachine &getCSKYTargetMachine() const {
60     return getTM<CSKYTargetMachine>();
61   }
62 };
63 
64 } // namespace
65 
66 TargetPassConfig *CSKYTargetMachine::createPassConfig(PassManagerBase &PM) {
67   return new CSKYPassConfig(*this, PM);
68 }
69