diff options
author | Pavel Kosov <kpdev42@gmail.com> | 2023-04-04 09:17:50 +0300 |
---|---|---|
committer | Pavel Kosov <kpdev42@gmail.com> | 2023-04-04 09:17:50 +0300 |
commit | 39fc67b8af707f6bdcbcfbec1e17f14ffbaeecb8 (patch) | |
tree | db6cff084c67a2aca10014a0b2f4e55ee15befdb /llvm/tools/llvm-exegesis/lib/Analysis.cpp | |
parent | 1f60c8d025d55f6156c93a63aa3b01f27aabee39 (diff) | |
download | llvm-39fc67b8af707f6bdcbcfbec1e17f14ffbaeecb8.zip llvm-39fc67b8af707f6bdcbcfbec1e17f14ffbaeecb8.tar.gz llvm-39fc67b8af707f6bdcbcfbec1e17f14ffbaeecb8.tar.bz2 |
[llvm-exegesis] Factor out DisassemblerHelper from the Analysis class
As part of preparing the reports, the Analysis class needs to print
machine instructions in a disassembled form. For this purpose, the class
has four fields (namely Context_, AsmInfo_, InstPrinter_ and Disasm_).
All the constructor of the Analysis class does is conditionally
initializing these four fields.
This commit factors out the logic for decoding machine code and printing
it in an assembler form into a separate DisassemblerHelper class.
~~
Huawei RRI, OS Lab
Reviewed By: courbet
Differential Revision: https://reviews.llvm.org/D147156
Diffstat (limited to 'llvm/tools/llvm-exegesis/lib/Analysis.cpp')
-rw-r--r-- | llvm/tools/llvm-exegesis/lib/Analysis.cpp | 21 |
1 files changed, 3 insertions, 18 deletions
diff --git a/llvm/tools/llvm-exegesis/lib/Analysis.cpp b/llvm/tools/llvm-exegesis/lib/Analysis.cpp index f6ee8f6..7c44373 100644 --- a/llvm/tools/llvm-exegesis/lib/Analysis.cpp +++ b/llvm/tools/llvm-exegesis/lib/Analysis.cpp @@ -102,12 +102,11 @@ template <typename EscapeTag, EscapeTag Tag> void Analysis::writeSnippet(raw_ostream &OS, ArrayRef<uint8_t> Bytes, const char *Separator) const { SmallVector<std::string, 3> Lines; - const auto &SI = State_.getSubtargetInfo(); // Parse the asm snippet and print it. while (!Bytes.empty()) { MCInst MI; uint64_t MISize = 0; - if (!Disasm_->getInstruction(MI, MISize, Bytes, 0, nulls())) { + if (!DisasmHelper_->decodeInst(MI, MISize, Bytes)) { writeEscaped<Tag>(OS, join(Lines, Separator)); writeEscaped<Tag>(OS, Separator); writeEscaped<Tag>(OS, "[error decoding asm snippet]"); @@ -115,7 +114,7 @@ void Analysis::writeSnippet(raw_ostream &OS, ArrayRef<uint8_t> Bytes, } SmallString<128> InstPrinterStr; // FIXME: magic number. raw_svector_ostream OSS(InstPrinterStr); - InstPrinter_->printInst(&MI, 0, "", SI, OSS); + DisasmHelper_->printInst(&MI, OSS); Bytes = Bytes.drop_front(MISize); Lines.emplace_back(InstPrinterStr.str().trim()); } @@ -163,21 +162,7 @@ Analysis::Analysis(const LLVMState &State, if (Clustering.getPoints().empty()) return; - MCTargetOptions MCOptions; - const auto &TM = State.getTargetMachine(); - const auto &Triple = TM.getTargetTriple(); - AsmInfo_.reset(TM.getTarget().createMCAsmInfo(State_.getRegInfo(), - Triple.str(), MCOptions)); - InstPrinter_.reset(TM.getTarget().createMCInstPrinter( - Triple, 0 /*default variant*/, *AsmInfo_, State_.getInstrInfo(), - State_.getRegInfo())); - - Context_ = std::make_unique<MCContext>( - Triple, AsmInfo_.get(), &State_.getRegInfo(), &State_.getSubtargetInfo()); - Disasm_.reset(TM.getTarget().createMCDisassembler(State_.getSubtargetInfo(), - *Context_)); - assert(Disasm_ && "cannot create MCDisassembler. missing call to " - "InitializeXXXTargetDisassembler ?"); + DisasmHelper_ = std::make_unique<DisassemblerHelper>(State); } template <> |