18#include "llvm/Support/CommandLine.h"
28static cl::opt<std::string, true>
30 cl::desc(
"Only view functions that match this pattern"),
31 cl::location(
ViewFilter), cl::Hidden, cl::init(
""));
33static cl::opt<bool, true>
35 cl::desc(
"Also show functions without any scops"),
36 cl::location(
ViewAll), cl::Hidden, cl::init(
false));
43 RegionNode *destNode = *CI;
45 if (srcNode->isSubRegion() || destNode->isSubRegion())
49 BasicBlock *srcBB = srcNode->getNodeAs<BasicBlock>();
50 BasicBlock *destBB = destNode->getNodeAs<BasicBlock>();
52 RegionInfo *RI = SD->
getRI();
53 Region *R = RI->getRegionFor(destBB);
55 while (R && R->getParent())
56 if (R->getParent()->getEntry() == destBB)
61 if (R && R->getEntry() == destBB && R->contains(srcBB))
62 return "constraint=false";
68DOTGraphTraits<ScopDetection *>::escapeString(llvm::StringRef String) {
71 for (
const auto &
C : String) {
80void DOTGraphTraits<ScopDetection *>::printRegionCluster(ScopDetection *SD,
84 O.indent(2 * depth) <<
"subgraph cluster_" <<
static_cast<const void *
>(R)
86 unsigned LineBegin, LineEnd;
92 if (LineBegin != (
unsigned)-1) {
93 Location = escapeString(FileName +
":" + std::to_string(LineBegin) +
"-" +
94 std::to_string(LineEnd) +
"\n");
98 ErrorMessage = escapeString(ErrorMessage);
99 O.indent(2 * (depth + 1))
100 <<
"label = \"" << Location << ErrorMessage <<
"\";\n";
103 O.indent(2 * (depth + 1)) <<
"style = filled;\n";
106 O.indent(2 * (depth + 1)) <<
"color = 3";
108 O.indent(2 * (depth + 1)) <<
"style = solid;\n";
110 int color = (R->getDepth() * 2 % 12) + 1;
116 O.indent(2 * (depth + 1)) <<
"color = " << color <<
"\n";
119 for (
const auto &SubRegion : *R)
120 printRegionCluster(SD, SubRegion.get(), O, depth + 1);
122 RegionInfo *RI = R->getRegionInfo();
124 for (BasicBlock *BB : R->blocks())
125 if (RI->getRegionFor(BB) == R)
126 O.indent(2 * (depth + 1))
128 <<
static_cast<void *
>(RI->getTopLevelRegion()->getBBNode(BB))
131 O.indent(2 * depth) <<
"}\n";
134void DOTGraphTraits<ScopDetection *>::addCustomGraphFeatures(
135 ScopDetection *SD, GraphWriter<ScopDetection *> &GW) {
136 raw_ostream &O = GW.getOStream();
137 O <<
"\tcolorscheme = \"paired12\"\n";
138 printRegionCluster(SD, SD->
getRI()->getTopLevelRegion(), O, 4);
151 return std::distance(SD.
begin(), SD.
end()) > 0;
static cl::opt< std::string, true > XViewFilter("polly-view-only", cl::desc("Only view functions that match this pattern"), cl::location(ViewFilter), cl::Hidden, cl::init(""))
static cl::opt< bool, true > XViewAll("polly-view-all", cl::desc("Also show functions without any scops"), cl::location(ViewAll), cl::Hidden, cl::init(false))
Pass to detect the maximal static control parts (Scops) of a function.
RegionInfo * getRI() const
Get the RegionInfo stored in this pass.
std::string regionIsInvalidBecause(const Region *R) const
Get a message why a region is invalid.
bool isMaxRegionInScop(const Region &R, bool Verify=true)
Is the region is the maximum region of a Scop?
void getDebugLocation(const llvm::Region *R, unsigned &LineBegin, unsigned &LineEnd, std::string &FileName)
Get the location of a region from the debug info.
bool processFunction(Function &F, const ScopDetection &SD) override