Restore the LoopInstSimplify pass, reverting r327329 that removed it.
[llvm-complete.git] / tools / llvm-mca / CodeRegion.cpp
blob896865996504201e11b6f0e93adf115fac33ece2
1 //===-------------------------- CodeRegion.cpp -----------------*- C++ -* -===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 /// \file
10 ///
11 /// This file implements methods from the CodeRegions interface.
12 ///
13 //===----------------------------------------------------------------------===//
15 #include "CodeRegion.h"
17 using namespace llvm;
19 namespace mca {
21 bool CodeRegion::isLocInRange(SMLoc Loc) const {
22 if (RangeEnd.isValid() && Loc.getPointer() > RangeEnd.getPointer())
23 return false;
24 if (RangeStart.isValid() && Loc.getPointer() < RangeStart.getPointer())
25 return false;
26 return true;
29 void CodeRegions::beginRegion(StringRef Description, SMLoc Loc) {
30 assert(!Regions.empty() && "Missing Default region");
31 const CodeRegion &CurrentRegion = *Regions.back();
32 if (CurrentRegion.startLoc().isValid() && !CurrentRegion.endLoc().isValid()) {
33 SM.PrintMessage(Loc, SourceMgr::DK_Warning,
34 "Ignoring invalid region start");
35 return;
38 // Remove the default region if there are user defined regions.
39 if (!CurrentRegion.startLoc().isValid())
40 Regions.erase(Regions.begin());
41 addRegion(Description, Loc);
44 void CodeRegions::endRegion(SMLoc Loc) {
45 assert(!Regions.empty() && "Missing Default region");
46 CodeRegion &CurrentRegion = *Regions.back();
47 if (CurrentRegion.endLoc().isValid()) {
48 SM.PrintMessage(Loc, SourceMgr::DK_Warning, "Ignoring invalid region end");
49 return;
52 CurrentRegion.setEndLocation(Loc);
55 void CodeRegions::addInstruction(std::unique_ptr<const MCInst> Instruction) {
56 const SMLoc &Loc = Instruction->getLoc();
57 const auto It =
58 std::find_if(Regions.rbegin(), Regions.rend(),
59 [Loc](const std::unique_ptr<CodeRegion> &Region) {
60 return Region->isLocInRange(Loc);
61 });
62 if (It != Regions.rend())
63 (*It)->addInstruction(std::move(Instruction));
66 } // namespace mca