1 //===--- CSKYTargetMachine.cpp - Define TargetMachine for CSKY ------------===//
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
7 //===----------------------------------------------------------------------===//
9 // Implements the info about CSKY target spec.
11 //===----------------------------------------------------------------------===//
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"
21 extern "C" LLVM_EXTERNAL_VISIBILITY
void LLVMInitializeCSKYTarget() {
22 RegisterTargetMachine
<CSKYTargetMachine
> X(getTheCSKYTarget());
25 static std::string
computeDataLayout(const Triple
&TT
) {
28 // Only support little endian for now.
29 // TODO: Add support for big endian.
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";
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
>()) {
54 class CSKYPassConfig
: public TargetPassConfig
{
56 CSKYPassConfig(CSKYTargetMachine
&TM
, PassManagerBase
&PM
)
57 : TargetPassConfig(TM
, PM
) {}
59 CSKYTargetMachine
&getCSKYTargetMachine() const {
60 return getTM
<CSKYTargetMachine
>();
66 TargetPassConfig
*CSKYTargetMachine::createPassConfig(PassManagerBase
&PM
) {
67 return new CSKYPassConfig(*this, PM
);