#include "VETargetMachine.h"
#include "TargetInfo/VETargetInfo.h"
#include "VE.h"
#include "VETargetTransformInfo.h"
#include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
#include "llvm/CodeGen/TargetPassConfig.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/MC/TargetRegistry.h"
using namespace llvm;
#define DEBUG_TYPE "ve"
extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeVETarget() {
RegisterTargetMachine<VETargetMachine> X(getTheVETarget());
}
static std::string computeDataLayout(const Triple &T) {
std::string Ret = "e";
Ret += "-m:e";
Ret += "-i64:64";
Ret += "-n32:64";
Ret += "-S128";
Ret += "-v64:64:64"; Ret += "-v128:64:64";
Ret += "-v256:64:64";
Ret += "-v512:64:64";
Ret += "-v1024:64:64";
Ret += "-v2048:64:64";
Ret += "-v4096:64:64";
Ret += "-v8192:64:64";
Ret += "-v16384:64:64";
return Ret;
}
static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
return RM.value_or(Reloc::Static);
}
class VEELFTargetObjectFile : public TargetLoweringObjectFileELF {
void Initialize(MCContext &Ctx, const TargetMachine &TM) override {
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
InitializeELF(TM.Options.UseInitArray);
}
};
static std::unique_ptr<TargetLoweringObjectFile> createTLOF() {
return std::make_unique<VEELFTargetObjectFile>();
}
VETargetMachine::VETargetMachine(const Target &T, const Triple &TT,
StringRef CPU, StringRef FS,
const TargetOptions &Options,
Optional<Reloc::Model> RM,
Optional<CodeModel::Model> CM,
CodeGenOpt::Level OL, bool JIT)
: LLVMTargetMachine(T, computeDataLayout(TT), TT, CPU, FS, Options,
getEffectiveRelocModel(RM),
getEffectiveCodeModel(CM, CodeModel::Small), OL),
TLOF(createTLOF()),
Subtarget(TT, std::string(CPU), std::string(FS), *this) {
initAsmInfo();
}
VETargetMachine::~VETargetMachine() = default;
TargetTransformInfo
VETargetMachine::getTargetTransformInfo(const Function &F) const {
return TargetTransformInfo(VETTIImpl(this, F));
}
namespace {
class VEPassConfig : public TargetPassConfig {
public:
VEPassConfig(VETargetMachine &TM, PassManagerBase &PM)
: TargetPassConfig(TM, PM) {}
VETargetMachine &getVETargetMachine() const {
return getTM<VETargetMachine>();
}
void addIRPasses() override;
bool addInstSelector() override;
void addPreEmitPass() override;
};
}
TargetPassConfig *VETargetMachine::createPassConfig(PassManagerBase &PM) {
return new VEPassConfig(*this, PM);
}
void VEPassConfig::addIRPasses() {
addPass(createAtomicExpandPass());
TargetPassConfig::addIRPasses();
}
bool VEPassConfig::addInstSelector() {
addPass(createVEISelDag(getVETargetMachine()));
return false;
}
void VEPassConfig::addPreEmitPass() {
addPass(createLVLGenPass());
}