From cb771fc5146275f9bba7e446895f6e8b322fd3cd Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Thu, 18 Jan 2018 15:15:38 +0000 Subject: [PATCH] [ScopInfo] Pass name to ScopStmt ctor. NFC. This will give control of the statement's name to the caller. Required to give -polly-stmt-granularity=scalar-indep more control over the name of the generated statement in a follow-up commit. git-svn-id: https://llvm.org/svn/llvm-project/polly/trunk@322851 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/polly/ScopInfo.h | 15 ++++++++------- lib/Analysis/ScopBuilder.cpp | 35 +++++++++++++++++++++++++++++++---- lib/Analysis/ScopInfo.cpp | 35 ++++++++++++++--------------------- 3 files changed, 53 insertions(+), 32 deletions(-) diff --git a/include/polly/ScopInfo.h b/include/polly/ScopInfo.h index 248e5f90..dadaa300 100644 --- a/include/polly/ScopInfo.h +++ b/include/polly/ScopInfo.h @@ -1195,8 +1195,8 @@ class ScopStmt { public: /// Create the ScopStmt from a BasicBlock. - ScopStmt(Scop &parent, BasicBlock &bb, Loop *SurroundingLoop, - std::vector Instructions, int Count); + ScopStmt(Scop &parent, BasicBlock &bb, StringRef Name, Loop *SurroundingLoop, + std::vector Instructions); /// Create an overapproximating ScopStmt for the region @p R. /// @@ -1206,7 +1206,7 @@ public: /// blocks for now. We currently do not allow /// to modify the instructions of blocks later /// in the region statement. - ScopStmt(Scop &parent, Region &R, Loop *SurroundingLoop, + ScopStmt(Scop &parent, Region &R, StringRef Name, Loop *SurroundingLoop, std::vector EntryBlockInstructions); /// Create a copy statement. @@ -2197,11 +2197,11 @@ private: /// and map. /// /// @param BB The basic block we build the statement for. + /// @param Name The name of the new statement. /// @param SurroundingLoop The loop the created statement is contained in. /// @param Instructions The instructions in the statement. - /// @param Count The index of the created statement in @p BB. - void addScopStmt(BasicBlock *BB, Loop *SurroundingLoop, - std::vector Instructions, int Count); + void addScopStmt(BasicBlock *BB, StringRef Name, Loop *SurroundingLoop, + std::vector Instructions); /// Create a new SCoP statement for @p R. /// @@ -2209,11 +2209,12 @@ private: /// and map. /// /// @param R The region we build the statement for. + /// @param Name The name of the new statement. /// @param SurroundingLoop The loop the created statement is contained /// in. /// @param EntryBlockInstructions The (interesting) instructions in the /// entry block of the region statement. - void addScopStmt(Region *R, Loop *SurroundingLoop, + void addScopStmt(Region *R, StringRef Name, Loop *SurroundingLoop, std::vector EntryBlockInstructions); /// Update access dimensionalities. diff --git a/lib/Analysis/ScopBuilder.cpp b/lib/Analysis/ScopBuilder.cpp index 3c7f67be..3274aa2a 100644 --- a/lib/Analysis/ScopBuilder.cpp +++ b/lib/Analysis/ScopBuilder.cpp @@ -19,6 +19,7 @@ #include "polly/ScopDetection.h" #include "polly/ScopDetectionDiagnostic.h" #include "polly/ScopInfo.h" +#include "polly/Support/GICHelper.h" #include "polly/Support/SCEVValidator.h" #include "polly/Support/ScopHelper.h" #include "polly/Support/VirtualInstruction.h" @@ -688,6 +689,28 @@ bool ScopBuilder::shouldModelInst(Instruction *Inst, Loop *L) { !canSynthesize(Inst, *scop, &SE, L); } +/// Generate a name for a statement. +/// +/// @param S The parent SCoP. +/// @param BB The basic block the statement will represent. +/// @param Count The index of the created statement in @p BB. +static std::string makeStmtName(Scop *S, BasicBlock *BB, int Count) { + std::string Suffix = ""; + if (Count != 0) + Suffix += std::to_string(Count); + return getIslCompatibleName("Stmt", BB, S->getNextStmtIdx(), Suffix, + UseInstructionNames); +} + +/// Generate a name for a statement that represents a non-affine subregion. +/// +/// @param S The parent SCoP. +/// @param R The region the statement will represent. +static std::string makeStmtName(Scop *S, Region *R) { + return getIslCompatibleName("Stmt", R->getNameStr(), S->getNextStmtIdx(), "", + UseInstructionNames); +} + void ScopBuilder::buildSequentialBlockStmts(BasicBlock *BB, bool SplitOnStore) { Loop *SurroundingLoop = LI.getLoopFor(BB); @@ -698,13 +721,15 @@ void ScopBuilder::buildSequentialBlockStmts(BasicBlock *BB, bool SplitOnStore) { Instructions.push_back(&Inst); if (Inst.getMetadata("polly_split_after") || (SplitOnStore && isa(Inst))) { - scop->addScopStmt(BB, SurroundingLoop, Instructions, Count); + std::string Name = makeStmtName(scop.get(), BB, Count); + scop->addScopStmt(BB, Name, SurroundingLoop, Instructions); Count++; Instructions.clear(); } } - scop->addScopStmt(BB, SurroundingLoop, Instructions, Count); + std::string Name = makeStmtName(scop.get(), BB, Count); + scop->addScopStmt(BB, Name, SurroundingLoop, Instructions); } /// Is @p Inst an ordered instruction? @@ -874,7 +899,8 @@ void ScopBuilder::buildEqivClassBlockStmts(BasicBlock *BB) { for (auto &Instructions : reverse(LeaderToInstList)) { std::vector &InstList = Instructions.second; std::reverse(InstList.begin(), InstList.end()); - scop->addScopStmt(BB, L, std::move(InstList), Count); + std::string Name = makeStmtName(scop.get(), BB, Count); + scop->addScopStmt(BB, Name, L, std::move(InstList)); Count += 1; } } @@ -887,7 +913,8 @@ void ScopBuilder::buildStmts(Region &SR) { for (Instruction &Inst : *SR.getEntry()) if (shouldModelInst(&Inst, SurroundingLoop)) Instructions.push_back(&Inst); - scop->addScopStmt(&SR, SurroundingLoop, Instructions); + std::string Name = makeStmtName(scop.get(), &SR); + scop->addScopStmt(&SR, Name, SurroundingLoop, Instructions); return; } diff --git a/lib/Analysis/ScopInfo.cpp b/lib/Analysis/ScopInfo.cpp index 1ef900d5..9ecf301b 100644 --- a/lib/Analysis/ScopInfo.cpp +++ b/lib/Analysis/ScopInfo.cpp @@ -1695,26 +1695,19 @@ bool buildConditionSets(Scop &S, BasicBlock *BB, TerminatorInst *TI, Loop *L, ConditionSets); } -ScopStmt::ScopStmt(Scop &parent, Region &R, Loop *SurroundingLoop, +ScopStmt::ScopStmt(Scop &parent, Region &R, StringRef Name, + Loop *SurroundingLoop, std::vector EntryBlockInstructions) : Parent(parent), InvalidDomain(nullptr), Domain(nullptr), R(&R), - Build(nullptr), SurroundingLoop(SurroundingLoop), - Instructions(EntryBlockInstructions) { - BaseName = getIslCompatibleName( - "Stmt", R.getNameStr(), parent.getNextStmtIdx(), "", UseInstructionNames); -} + Build(nullptr), BaseName(Name), SurroundingLoop(SurroundingLoop), + Instructions(EntryBlockInstructions) {} -ScopStmt::ScopStmt(Scop &parent, BasicBlock &bb, Loop *SurroundingLoop, - std::vector Instructions, int Count) +ScopStmt::ScopStmt(Scop &parent, BasicBlock &bb, StringRef Name, + Loop *SurroundingLoop, + std::vector Instructions) : Parent(parent), InvalidDomain(nullptr), Domain(nullptr), BB(&bb), - Build(nullptr), SurroundingLoop(SurroundingLoop), - Instructions(Instructions) { - std::string S = ""; - if (Count != 0) - S += std::to_string(Count); - BaseName = getIslCompatibleName("Stmt", &bb, parent.getNextStmtIdx(), S, - UseInstructionNames); -} + Build(nullptr), BaseName(Name), SurroundingLoop(SurroundingLoop), + Instructions(Instructions) {} ScopStmt::ScopStmt(Scop &parent, isl::map SourceRel, isl::map TargetRel, isl::set NewDomain) @@ -4644,10 +4637,10 @@ static isl::multi_union_pw_aff mapToDimension(isl::union_set USet, int N) { return isl::multi_union_pw_aff(isl::union_pw_multi_aff(Result)); } -void Scop::addScopStmt(BasicBlock *BB, Loop *SurroundingLoop, - std::vector Instructions, int Count) { +void Scop::addScopStmt(BasicBlock *BB, StringRef Name, Loop *SurroundingLoop, + std::vector Instructions) { assert(BB && "Unexpected nullptr!"); - Stmts.emplace_back(*this, *BB, SurroundingLoop, Instructions, Count); + Stmts.emplace_back(*this, *BB, Name, SurroundingLoop, Instructions); auto *Stmt = &Stmts.back(); StmtMap[BB].push_back(Stmt); for (Instruction *Inst : Instructions) { @@ -4657,10 +4650,10 @@ void Scop::addScopStmt(BasicBlock *BB, Loop *SurroundingLoop, } } -void Scop::addScopStmt(Region *R, Loop *SurroundingLoop, +void Scop::addScopStmt(Region *R, StringRef Name, Loop *SurroundingLoop, std::vector Instructions) { assert(R && "Unexpected nullptr!"); - Stmts.emplace_back(*this, *R, SurroundingLoop, Instructions); + Stmts.emplace_back(*this, *R, Name, SurroundingLoop, Instructions); auto *Stmt = &Stmts.back(); for (Instruction *Inst : Instructions) { -- 2.11.4.GIT