diff options
Diffstat (limited to 'llvm/tools/llvm-mca')
| -rw-r--r-- | llvm/tools/llvm-mca/CodeRegion.cpp | 23 | ||||
| -rw-r--r-- | llvm/tools/llvm-mca/CodeRegion.h | 23 | 
2 files changed, 22 insertions, 24 deletions
| diff --git a/llvm/tools/llvm-mca/CodeRegion.cpp b/llvm/tools/llvm-mca/CodeRegion.cpp index 83541675774..6d4192250aa 100644 --- a/llvm/tools/llvm-mca/CodeRegion.cpp +++ b/llvm/tools/llvm-mca/CodeRegion.cpp @@ -16,7 +16,12 @@  namespace llvm {  namespace mca { -bool CodeRegion::isLocInRange(llvm::SMLoc Loc) const { +CodeRegions::CodeRegions(llvm::SourceMgr &S) : SM(S) { +  // Create a default region for the input code sequence. +  Regions.emplace_back(make_unique<CodeRegion>("Default", SMLoc())); +} + +bool CodeRegion::isLocInRange(SMLoc Loc) const {    if (RangeEnd.isValid() && Loc.getPointer() > RangeEnd.getPointer())      return false;    if (RangeStart.isValid() && Loc.getPointer() < RangeStart.getPointer()) @@ -24,11 +29,11 @@ bool CodeRegion::isLocInRange(llvm::SMLoc Loc) const {    return true;  } -void CodeRegions::beginRegion(llvm::StringRef Description, llvm::SMLoc Loc) { +void CodeRegions::beginRegion(StringRef Description, SMLoc Loc) {    assert(!Regions.empty() && "Missing Default region");    const CodeRegion &CurrentRegion = *Regions.back();    if (CurrentRegion.startLoc().isValid() && !CurrentRegion.endLoc().isValid()) { -    SM.PrintMessage(Loc, llvm::SourceMgr::DK_Warning, +    SM.PrintMessage(Loc, SourceMgr::DK_Warning,                      "Ignoring invalid region start");      return;    } @@ -36,14 +41,14 @@ void CodeRegions::beginRegion(llvm::StringRef Description, llvm::SMLoc Loc) {    // Remove the default region if there are user defined regions.    if (!CurrentRegion.startLoc().isValid())      Regions.erase(Regions.begin()); -  addRegion(Description, Loc); +  Regions.emplace_back(make_unique<CodeRegion>(Description, Loc));  } -void CodeRegions::endRegion(llvm::SMLoc Loc) { +void CodeRegions::endRegion(SMLoc Loc) {    assert(!Regions.empty() && "Missing Default region");    CodeRegion &CurrentRegion = *Regions.back();    if (CurrentRegion.endLoc().isValid()) { -    SM.PrintMessage(Loc, llvm::SourceMgr::DK_Warning, +    SM.PrintMessage(Loc, SourceMgr::DK_Warning,                      "Ignoring invalid region end");      return;    } @@ -51,11 +56,11 @@ void CodeRegions::endRegion(llvm::SMLoc Loc) {    CurrentRegion.setEndLocation(Loc);  } -void CodeRegions::addInstruction(const llvm::MCInst &Instruction) { -  const llvm::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) { +                   [Loc](const UniqueCodeRegion &Region) {                       return Region->isLocInRange(Loc);                     });    if (It != Regions.rend()) diff --git a/llvm/tools/llvm-mca/CodeRegion.h b/llvm/tools/llvm-mca/CodeRegion.h index 1cdfeabfef4..cc474b78ca7 100644 --- a/llvm/tools/llvm-mca/CodeRegion.h +++ b/llvm/tools/llvm-mca/CodeRegion.h @@ -34,6 +34,7 @@  #define LLVM_TOOLS_LLVM_MCA_CODEREGION_H  #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallVector.h"  #include "llvm/ADT/StringRef.h"  #include "llvm/MC/MCInst.h"  #include "llvm/Support/SMLoc.h" @@ -50,7 +51,7 @@ class CodeRegion {    // An optional descriptor for this region.    llvm::StringRef Description;    // Instructions that form this region. -  std::vector<llvm::MCInst> Instructions; +  llvm::SmallVector<llvm::MCInst, 8> Instructions;    // Source location range.    llvm::SMLoc RangeStart;    llvm::SMLoc RangeEnd; @@ -82,20 +83,15 @@ class CodeRegions {    // A source manager. Used by the tool to generate meaningful warnings.    llvm::SourceMgr &SM; -  std::vector<std::unique_ptr<CodeRegion>> Regions; - -  // Construct a new region of code guarded by LLVM-MCA comments. -  void addRegion(llvm::StringRef Description, llvm::SMLoc Loc) { -    Regions.emplace_back(llvm::make_unique<CodeRegion>(Description, Loc)); -  } +  using UniqueCodeRegion = std::unique_ptr<CodeRegion>; +  std::vector<UniqueCodeRegion> Regions;    CodeRegions(const CodeRegions &) = delete;    CodeRegions &operator=(const CodeRegions &) = delete;  public: -  typedef std::vector<std::unique_ptr<CodeRegion>>::iterator iterator; -  typedef std::vector<std::unique_ptr<CodeRegion>>::const_iterator -      const_iterator; +  typedef std::vector<UniqueCodeRegion>::iterator iterator; +  typedef std::vector<UniqueCodeRegion>::const_iterator const_iterator;    iterator begin() { return Regions.begin(); }    iterator end() { return Regions.end(); } @@ -107,17 +103,14 @@ public:    void addInstruction(const llvm::MCInst &Instruction);    llvm::SourceMgr &getSourceMgr() const { return SM; } -  CodeRegions(llvm::SourceMgr &S) : SM(S) { -    // Create a default region for the input code sequence. -    addRegion("Default", llvm::SMLoc()); -  } +  CodeRegions(llvm::SourceMgr &S);    llvm::ArrayRef<llvm::MCInst> getInstructionSequence(unsigned Idx) const {      return Regions[Idx]->getInstructions();    }    bool empty() const { -    return llvm::all_of(Regions, [](const std::unique_ptr<CodeRegion> &Region) { +    return llvm::all_of(Regions, [](const UniqueCodeRegion &Region) {        return Region->empty();      });    } | 

