Path: blob/main/contrib/llvm-project/llvm/lib/Target/VE/VETargetMachine.cpp
35269 views
//===-- VETargetMachine.cpp - Define TargetMachine for VE -----------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8//9//===----------------------------------------------------------------------===//1011#include "VETargetMachine.h"12#include "TargetInfo/VETargetInfo.h"13#include "VE.h"14#include "VEMachineFunctionInfo.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/MC/TargetRegistry.h"21#include <optional>2223using namespace llvm;2425#define DEBUG_TYPE "ve"2627extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeVETarget() {28// Register the target.29RegisterTargetMachine<VETargetMachine> X(getTheVETarget());3031PassRegistry &PR = *PassRegistry::getPassRegistry();32initializeVEDAGToDAGISelLegacyPass(PR);33}3435static std::string computeDataLayout(const Triple &T) {36// Aurora VE is little endian37std::string Ret = "e";3839// Use ELF mangling40Ret += "-m:e";4142// Alignments for 64 bit integers.43Ret += "-i64:64";4445// VE supports 32 bit and 64 bits integer on registers46Ret += "-n32:64";4748// Stack alignment is 128 bits49Ret += "-S128";5051// Vector alignments are 64 bits52// Need to define all of them. Otherwise, each alignment becomes53// the size of each data by default.54Ret += "-v64:64:64"; // for v2f3255Ret += "-v128:64:64";56Ret += "-v256:64:64";57Ret += "-v512:64:64";58Ret += "-v1024:64:64";59Ret += "-v2048:64:64";60Ret += "-v4096:64:64";61Ret += "-v8192:64:64";62Ret += "-v16384:64:64"; // for v256f646364return Ret;65}6667static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM) {68return RM.value_or(Reloc::Static);69}7071namespace {72class VEELFTargetObjectFile : public TargetLoweringObjectFileELF {73void Initialize(MCContext &Ctx, const TargetMachine &TM) override {74TargetLoweringObjectFileELF::Initialize(Ctx, TM);75InitializeELF(TM.Options.UseInitArray);76}77};78} // namespace7980static std::unique_ptr<TargetLoweringObjectFile> createTLOF() {81return std::make_unique<VEELFTargetObjectFile>();82}8384/// Create an Aurora VE architecture model85VETargetMachine::VETargetMachine(const Target &T, const Triple &TT,86StringRef CPU, StringRef FS,87const TargetOptions &Options,88std::optional<Reloc::Model> RM,89std::optional<CodeModel::Model> CM,90CodeGenOptLevel OL, bool JIT)91: LLVMTargetMachine(T, computeDataLayout(TT), TT, CPU, FS, Options,92getEffectiveRelocModel(RM),93getEffectiveCodeModel(CM, CodeModel::Small), OL),94TLOF(createTLOF()),95Subtarget(TT, std::string(CPU), std::string(FS), *this) {96initAsmInfo();97}9899VETargetMachine::~VETargetMachine() = default;100101TargetTransformInfo102VETargetMachine::getTargetTransformInfo(const Function &F) const {103return TargetTransformInfo(VETTIImpl(this, F));104}105106MachineFunctionInfo *VETargetMachine::createMachineFunctionInfo(107BumpPtrAllocator &Allocator, const Function &F,108const TargetSubtargetInfo *STI) const {109return VEMachineFunctionInfo::create<VEMachineFunctionInfo>(Allocator, F,110STI);111}112113namespace {114/// VE Code Generator Pass Configuration Options.115class VEPassConfig : public TargetPassConfig {116public:117VEPassConfig(VETargetMachine &TM, PassManagerBase &PM)118: TargetPassConfig(TM, PM) {}119120VETargetMachine &getVETargetMachine() const {121return getTM<VETargetMachine>();122}123124void addIRPasses() override;125bool addInstSelector() override;126void addPreEmitPass() override;127};128} // namespace129130TargetPassConfig *VETargetMachine::createPassConfig(PassManagerBase &PM) {131return new VEPassConfig(*this, PM);132}133134void VEPassConfig::addIRPasses() {135// VE requires atomic expand pass.136addPass(createAtomicExpandLegacyPass());137TargetPassConfig::addIRPasses();138}139140bool VEPassConfig::addInstSelector() {141addPass(createVEISelDag(getVETargetMachine()));142return false;143}144145void VEPassConfig::addPreEmitPass() {146// LVLGen should be called after scheduling and register allocation147addPass(createLVLGenPass());148}149150151