From 01b9fd6868104bc05a48c819d7516078d325b929 Mon Sep 17 00:00:00 2001 From: Andrea Di Biagio Date: Mon, 22 Oct 2018 15:36:15 +0000 Subject: [PATCH] [llvm-mca] Use llvm::ArrayRef in class SourceMgr. NFCI Class SourceMgr now uses type ArrayRef to reference the sequence of code from a "CodeRegion". llvm-svn: 344911 --- llvm/tools/llvm-mca/CodeRegion.cpp | 6 +++--- llvm/tools/llvm-mca/CodeRegion.h | 24 ++++++++++-------------- llvm/tools/llvm-mca/include/SourceMgr.h | 14 +++++++------- llvm/tools/llvm-mca/lib/Stages/FetchStage.cpp | 2 +- llvm/tools/llvm-mca/llvm-mca.cpp | 18 ++++++++++-------- 5 files changed, 31 insertions(+), 33 deletions(-) diff --git a/llvm/tools/llvm-mca/CodeRegion.cpp b/llvm/tools/llvm-mca/CodeRegion.cpp index 8968659..c26658a 100644 --- a/llvm/tools/llvm-mca/CodeRegion.cpp +++ b/llvm/tools/llvm-mca/CodeRegion.cpp @@ -52,15 +52,15 @@ void CodeRegions::endRegion(SMLoc Loc) { CurrentRegion.setEndLocation(Loc); } -void CodeRegions::addInstruction(std::unique_ptr Instruction) { - const SMLoc &Loc = Instruction->getLoc(); +void CodeRegions::addInstruction(const MCInst &Instruction) { + const SMLoc &Loc = Instruction.getLoc(); const auto It = std::find_if(Regions.rbegin(), Regions.rend(), [Loc](const std::unique_ptr &Region) { return Region->isLocInRange(Loc); }); if (It != Regions.rend()) - (*It)->addInstruction(std::move(Instruction)); + (*It)->addInstruction(Instruction); } } // namespace mca diff --git a/llvm/tools/llvm-mca/CodeRegion.h b/llvm/tools/llvm-mca/CodeRegion.h index 7f0025e..21ca8da 100644 --- a/llvm/tools/llvm-mca/CodeRegion.h +++ b/llvm/tools/llvm-mca/CodeRegion.h @@ -34,6 +34,7 @@ #ifndef LLVM_TOOLS_LLVM_MCA_CODEREGION_H #define LLVM_TOOLS_LLVM_MCA_CODEREGION_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/MC/MCInst.h" #include "llvm/Support/SMLoc.h" @@ -49,7 +50,7 @@ class CodeRegion { // An optional descriptor for this region. llvm::StringRef Description; // Instructions that form this region. - std::vector> Instructions; + std::vector Instructions; // Source location range. llvm::SMLoc RangeStart; llvm::SMLoc RangeEnd; @@ -61,8 +62,8 @@ public: CodeRegion(llvm::StringRef Desc, llvm::SMLoc Start) : Description(Desc), RangeStart(Start), RangeEnd() {} - void addInstruction(std::unique_ptr Instruction) { - Instructions.emplace_back(std::move(Instruction)); + void addInstruction(const llvm::MCInst &Instruction) { + Instructions.emplace_back(Instruction); } llvm::SMLoc startLoc() const { return RangeStart; } @@ -72,10 +73,7 @@ public: bool empty() const { return Instructions.empty(); } bool isLocInRange(llvm::SMLoc Loc) const; - const std::vector> & - getInstructions() const { - return Instructions; - } + llvm::ArrayRef getInstructions() const { return Instructions; } llvm::StringRef getDescription() const { return Description; } }; @@ -106,23 +104,21 @@ public: void beginRegion(llvm::StringRef Description, llvm::SMLoc Loc); void endRegion(llvm::SMLoc Loc); - void addInstruction(std::unique_ptr Instruction); + void addInstruction(const llvm::MCInst &Instruction); CodeRegions(llvm::SourceMgr &S) : SM(S) { // Create a default region for the input code sequence. addRegion("Default", llvm::SMLoc()); } - const std::vector> & - getInstructionSequence(unsigned Idx) const { + llvm::ArrayRef getInstructionSequence(unsigned Idx) const { return Regions[Idx]->getInstructions(); } bool empty() const { - return std::all_of(Regions.begin(), Regions.end(), - [](const std::unique_ptr &Region) { - return Region->empty(); - }); + return llvm::all_of(Regions, [](const std::unique_ptr &Region) { + return Region->empty(); + }); } }; diff --git a/llvm/tools/llvm-mca/include/SourceMgr.h b/llvm/tools/llvm-mca/include/SourceMgr.h index 573ca7a..8941283 100644 --- a/llvm/tools/llvm-mca/include/SourceMgr.h +++ b/llvm/tools/llvm-mca/include/SourceMgr.h @@ -16,29 +16,29 @@ #ifndef LLVM_TOOLS_LLVM_MCA_SOURCEMGR_H #define LLVM_TOOLS_LLVM_MCA_SOURCEMGR_H +#include "llvm/ADT/ArrayRef.h" #include "llvm/MC/MCInst.h" #include namespace mca { -typedef std::pair SourceRef; +typedef std::pair SourceRef; class SourceMgr { - using InstVec = std::vector>; - const InstVec &Sequence; + llvm::ArrayRef Sequence; unsigned Current; unsigned Iterations; static const unsigned DefaultIterations = 100; public: - SourceMgr(const InstVec &MCInstSequence, unsigned NumIterations) + SourceMgr(llvm::ArrayRef MCInstSequence, unsigned NumIterations) : Sequence(MCInstSequence), Current(0), Iterations(NumIterations ? NumIterations : DefaultIterations) {} unsigned getCurrentIteration() const { return Current / Sequence.size(); } unsigned getNumIterations() const { return Iterations; } unsigned size() const { return Sequence.size(); } - const InstVec &getSequence() const { return Sequence; } + llvm::ArrayRef getSequence() const { return Sequence; } bool hasNext() const { return Current < (Iterations * size()); } void updateNext() { Current++; } @@ -46,7 +46,7 @@ public: const SourceRef peekNext() const { assert(hasNext() && "Already at end of sequence!"); unsigned Index = getCurrentInstructionIndex(); - return SourceRef(Current, Sequence[Index].get()); + return SourceRef(Current, Sequence[Index]); } unsigned getCurrentInstructionIndex() const { @@ -54,7 +54,7 @@ public: } const llvm::MCInst &getMCInstFromIndex(unsigned Index) const { - return *Sequence[Index % size()]; + return Sequence[Index % size()]; } bool isEmpty() const { return size() == 0; } diff --git a/llvm/tools/llvm-mca/lib/Stages/FetchStage.cpp b/llvm/tools/llvm-mca/lib/Stages/FetchStage.cpp index e2cdad3..8bd0bd9 100644 --- a/llvm/tools/llvm-mca/lib/Stages/FetchStage.cpp +++ b/llvm/tools/llvm-mca/lib/Stages/FetchStage.cpp @@ -36,7 +36,7 @@ llvm::Error FetchStage::getNextInstruction() { return llvm::ErrorSuccess(); const SourceRef SR = SM.peekNext(); llvm::Expected> InstOrErr = - IB.createInstruction(*SR.second); + IB.createInstruction(SR.second); if (!InstOrErr) return InstOrErr.takeError(); CurrentInstruction = std::move(InstOrErr.get()); diff --git a/llvm/tools/llvm-mca/llvm-mca.cpp b/llvm/tools/llvm-mca/llvm-mca.cpp index 9466ae7..59b78ff 100644 --- a/llvm/tools/llvm-mca/llvm-mca.cpp +++ b/llvm/tools/llvm-mca/llvm-mca.cpp @@ -68,13 +68,15 @@ static cl::opt OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename")); static cl::opt - ArchName("march", cl::desc("Target arch to assemble for, " - "see -version for available targets"), + ArchName("march", + cl::desc("Target arch to assemble for, " + "see -version for available targets"), cl::cat(ToolOptions)); static cl::opt - TripleName("mtriple", cl::desc("Target triple to assemble for, " - "see -version for available targets"), + TripleName("mtriple", + cl::desc("Target triple to assemble for, " + "see -version for available targets"), cl::cat(ToolOptions)); static cl::opt @@ -270,9 +272,10 @@ public: : MCStreamer(Context), Regions(R) {} // We only want to intercept the emission of new instructions. - virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, + virtual void EmitInstruction(const MCInst &Inst, + const MCSubtargetInfo & /* unused */, bool /* unused */) override { - Regions.addInstruction(llvm::make_unique(Inst)); + Regions.addInstruction(Inst); } bool EmitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override { @@ -290,8 +293,7 @@ public: void EmitCOFFSymbolType(int Type) override {} void EndCOFFSymbolDef() override {} - const std::vector> & - GetInstructionSequence(unsigned Index) const { + ArrayRef GetInstructionSequence(unsigned Index) const { return Regions.getInstructionSequence(Index); } }; -- 2.7.4