diff options
| author | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2018-10-22 15:36:15 +0000 | 
|---|---|---|
| committer | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2018-10-22 15:36:15 +0000 | 
| commit | 01b9fd6868104bc05a48c819d7516078d325b929 (patch) | |
| tree | 7b8467b5ca5b07b3b039d7d5408616233efb1c35 /llvm/tools/llvm-mca | |
| parent | 6f5cd7c67fd104942738925b235ed2ca87e6d5d6 (diff) | |
| download | bcm5719-llvm-01b9fd6868104bc05a48c819d7516078d325b929.tar.gz bcm5719-llvm-01b9fd6868104bc05a48c819d7516078d325b929.zip | |
[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".
llvm-svn: 344911
Diffstat (limited to 'llvm/tools/llvm-mca')
| -rw-r--r-- | llvm/tools/llvm-mca/CodeRegion.cpp | 6 | ||||
| -rw-r--r-- | llvm/tools/llvm-mca/CodeRegion.h | 24 | ||||
| -rw-r--r-- | llvm/tools/llvm-mca/include/SourceMgr.h | 14 | ||||
| -rw-r--r-- | llvm/tools/llvm-mca/lib/Stages/FetchStage.cpp | 2 | ||||
| -rw-r--r-- | 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 89686599650..c26658a6cf5 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<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 diff --git a/llvm/tools/llvm-mca/CodeRegion.h b/llvm/tools/llvm-mca/CodeRegion.h index 7f0025e4884..21ca8da9b53 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<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(); +    });    }  }; diff --git a/llvm/tools/llvm-mca/include/SourceMgr.h b/llvm/tools/llvm-mca/include/SourceMgr.h index 573ca7a9a00..89412836360 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 <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; } diff --git a/llvm/tools/llvm-mca/lib/Stages/FetchStage.cpp b/llvm/tools/llvm-mca/lib/Stages/FetchStage.cpp index e2cdad37ee1..8bd0bd9e3a7 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<std::unique_ptr<Instruction>> 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 9466ae7e84d..59b78ff1545 100644 --- a/llvm/tools/llvm-mca/llvm-mca.cpp +++ b/llvm/tools/llvm-mca/llvm-mca.cpp @@ -68,13 +68,15 @@ static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"),                                             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);    }  }; | 

