[PATCH] D48428: [llvm-exegesis][NFC] Simplify LLVMState.
Clement Courbet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 21 06:45:27 PDT 2018
courbet created this revision.
courbet added a reviewer: gchatelet.
Herald added a subscriber: tschuett.
Pretty much everything we need is in llvm::TargetMachine.
Repository:
rL LLVM
https://reviews.llvm.org/D48428
Files:
tools/llvm-exegesis/lib/LlvmState.cpp
tools/llvm-exegesis/lib/LlvmState.h
Index: tools/llvm-exegesis/lib/LlvmState.h
===================================================================
--- tools/llvm-exegesis/lib/LlvmState.h
+++ 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 {
@@ -39,27 +41,31 @@
llvm::StringRef getCpuName() const { return CpuName; }
llvm::StringRef getFeatures() const { return Features; }
- const llvm::MCInstrInfo &getInstrInfo() const { return *InstrInfo; }
+ const llvm::TargetMachine &getTargetMachine() const { return *TargetMachine; }
+ std::unique_ptr<llvm::LLVMTargetMachine> createTargetMachine() const;
- const llvm::MCRegisterInfo &getRegInfo() const { return *RegInfo; }
+ const ExegesisTarget *getExegesisTarget() const { return TheExegesisTarget; }
+ 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
Index: tools/llvm-exegesis/lib/LlvmState.cpp
===================================================================
--- tools/llvm-exegesis/lib/LlvmState.cpp
+++ tools/llvm-exegesis/lib/LlvmState.cpp
@@ -25,11 +25,7 @@
std::string Error;
TheTarget = llvm::TargetRegistry::lookupTarget(TheTriple, 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));
+ TargetMachine = createTargetMachine();
}
LLVMState::LLVMState()
@@ -46,13 +42,17 @@
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));
+ TheTarget->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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48428.152284.patch
Type: text/x-patch
Size: 3671 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180621/95fbc82b/attachment.bin>
More information about the llvm-commits
mailing list