LLVM  17.0.0git
VETargetMachine.cpp
Go to the documentation of this file.
1 //===-- VETargetMachine.cpp - Define TargetMachine for VE -----------------===//
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 //
10 //===----------------------------------------------------------------------===//
11 
12 #include "VETargetMachine.h"
14 #include "VE.h"
15 #include "VEMachineFunctionInfo.h"
16 #include "VETargetTransformInfo.h"
17 #include "llvm/CodeGen/Passes.h"
21 #include "llvm/MC/TargetRegistry.h"
22 #include <optional>
23 
24 using namespace llvm;
25 
26 #define DEBUG_TYPE "ve"
27 
29  // Register the target.
31 
34 }
35 
36 static std::string computeDataLayout(const Triple &T) {
37  // Aurora VE is little endian
38  std::string Ret = "e";
39 
40  // Use ELF mangling
41  Ret += "-m:e";
42 
43  // Alignments for 64 bit integers.
44  Ret += "-i64:64";
45 
46  // VE supports 32 bit and 64 bits integer on registers
47  Ret += "-n32:64";
48 
49  // Stack alignment is 128 bits
50  Ret += "-S128";
51 
52  // Vector alignments are 64 bits
53  // Need to define all of them. Otherwise, each alignment becomes
54  // the size of each data by default.
55  Ret += "-v64:64:64"; // for v2f32
56  Ret += "-v128:64:64";
57  Ret += "-v256:64:64";
58  Ret += "-v512:64:64";
59  Ret += "-v1024:64:64";
60  Ret += "-v2048:64:64";
61  Ret += "-v4096:64:64";
62  Ret += "-v8192:64:64";
63  Ret += "-v16384:64:64"; // for v256f64
64 
65  return Ret;
66 }
67 
68 static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {
69  return RM.value_or(Reloc::Static);
70 }
71 
72 namespace {
73 class VEELFTargetObjectFile : public TargetLoweringObjectFileELF {
74  void Initialize(MCContext &Ctx, const TargetMachine &TM) override {
76  InitializeELF(TM.Options.UseInitArray);
77  }
78 };
79 } // namespace
80 
81 static std::unique_ptr<TargetLoweringObjectFile> createTLOF() {
82  return std::make_unique<VEELFTargetObjectFile>();
83 }
84 
85 /// Create an Aurora VE architecture model
87  StringRef CPU, StringRef FS,
88  const TargetOptions &Options,
89  std::optional<Reloc::Model> RM,
90  std::optional<CodeModel::Model> CM,
91  CodeGenOpt::Level OL, bool JIT)
95  TLOF(createTLOF()),
96  Subtarget(TT, std::string(CPU), std::string(FS), *this) {
97  initAsmInfo();
98 }
99 
101 
104  return TargetTransformInfo(VETTIImpl(this, F));
105 }
106 
109  const TargetSubtargetInfo *STI) const {
110  return VEMachineFunctionInfo::create<VEMachineFunctionInfo>(Allocator, F,
111  STI);
112 }
113 
114 namespace {
115 /// VE Code Generator Pass Configuration Options.
116 class VEPassConfig : public TargetPassConfig {
117 public:
118  VEPassConfig(VETargetMachine &TM, PassManagerBase &PM)
119  : TargetPassConfig(TM, PM) {}
120 
121  VETargetMachine &getVETargetMachine() const {
122  return getTM<VETargetMachine>();
123  }
124 
125  void addIRPasses() override;
126  bool addInstSelector() override;
127  void addPreEmitPass() override;
128 };
129 } // namespace
130 
132  return new VEPassConfig(*this, PM);
133 }
134 
135 void VEPassConfig::addIRPasses() {
136  // VE requires atomic expand pass.
137  addPass(createAtomicExpandPass());
139 }
140 
141 bool VEPassConfig::addInstSelector() {
142  addPass(createVEISelDag(getVETargetMachine()));
143  return false;
144 }
145 
146 void VEPassConfig::addPreEmitPass() {
147  // LVLGen should be called after scheduling and register allocation
148  addPass(createLVLGenPass());
149 }
llvm::VETargetMachine::createMachineFunctionInfo
MachineFunctionInfo * createMachineFunctionInfo(BumpPtrAllocator &Allocator, const Function &F, const TargetSubtargetInfo *STI) const override
Create the target's instance of MachineFunctionInfo.
Definition: VETargetMachine.cpp:107
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::TargetMachine::STI
std::unique_ptr< const MCSubtargetInfo > STI
Definition: TargetMachine.h:109
llvm::TargetOptions
Definition: TargetOptions.h:124
T
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:76
llvm::Function
Definition: Function.h:59
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:149
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: TargetTransformInfo.h:172
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::X86AS::FS
@ FS
Definition: X86.h:201
llvm::TargetLoweringObjectFileELF
Definition: TargetLoweringObjectFileImpl.h:34
llvm::VETTIImpl
Definition: VETargetTransformInfo.h:52
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:119
llvm::initializeVEDAGToDAGISelPass
void initializeVEDAGToDAGISelPass(PassRegistry &)
LegacyPassManager.h
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::Reloc::Model
Model
Definition: CodeGen.h:25
llvm::getTheVETarget
Target & getTheVETarget()
Definition: VETargetInfo.cpp:14
llvm::MSP430Attrs::CodeModel
CodeModel
Definition: MSP430Attributes.h:37
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:24
llvm::CodeModel::Small
@ Small
Definition: CodeGen.h:31
llvm::createAtomicExpandPass
FunctionPass * createAtomicExpandPass()
AtomicExpandPass - At IR level this pass replace atomic instructions with __atomic_* library calls,...
llvm::RegisterTargetMachine
RegisterTargetMachine - Helper template for registering a target machine implementation,...
Definition: TargetRegistry.h:1354
llvm::PassRegistry
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:38
Options
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Definition: PassBuilderBindings.cpp:48
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
Passes.h
llvm::TargetPassConfig
Target-Independent Code Generator Pass Configuration Options.
Definition: TargetPassConfig.h:84
LLVMInitializeVETarget
LLVM_EXTERNAL_VISIBILITY void LLVMInitializeVETarget()
Definition: VETargetMachine.cpp:28
llvm::getEffectiveCodeModel
CodeModel::Model getEffectiveCodeModel(std::optional< CodeModel::Model > CM, CodeModel::Model Default)
Helper method for getting the code model, returning Default if CM does not have a value.
Definition: TargetMachine.h:510
llvm::EngineKind::JIT
@ JIT
Definition: ExecutionEngine.h:524
LLVM_EXTERNAL_VISIBILITY
#define LLVM_EXTERNAL_VISIBILITY
Definition: Compiler.h:127
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
llvm::createLVLGenPass
FunctionPass * createLVLGenPass()
Definition: LVLGen.cpp:38
llvm::TargetPassConfig::addIRPasses
virtual void addIRPasses()
Add common target configurable passes that perform LLVM IR to IR transforms following machine indepen...
Definition: TargetPassConfig.cpp:839
TargetPassConfig.h
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:78
llvm::getEffectiveRelocModel
static Reloc::Model getEffectiveRelocModel(std::optional< Reloc::Model > RM)
Definition: AVRTargetMachine.cpp:43
llvm::AArch64::RM
@ RM
Definition: AArch64ISelLowering.h:499
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
this
Analysis the ScalarEvolution expression for r is this
Definition: README.txt:8
llvm::Reloc::Static
@ Static
Definition: CodeGen.h:25
llvm::VETargetMachine::getTargetTransformInfo
TargetTransformInfo getTargetTransformInfo(const Function &F) const override
Get a TargetTransformInfo implementation for the target.
Definition: VETargetMachine.cpp:103
llvm::createVEISelDag
FunctionPass * createVEISelDag(VETargetMachine &TM)
createVEISelDag - This pass converts a legalized DAG into a VE-specific DAG, ready for instruction sc...
Definition: VEISelDAGToDAG.cpp:339
VETargetTransformInfo.h
llvm::TargetSubtargetInfo
TargetSubtargetInfo - Generic base class for all target subtargets.
Definition: TargetSubtargetInfo.h:62
llvm::LLVMTargetMachine::initAsmInfo
void initAsmInfo()
Definition: LLVMTargetMachine.cpp:40
llvm::VETargetMachine
Definition: VETargetMachine.h:23
VETargetInfo.h
llvm::VETargetMachine::~VETargetMachine
~VETargetMachine() override
std
Definition: BitVector.h:851
VEMachineFunctionInfo.h
llvm::TargetLoweringObjectFileELF::Initialize
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Definition: TargetLoweringObjectFileImpl.cpp:116
llvm::LLVMTargetMachine
This class describes a target machine that is implemented with the LLVM target-independent code gener...
Definition: TargetMachine.h:417
VE.h
llvm::VETargetMachine::createPassConfig
TargetPassConfig * createPassConfig(PassManagerBase &PM) override
Create a pass configuration object to be used by addPassToEmitX methods for generating a pipeline of ...
Definition: VETargetMachine.cpp:131
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:143
computeDataLayout
static std::string computeDataLayout(const Triple &T)
Definition: VETargetMachine.cpp:36
llvm::legacy::PassManagerBase
PassManagerBase - An abstract interface to allow code to add passes to a pass manager without having ...
Definition: LegacyPassManager.h:39
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
VETargetMachine.h
llvm::CodeGenOpt::Level
Level
Code generation optimization level.
Definition: CodeGen.h:57
TargetRegistry.h
llvm::MachineFunctionInfo
MachineFunctionInfo - This class can be derived from and used by targets to hold private target-speci...
Definition: MachineFunction.h:95
llvm::VETargetMachine::VETargetMachine
VETargetMachine(const Target &T, const Triple &TT, StringRef CPU, StringRef FS, const TargetOptions &Options, std::optional< Reloc::Model > RM, std::optional< CodeModel::Model > CM, CodeGenOpt::Level OL, bool JIT)
Create an Aurora VE architecture model.
Definition: VETargetMachine.cpp:86
createTLOF
static std::unique_ptr< TargetLoweringObjectFile > createTLOF()
Definition: VETargetMachine.cpp:81
SpecialSubKind::string
@ string
TargetLoweringObjectFileImpl.h