1 //===-- LanaiTargetMachine.cpp - Define TargetMachine for Lanai ---------===//
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 Lanai target spec.
11 //===----------------------------------------------------------------------===//
13 #include "LanaiTargetMachine.h"
16 #include "LanaiTargetObjectFile.h"
17 #include "LanaiTargetTransformInfo.h"
18 #include "llvm/Analysis/TargetTransformInfo.h"
19 #include "llvm/CodeGen/Passes.h"
20 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
21 #include "llvm/CodeGen/TargetPassConfig.h"
22 #include "llvm/Support/FormattedStream.h"
23 #include "llvm/Support/TargetRegistry.h"
24 #include "llvm/Target/TargetOptions.h"
29 void initializeLanaiMemAluCombinerPass(PassRegistry
&);
32 extern "C" void LLVMInitializeLanaiTarget() {
33 // Register the target.
34 RegisterTargetMachine
<LanaiTargetMachine
> registered_target(
38 static std::string
computeDataLayout() {
39 // Data layout (keep in sync with clang/lib/Basic/Targets.cpp)
40 return "E" // Big endian
41 "-m:e" // ELF name manging
42 "-p:32:32" // 32-bit pointers, 32 bit aligned
43 "-i64:64" // 64 bit integers, 64 bit aligned
44 "-a:0:32" // 32 bit alignment of objects of aggregate type
45 "-n32" // 32 bit native integer width
46 "-S64"; // 64 bit natural stack alignment
49 static Reloc::Model
getEffectiveRelocModel(Optional
<Reloc::Model
> RM
) {
55 LanaiTargetMachine::LanaiTargetMachine(const Target
&T
, const Triple
&TT
,
56 StringRef Cpu
, StringRef FeatureString
,
57 const TargetOptions
&Options
,
58 Optional
<Reloc::Model
> RM
,
59 Optional
<CodeModel::Model
> CodeModel
,
60 CodeGenOpt::Level OptLevel
, bool JIT
)
61 : LLVMTargetMachine(T
, computeDataLayout(), TT
, Cpu
, FeatureString
, Options
,
62 getEffectiveRelocModel(RM
),
63 getEffectiveCodeModel(CodeModel
, CodeModel::Medium
),
65 Subtarget(TT
, Cpu
, FeatureString
, *this, Options
, getCodeModel(),
67 TLOF(new LanaiTargetObjectFile()) {
72 LanaiTargetMachine::getTargetTransformInfo(const Function
&F
) {
73 return TargetTransformInfo(LanaiTTIImpl(this, F
));
77 // Lanai Code Generator Pass Configuration Options.
78 class LanaiPassConfig
: public TargetPassConfig
{
80 LanaiPassConfig(LanaiTargetMachine
&TM
, PassManagerBase
*PassManager
)
81 : TargetPassConfig(TM
, *PassManager
) {}
83 LanaiTargetMachine
&getLanaiTargetMachine() const {
84 return getTM
<LanaiTargetMachine
>();
87 bool addInstSelector() override
;
88 void addPreSched2() override
;
89 void addPreEmitPass() override
;
94 LanaiTargetMachine::createPassConfig(PassManagerBase
&PassManager
) {
95 return new LanaiPassConfig(*this, &PassManager
);
98 // Install an instruction selector pass.
99 bool LanaiPassConfig::addInstSelector() {
100 addPass(createLanaiISelDag(getLanaiTargetMachine()));
104 // Implemented by targets that want to run passes immediately before
105 // machine code is emitted.
106 void LanaiPassConfig::addPreEmitPass() {
107 addPass(createLanaiDelaySlotFillerPass(getLanaiTargetMachine()));
110 // Run passes after prolog-epilog insertion and before the second instruction
112 void LanaiPassConfig::addPreSched2() {
113 addPass(createLanaiMemAluCombinerPass());