llvm/tools/llvm-mca/CodeRegion.cpp
Fangrui Song 467c30721b [llvm-mca] Move namespace mca inside llvm::
Summary: This allows to remove `using namespace llvm;` in those *.cpp files

When we want to revisit the decision (everything resides in llvm::mca::*) in the future, we can move things to a nested namespace of llvm::mca::, to conceptually make them separate from the rest of llvm::mca::*

Reviewers: andreadb, mattd

Reviewed By: andreadb

Subscribers: javed.absar, tschuett, gbedwell, llvm-commits

Differential Revision: https://reviews.llvm.org/D53407

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345612 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-30 15:56:08 +00:00

68 lines
2.1 KiB
C++

//===-------------------------- CodeRegion.cpp -----------------*- C++ -* -===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
/// \file
///
/// This file implements methods from the CodeRegions interface.
///
//===----------------------------------------------------------------------===//
#include "CodeRegion.h"
namespace llvm {
namespace mca {
bool CodeRegion::isLocInRange(llvm::SMLoc Loc) const {
if (RangeEnd.isValid() && Loc.getPointer() > RangeEnd.getPointer())
return false;
if (RangeStart.isValid() && Loc.getPointer() < RangeStart.getPointer())
return false;
return true;
}
void CodeRegions::beginRegion(llvm::StringRef Description, llvm::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,
"Ignoring invalid region start");
return;
}
// Remove the default region if there are user defined regions.
if (!CurrentRegion.startLoc().isValid())
Regions.erase(Regions.begin());
addRegion(Description, Loc);
}
void CodeRegions::endRegion(llvm::SMLoc Loc) {
assert(!Regions.empty() && "Missing Default region");
CodeRegion &CurrentRegion = *Regions.back();
if (CurrentRegion.endLoc().isValid()) {
SM.PrintMessage(Loc, llvm::SourceMgr::DK_Warning,
"Ignoring invalid region end");
return;
}
CurrentRegion.setEndLocation(Loc);
}
void CodeRegions::addInstruction(const llvm::MCInst &Instruction) {
const llvm::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(Instruction);
}
} // namespace mca
} // namespace llvm