Index: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp +++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp @@ -63,8 +63,9 @@ unsigned Opcode, unsigned NumRepetitions) const { InstructionBenchmark InstrBenchmark; InstrBenchmark.Mode = getMode(); - InstrBenchmark.CpuName = State.getCpuName(); - InstrBenchmark.LLVMTriple = State.getTriple(); + InstrBenchmark.CpuName = State.getTargetMachine().getTargetCPU(); + InstrBenchmark.LLVMTriple = + State.getTargetMachine().getTargetTriple().normalize(); InstrBenchmark.NumRepetitions = NumRepetitions; InstrBenchmark.Info = Configuration.Info; Index: llvm/trunk/tools/llvm-exegesis/lib/LlvmState.h =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/LlvmState.h +++ llvm/trunk/tools/llvm-exegesis/lib/LlvmState.h @@ -26,6 +26,8 @@ namespace exegesis { +class ExegesisTarget; + // An object to initialize LLVM and prepare objects needed to run the // measurements. class LLVMState { @@ -35,31 +37,27 @@ 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 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 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 SubtargetInfo; - std::unique_ptr InstrInfo; - std::unique_ptr RegInfo; - std::unique_ptr AsmInfo; + const ExegesisTarget *TheExegesisTarget = nullptr; + std::unique_ptr TargetMachine; }; } // namespace exegesis Index: llvm/trunk/tools/llvm-exegesis/lib/LlvmState.cpp =================================================================== --- llvm/trunk/tools/llvm-exegesis/lib/LlvmState.cpp +++ llvm/trunk/tools/llvm-exegesis/lib/LlvmState.cpp @@ -20,16 +20,15 @@ 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( + TheTarget->createTargetMachine(Triple, CpuName, /*Features*/ "", Options, + llvm::Reloc::Model::Static))); } LLVMState::LLVMState() @@ -38,21 +37,28 @@ std::unique_ptr LLVMState::createTargetMachine() const { - const llvm::TargetOptions Options; return std::unique_ptr( - static_cast(TheTarget->createTargetMachine( - TheTriple, CpuName, Features, Options, llvm::Reloc::Model::Static))); + static_cast( + 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 CodeEmitter( - TheTarget->createMCCodeEmitter(*InstrInfo, *RegInfo, Context)); + TargetMachine->getTarget().createMCCodeEmitter( + *TargetMachine->getMCInstrInfo(), *TargetMachine->getMCRegisterInfo(), + Context)); llvm::SmallVector Tmp; llvm::raw_svector_ostream OS(Tmp); llvm::SmallVector Fixups; - CodeEmitter->encodeInstruction(Inst, OS, Fixups, *SubtargetInfo); + CodeEmitter->encodeInstruction(Inst, OS, Fixups, + *TargetMachine->getMCSubtargetInfo()); return Tmp.size() > 0; }