namespace exegesis {
-LLVMState::LLVMState(const std::string &Triple, const std::string &CpuName)
- : TheTriple(Triple), CpuName(CpuName) {
+LLVMState::LLVMState(const std::string &Triple, const std::string &CpuName) {
std::string Error;
- TheTarget = llvm::TargetRegistry::lookupTarget(TheTriple, Error);
+ const llvm::Target *const TheTarget =
+ llvm::TargetRegistry::lookupTarget(Triple, Error);
assert(TheTarget && "unknown target for host");
- SubtargetInfo.reset(
- TheTarget->createMCSubtargetInfo(TheTriple, CpuName, Features));
- InstrInfo.reset(TheTarget->createMCInstrInfo());
- RegInfo.reset(TheTarget->createMCRegInfo(TheTriple));
- AsmInfo.reset(TheTarget->createMCAsmInfo(*RegInfo, TheTriple));
+ const llvm::TargetOptions Options;
+ TargetMachine.reset(static_cast<llvm::LLVMTargetMachine *>(
+ TheTarget->createTargetMachine(Triple, CpuName, /*Features*/ "", Options,
+ llvm::Reloc::Model::Static)));
}
LLVMState::LLVMState()
std::unique_ptr<llvm::LLVMTargetMachine>
LLVMState::createTargetMachine() const {
- const llvm::TargetOptions Options;
return std::unique_ptr<llvm::LLVMTargetMachine>(
- static_cast<llvm::LLVMTargetMachine *>(TheTarget->createTargetMachine(
- TheTriple, CpuName, Features, Options, llvm::Reloc::Model::Static)));
+ static_cast<llvm::LLVMTargetMachine *>(
+ TargetMachine->getTarget().createTargetMachine(
+ TargetMachine->getTargetTriple().normalize(),
+ TargetMachine->getTargetCPU(),
+ TargetMachine->getTargetFeatureString(), TargetMachine->Options,
+ llvm::Reloc::Model::Static)));
}
bool LLVMState::canAssemble(const llvm::MCInst &Inst) const {
llvm::MCObjectFileInfo ObjectFileInfo;
- llvm::MCContext Context(AsmInfo.get(), RegInfo.get(), &ObjectFileInfo);
+ llvm::MCContext Context(TargetMachine->getMCAsmInfo(),
+ TargetMachine->getMCRegisterInfo(), &ObjectFileInfo);
std::unique_ptr<const llvm::MCCodeEmitter> CodeEmitter(
- TheTarget->createMCCodeEmitter(*InstrInfo, *RegInfo, Context));
+ TargetMachine->getTarget().createMCCodeEmitter(
+ *TargetMachine->getMCInstrInfo(), *TargetMachine->getMCRegisterInfo(),
+ Context));
llvm::SmallVector<char, 16> Tmp;
llvm::raw_svector_ostream OS(Tmp);
llvm::SmallVector<llvm::MCFixup, 4> Fixups;
- CodeEmitter->encodeInstruction(Inst, OS, Fixups, *SubtargetInfo);
+ CodeEmitter->encodeInstruction(Inst, OS, Fixups,
+ *TargetMachine->getMCSubtargetInfo());
return Tmp.size() > 0;
}
namespace exegesis {
+class ExegesisTarget;
+
// An object to initialize LLVM and prepare objects needed to run the
// measurements.
class LLVMState {
LLVMState(const std::string &Triple,
const std::string &CpuName); // For tests.
- llvm::StringRef getTriple() const { return TheTriple; }
- llvm::StringRef getCpuName() const { return CpuName; }
- llvm::StringRef getFeatures() const { return Features; }
+ const llvm::TargetMachine &getTargetMachine() const { return *TargetMachine; }
+ std::unique_ptr<llvm::LLVMTargetMachine> createTargetMachine() const;
- const llvm::MCInstrInfo &getInstrInfo() const { return *InstrInfo; }
+ const ExegesisTarget *getExegesisTarget() const { return TheExegesisTarget; }
- const llvm::MCRegisterInfo &getRegInfo() const { return *RegInfo; }
+ bool canAssemble(const llvm::MCInst &mc_inst) const;
+ // For convenience:
+ const llvm::MCInstrInfo &getInstrInfo() const {
+ return *TargetMachine->getMCInstrInfo();
+ }
+ const llvm::MCRegisterInfo &getRegInfo() const {
+ return *TargetMachine->getMCRegisterInfo();
+ }
const llvm::MCSubtargetInfo &getSubtargetInfo() const {
- return *SubtargetInfo;
+ return *TargetMachine->getMCSubtargetInfo();
}
- std::unique_ptr<llvm::LLVMTargetMachine> createTargetMachine() const;
-
- bool canAssemble(const llvm::MCInst &mc_inst) const;
-
private:
- std::string TheTriple;
- std::string CpuName;
- std::string Features;
- const llvm::Target *TheTarget = nullptr;
- std::unique_ptr<const llvm::MCSubtargetInfo> SubtargetInfo;
- std::unique_ptr<const llvm::MCInstrInfo> InstrInfo;
- std::unique_ptr<const llvm::MCRegisterInfo> RegInfo;
- std::unique_ptr<const llvm::MCAsmInfo> AsmInfo;
+ const ExegesisTarget *TheExegesisTarget = nullptr;
+ std::unique_ptr<const llvm::TargetMachine> TargetMachine;
};
} // namespace exegesis