2016-03-28 15:09:54 +02:00
|
|
|
//===-- LanaiTargetMachine.cpp - Define TargetMachine for Lanai ---------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Implements the info about Lanai target spec.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "LanaiTargetMachine.h"
|
|
|
|
|
|
|
|
#include "Lanai.h"
|
|
|
|
#include "LanaiTargetObjectFile.h"
|
|
|
|
#include "LanaiTargetTransformInfo.h"
|
|
|
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
|
|
|
#include "llvm/CodeGen/Passes.h"
|
|
|
|
#include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
|
2016-05-20 23:41:53 +02:00
|
|
|
#include "llvm/CodeGen/TargetPassConfig.h"
|
2016-03-28 15:09:54 +02:00
|
|
|
#include "llvm/Support/FormattedStream.h"
|
|
|
|
#include "llvm/Support/TargetRegistry.h"
|
|
|
|
#include "llvm/Target/TargetOptions.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
void initializeLanaiMemAluCombinerPass(PassRegistry &);
|
|
|
|
} // namespace llvm
|
|
|
|
|
|
|
|
extern "C" void LLVMInitializeLanaiTarget() {
|
|
|
|
// Register the target.
|
2016-10-10 01:00:34 +02:00
|
|
|
RegisterTargetMachine<LanaiTargetMachine> registered_target(
|
|
|
|
getTheLanaiTarget());
|
2016-03-28 15:09:54 +02:00
|
|
|
}
|
|
|
|
|
2016-07-16 00:38:32 +02:00
|
|
|
static std::string computeDataLayout() {
|
2016-03-28 15:09:54 +02:00
|
|
|
// Data layout (keep in sync with clang/lib/Basic/Targets.cpp)
|
|
|
|
return "E" // Big endian
|
|
|
|
"-m:e" // ELF name manging
|
|
|
|
"-p:32:32" // 32-bit pointers, 32 bit aligned
|
|
|
|
"-i64:64" // 64 bit integers, 64 bit aligned
|
|
|
|
"-a:0:32" // 32 bit alignment of objects of aggregate type
|
|
|
|
"-n32" // 32 bit native integer width
|
|
|
|
"-S64"; // 64 bit natural stack alignment
|
|
|
|
}
|
|
|
|
|
2016-07-16 00:38:32 +02:00
|
|
|
static Reloc::Model getEffectiveRelocModel(Optional<Reloc::Model> RM) {
|
2016-05-20 05:21:37 +02:00
|
|
|
if (!RM.hasValue())
|
2016-05-20 23:41:53 +02:00
|
|
|
return Reloc::PIC_;
|
2016-05-20 05:21:37 +02:00
|
|
|
return *RM;
|
|
|
|
}
|
|
|
|
|
2017-08-03 04:16:21 +02:00
|
|
|
static CodeModel::Model getEffectiveCodeModel(Optional<CodeModel::Model> CM) {
|
|
|
|
if (CM)
|
|
|
|
return *CM;
|
|
|
|
return CodeModel::Medium;
|
|
|
|
}
|
|
|
|
|
2016-05-20 05:21:37 +02:00
|
|
|
LanaiTargetMachine::LanaiTargetMachine(const Target &T, const Triple &TT,
|
2016-03-28 15:09:54 +02:00
|
|
|
StringRef Cpu, StringRef FeatureString,
|
|
|
|
const TargetOptions &Options,
|
2016-05-20 05:21:37 +02:00
|
|
|
Optional<Reloc::Model> RM,
|
2017-08-03 04:16:21 +02:00
|
|
|
Optional<CodeModel::Model> CodeModel,
|
|
|
|
CodeGenOpt::Level OptLevel, bool JIT)
|
2016-07-16 00:38:32 +02:00
|
|
|
: LLVMTargetMachine(T, computeDataLayout(), TT, Cpu, FeatureString, Options,
|
2017-08-03 04:16:21 +02:00
|
|
|
getEffectiveRelocModel(RM),
|
|
|
|
getEffectiveCodeModel(CodeModel), OptLevel),
|
|
|
|
Subtarget(TT, Cpu, FeatureString, *this, Options, getCodeModel(),
|
|
|
|
OptLevel),
|
2016-03-28 15:09:54 +02:00
|
|
|
TLOF(new LanaiTargetObjectFile()) {
|
|
|
|
initAsmInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
TargetIRAnalysis LanaiTargetMachine::getTargetIRAnalysis() {
|
|
|
|
return TargetIRAnalysis([this](const Function &F) {
|
|
|
|
return TargetTransformInfo(LanaiTTIImpl(this, F));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
// Lanai Code Generator Pass Configuration Options.
|
|
|
|
class LanaiPassConfig : public TargetPassConfig {
|
|
|
|
public:
|
2017-05-30 23:36:41 +02:00
|
|
|
LanaiPassConfig(LanaiTargetMachine &TM, PassManagerBase *PassManager)
|
2016-03-28 15:09:54 +02:00
|
|
|
: TargetPassConfig(TM, *PassManager) {}
|
|
|
|
|
|
|
|
LanaiTargetMachine &getLanaiTargetMachine() const {
|
|
|
|
return getTM<LanaiTargetMachine>();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool addInstSelector() override;
|
|
|
|
void addPreSched2() override;
|
|
|
|
void addPreEmitPass() override;
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TargetPassConfig *
|
|
|
|
LanaiTargetMachine::createPassConfig(PassManagerBase &PassManager) {
|
2017-05-30 23:36:41 +02:00
|
|
|
return new LanaiPassConfig(*this, &PassManager);
|
2016-03-28 15:09:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Install an instruction selector pass.
|
|
|
|
bool LanaiPassConfig::addInstSelector() {
|
|
|
|
addPass(createLanaiISelDag(getLanaiTargetMachine()));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implemented by targets that want to run passes immediately before
|
|
|
|
// machine code is emitted.
|
|
|
|
void LanaiPassConfig::addPreEmitPass() {
|
|
|
|
addPass(createLanaiDelaySlotFillerPass(getLanaiTargetMachine()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run passes after prolog-epilog insertion and before the second instruction
|
|
|
|
// scheduling pass.
|
|
|
|
void LanaiPassConfig::addPreSched2() {
|
|
|
|
addPass(createLanaiMemAluCombinerPass());
|
|
|
|
}
|