1 //===-- VETargetMachine.cpp - Define TargetMachine for VE -----------------===//
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 //===----------------------------------------------------------------------===//
10 //===----------------------------------------------------------------------===//
12 #include "VETargetMachine.h"
13 #include "TargetInfo/VETargetInfo.h"
15 #include "VETargetTransformInfo.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
18 #include "llvm/CodeGen/TargetPassConfig.h"
19 #include "llvm/IR/LegacyPassManager.h"
20 #include "llvm/Support/TargetRegistry.h"
24 #define DEBUG_TYPE "ve"
26 extern "C" LLVM_EXTERNAL_VISIBILITY
void LLVMInitializeVETarget() {
27 // Register the target.
28 RegisterTargetMachine
<VETargetMachine
> X(getTheVETarget());
31 static std::string
computeDataLayout(const Triple
&T
) {
32 // Aurora VE is little endian
33 std::string Ret
= "e";
38 // Alignments for 64 bit integers.
41 // VE supports 32 bit and 64 bits integer on registers
44 // Stack alignment is 128 bits
47 // Vector alignments are 64 bits
48 // Need to define all of them. Otherwise, each alignment becomes
49 // the size of each data by default.
50 Ret
+= "-v64:64:64"; // for v2f32
54 Ret
+= "-v1024:64:64";
55 Ret
+= "-v2048:64:64";
56 Ret
+= "-v4096:64:64";
57 Ret
+= "-v8192:64:64";
58 Ret
+= "-v16384:64:64"; // for v256f64
63 static Reloc::Model
getEffectiveRelocModel(Optional
<Reloc::Model
> RM
) {
64 return RM
.getValueOr(Reloc::Static
);
67 class VEELFTargetObjectFile
: public TargetLoweringObjectFileELF
{
68 void Initialize(MCContext
&Ctx
, const TargetMachine
&TM
) override
{
69 TargetLoweringObjectFileELF::Initialize(Ctx
, TM
);
70 InitializeELF(TM
.Options
.UseInitArray
);
74 static std::unique_ptr
<TargetLoweringObjectFile
> createTLOF() {
75 return std::make_unique
<VEELFTargetObjectFile
>();
78 /// Create an Aurora VE architecture model
79 VETargetMachine::VETargetMachine(const Target
&T
, const Triple
&TT
,
80 StringRef CPU
, StringRef FS
,
81 const TargetOptions
&Options
,
82 Optional
<Reloc::Model
> RM
,
83 Optional
<CodeModel::Model
> CM
,
84 CodeGenOpt::Level OL
, bool JIT
)
85 : LLVMTargetMachine(T
, computeDataLayout(TT
), TT
, CPU
, FS
, Options
,
86 getEffectiveRelocModel(RM
),
87 getEffectiveCodeModel(CM
, CodeModel::Small
), OL
),
89 Subtarget(TT
, std::string(CPU
), std::string(FS
), *this) {
93 VETargetMachine::~VETargetMachine() {}
95 TargetTransformInfo
VETargetMachine::getTargetTransformInfo(const Function
&F
) {
96 return TargetTransformInfo(VETTIImpl(this, F
));
100 /// VE Code Generator Pass Configuration Options.
101 class VEPassConfig
: public TargetPassConfig
{
103 VEPassConfig(VETargetMachine
&TM
, PassManagerBase
&PM
)
104 : TargetPassConfig(TM
, PM
) {}
106 VETargetMachine
&getVETargetMachine() const {
107 return getTM
<VETargetMachine
>();
110 void addIRPasses() override
;
111 bool addInstSelector() override
;
112 void addPreEmitPass() override
;
116 TargetPassConfig
*VETargetMachine::createPassConfig(PassManagerBase
&PM
) {
117 return new VEPassConfig(*this, PM
);
120 void VEPassConfig::addIRPasses() {
121 // VE requires atomic expand pass.
122 addPass(createAtomicExpandPass());
123 TargetPassConfig::addIRPasses();
126 bool VEPassConfig::addInstSelector() {
127 addPass(createVEISelDag(getVETargetMachine()));
131 void VEPassConfig::addPreEmitPass() {
132 // LVLGen should be called after scheduling and register allocation
133 addPass(createLVLGenPass());