[llvm] r344911 - [llvm-mca] Use llvm::ArrayRef in class SourceMgr. NFCI
Andrea Di Biagio via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 22 08:36:16 PDT 2018
Author: adibiagio
Date: Mon Oct 22 08:36:15 2018
New Revision: 344911
URL: http://llvm.org/viewvc/llvm-project?rev=344911&view=rev
Log:
[llvm-mca] Use llvm::ArrayRef in class SourceMgr. NFCI
Class SourceMgr now uses type ArrayRef<MCInst> to reference the
sequence of code from a "CodeRegion".
Modified:
llvm/trunk/tools/llvm-mca/CodeRegion.cpp
llvm/trunk/tools/llvm-mca/CodeRegion.h
llvm/trunk/tools/llvm-mca/include/SourceMgr.h
llvm/trunk/tools/llvm-mca/lib/Stages/FetchStage.cpp
llvm/trunk/tools/llvm-mca/llvm-mca.cpp
Modified: llvm/trunk/tools/llvm-mca/CodeRegion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/CodeRegion.cpp?rev=344911&r1=344910&r2=344911&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/CodeRegion.cpp (original)
+++ llvm/trunk/tools/llvm-mca/CodeRegion.cpp Mon Oct 22 08:36:15 2018
@@ -52,15 +52,15 @@ void CodeRegions::endRegion(SMLoc Loc) {
CurrentRegion.setEndLocation(Loc);
}
-void CodeRegions::addInstruction(std::unique_ptr<const MCInst> 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<CodeRegion> &Region) {
return Region->isLocInRange(Loc);
});
if (It != Regions.rend())
- (*It)->addInstruction(std::move(Instruction));
+ (*It)->addInstruction(Instruction);
}
} // namespace mca
Modified: llvm/trunk/tools/llvm-mca/CodeRegion.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/CodeRegion.h?rev=344911&r1=344910&r2=344911&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/CodeRegion.h (original)
+++ llvm/trunk/tools/llvm-mca/CodeRegion.h Mon Oct 22 08:36:15 2018
@@ -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<std::unique_ptr<const llvm::MCInst>> Instructions;
+ std::vector<llvm::MCInst> 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<const llvm::MCInst> 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<std::unique_ptr<const llvm::MCInst>> &
- getInstructions() const {
- return Instructions;
- }
+ llvm::ArrayRef<llvm::MCInst> 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<const llvm::MCInst> 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<std::unique_ptr<const llvm::MCInst>> &
- getInstructionSequence(unsigned Idx) const {
+ llvm::ArrayRef<llvm::MCInst> getInstructionSequence(unsigned Idx) const {
return Regions[Idx]->getInstructions();
}
bool empty() const {
- return std::all_of(Regions.begin(), Regions.end(),
- [](const std::unique_ptr<CodeRegion> &Region) {
- return Region->empty();
- });
+ return llvm::all_of(Regions, [](const std::unique_ptr<CodeRegion> &Region) {
+ return Region->empty();
+ });
}
};
Modified: llvm/trunk/tools/llvm-mca/include/SourceMgr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/include/SourceMgr.h?rev=344911&r1=344910&r2=344911&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/include/SourceMgr.h (original)
+++ llvm/trunk/tools/llvm-mca/include/SourceMgr.h Mon Oct 22 08:36:15 2018
@@ -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 <vector>
namespace mca {
-typedef std::pair<unsigned, const llvm::MCInst *> SourceRef;
+typedef std::pair<unsigned, const llvm::MCInst &> SourceRef;
class SourceMgr {
- using InstVec = std::vector<std::unique_ptr<const llvm::MCInst>>;
- const InstVec &Sequence;
+ llvm::ArrayRef<llvm::MCInst> Sequence;
unsigned Current;
unsigned Iterations;
static const unsigned DefaultIterations = 100;
public:
- SourceMgr(const InstVec &MCInstSequence, unsigned NumIterations)
+ SourceMgr(llvm::ArrayRef<llvm::MCInst> 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<llvm::MCInst> 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; }
Modified: llvm/trunk/tools/llvm-mca/lib/Stages/FetchStage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/lib/Stages/FetchStage.cpp?rev=344911&r1=344910&r2=344911&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/lib/Stages/FetchStage.cpp (original)
+++ llvm/trunk/tools/llvm-mca/lib/Stages/FetchStage.cpp Mon Oct 22 08:36:15 2018
@@ -36,7 +36,7 @@ llvm::Error FetchStage::getNextInstructi
return llvm::ErrorSuccess();
const SourceRef SR = SM.peekNext();
llvm::Expected<std::unique_ptr<Instruction>> InstOrErr =
- IB.createInstruction(*SR.second);
+ IB.createInstruction(SR.second);
if (!InstOrErr)
return InstOrErr.takeError();
CurrentInstruction = std::move(InstOrErr.get());
Modified: llvm/trunk/tools/llvm-mca/llvm-mca.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/llvm-mca.cpp?rev=344911&r1=344910&r2=344911&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/llvm-mca.cpp (original)
+++ llvm/trunk/tools/llvm-mca/llvm-mca.cpp Mon Oct 22 08:36:15 2018
@@ -68,13 +68,15 @@ static cl::opt<std::string> OutputFilena
cl::value_desc("filename"));
static cl::opt<std::string>
- 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<std::string>
- 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<std::string>
@@ -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<const MCInst>(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<std::unique_ptr<const MCInst>> &
- GetInstructionSequence(unsigned Index) const {
+ ArrayRef<MCInst> GetInstructionSequence(unsigned Index) const {
return Regions.getInstructionSequence(Index);
}
};
More information about the llvm-commits
mailing list