[llvm] r335237 - [llvm-exegesis][NFC] Simplify LLVMState.
Clement Courbet via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 21 07:11:09 PDT 2018
Author: courbet
Date: Thu Jun 21 07:11:09 2018
New Revision: 335237
URL: http://llvm.org/viewvc/llvm-project?rev=335237&view=rev
Log:
[llvm-exegesis][NFC] Simplify LLVMState.
Summary: Pretty much everything we need is in llvm::TargetMachine.
Reviewers: gchatelet
Subscribers: llvm-commits, tschuett
Differential Revision: https://reviews.llvm.org/D48428
Modified:
llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
llvm/trunk/tools/llvm-exegesis/lib/LlvmState.cpp
llvm/trunk/tools/llvm-exegesis/lib/LlvmState.h
Modified: llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp?rev=335237&r1=335236&r2=335237&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/BenchmarkRunner.cpp Thu Jun 21 07:11:09 2018
@@ -63,8 +63,9 @@ BenchmarkRunner::runOne(const BenchmarkC
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;
Modified: llvm/trunk/tools/llvm-exegesis/lib/LlvmState.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/LlvmState.cpp?rev=335237&r1=335236&r2=335237&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/LlvmState.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/LlvmState.cpp Thu Jun 21 07:11:09 2018
@@ -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<llvm::LLVMTargetMachine *>(
+ TheTarget->createTargetMachine(Triple, CpuName, /*Features*/ "", Options,
+ llvm::Reloc::Model::Static)));
}
LLVMState::LLVMState()
@@ -38,21 +37,28 @@ 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;
}
Modified: llvm/trunk/tools/llvm-exegesis/lib/LlvmState.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/LlvmState.h?rev=335237&r1=335236&r2=335237&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/LlvmState.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/LlvmState.h Thu Jun 21 07:11:09 2018
@@ -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 @@ public:
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
More information about the llvm-commits
mailing list