diff options
| author | Michael Kruse <llvm@meinersbur.de> | 2018-04-25 19:43:49 +0000 |
|---|---|---|
| committer | Michael Kruse <llvm@meinersbur.de> | 2018-04-25 19:43:49 +0000 |
| commit | e819fffee3b948c7699ce3948b35624bf6cc63ae (patch) | |
| tree | 79845af0f5f0e535085dac7244a7010bfa29813a /polly/lib/CodeGen/BlockGenerators.cpp | |
| parent | 152060275fd43196bc34648d1a264e6478555860 (diff) | |
| download | bcm5719-llvm-e819fffee3b948c7699ce3948b35624bf6cc63ae.tar.gz bcm5719-llvm-e819fffee3b948c7699ce3948b35624bf6cc63ae.zip | |
[CodeGen] Print executed statement instances at runtime.
Add the options -polly-codegen-trace-stmts and
-polly-codegen-trace-scalars. When enabled, adds a call to the
beginning of every generated statement that prints the executed
statement instance. With -polly-codegen-trace-scalars, it also prints
the value of all scalars that are used in the statement, and PHIs
defined in the beginning of the statement.
Differential Revision: https://reviews.llvm.org/D45743
llvm-svn: 330864
Diffstat (limited to 'polly/lib/CodeGen/BlockGenerators.cpp')
| -rw-r--r-- | polly/lib/CodeGen/BlockGenerators.cpp | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp index 9bff9d2a1b9..a42c639e442 100644 --- a/polly/lib/CodeGen/BlockGenerators.cpp +++ b/polly/lib/CodeGen/BlockGenerators.cpp @@ -51,6 +51,17 @@ static cl::opt<bool, true> DebugPrintingX( cl::location(PollyDebugPrinting), cl::Hidden, cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory)); +static cl::opt<bool> TraceStmts( + "polly-codegen-trace-stmts", + cl::desc("Add printf calls that print the statement being executed"), + cl::Hidden, cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory)); + +static cl::opt<bool> TraceScalars( + "polly-codegen-trace-scalars", + cl::desc("Add printf calls that print the values of all scalar values " + "used in a statement. Requires -polly-codegen-trace-stmts."), + cl::Hidden, cl::init(false), cl::ZeroOrMore, cl::cat(PollyCategory)); + BlockGenerator::BlockGenerator( PollyIRBuilder &B, LoopInfo &LI, ScalarEvolution &SE, DominatorTree &DT, AllocaMapTy &ScalarMap, EscapeUsersAllocaMapTy &EscapeMap, @@ -436,6 +447,7 @@ BasicBlock *BlockGenerator::copyBB(ScopStmt &Stmt, BasicBlock *BB, BasicBlock *CopyBB = splitBB(BB); Builder.SetInsertPoint(&CopyBB->front()); generateScalarLoads(Stmt, LTS, BBMap, NewAccesses); + generateBeginStmtTrace(Stmt, LTS, BBMap); copyBB(Stmt, BB, CopyBB, BBMap, LTS, NewAccesses); @@ -647,6 +659,108 @@ void BlockGenerator::generateConditionalExecution( Builder.SetInsertPoint(TailBlock, TailBlock->getFirstInsertionPt()); } +static std::string getInstName(Value *Val) { + std::string Result; + raw_string_ostream OS(Result); + Val->printAsOperand(OS, false); + return OS.str(); +} + +void BlockGenerator::generateBeginStmtTrace(ScopStmt &Stmt, LoopToScevMapT <S, + ValueMapT &BBMap) { + if (!TraceStmts) + return; + + Scop *S = Stmt.getParent(); + const char *BaseName = Stmt.getBaseName(); + + isl::ast_build AstBuild = Stmt.getAstBuild(); + isl::set Domain = Stmt.getDomain(); + + isl::union_map USchedule = AstBuild.get_schedule().intersect_domain(Domain); + isl::map Schedule = isl::map::from_union_map(USchedule); + assert(Schedule.is_empty().is_false() && + "The stmt must have a valid instance"); + + isl::multi_pw_aff ScheduleMultiPwAff = + isl::pw_multi_aff::from_map(Schedule.reverse()); + isl::ast_build RestrictedBuild = AstBuild.restrict(Schedule.range()); + + // Sequence of strings to print. + SmallVector<llvm::Value *, 8> Values; + + // Print the name of the statement. + // TODO: Indent by the depth of the statement instance in the schedule tree. + Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, BaseName)); + Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, "(")); + + // Add the coordinate of the statement instance. + int DomDims = ScheduleMultiPwAff.dim(isl::dim::out); + for (int i = 0; i < DomDims; i += 1) { + if (i > 0) + Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, ",")); + + isl::ast_expr IsInSet = + RestrictedBuild.expr_from(ScheduleMultiPwAff.get_pw_aff(i)); + Values.push_back(ExprBuilder->create(IsInSet.copy())); + } + + if (TraceScalars) { + Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, ")")); + DenseSet<Instruction *> Encountered; + + // Add the value of each scalar (and the result of PHIs) used in the + // statement. + // TODO: Values used in region-statements. + for (Instruction *Inst : Stmt.insts()) { + if (!RuntimeDebugBuilder::isPrintable(Inst->getType())) + continue; + + if (isa<PHINode>(Inst)) { + Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, " ")); + Values.push_back(RuntimeDebugBuilder::getPrintableString( + Builder, getInstName(Inst))); + Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, "=")); + Values.push_back(getNewValue(Stmt, Inst, BBMap, LTS, + LI.getLoopFor(Inst->getParent()))); + } else { + for (Value *Op : Inst->operand_values()) { + // Do not print values that cannot change during the execution of the + // SCoP. + auto *OpInst = dyn_cast<Instruction>(Op); + if (!OpInst) + continue; + if (!S->contains(OpInst)) + continue; + + // Print each scalar at most once, and exclude values defined in the + // statement itself. + if (Encountered.count(OpInst)) + continue; + + Values.push_back( + RuntimeDebugBuilder::getPrintableString(Builder, " ")); + Values.push_back(RuntimeDebugBuilder::getPrintableString( + Builder, getInstName(OpInst))); + Values.push_back( + RuntimeDebugBuilder::getPrintableString(Builder, "=")); + Values.push_back(getNewValue(Stmt, OpInst, BBMap, LTS, + LI.getLoopFor(Inst->getParent()))); + Encountered.insert(OpInst); + } + } + + Encountered.insert(Inst); + } + + Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, "\n")); + } else { + Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, ")\n")); + } + + RuntimeDebugBuilder::createCPUPrinter(Builder, ArrayRef<Value *>(Values)); +} + void BlockGenerator::generateScalarStores( ScopStmt &Stmt, LoopToScevMapT <S, ValueMapT &BBMap, __isl_keep isl_id_to_ast_expr *NewAccesses) { @@ -1375,6 +1489,7 @@ void RegionGenerator::copyStmt(ScopStmt &Stmt, LoopToScevMapT <S, ValueMapT &EntryBBMap = RegionMaps[EntryBBCopy]; generateScalarLoads(Stmt, LTS, EntryBBMap, IdToAstExp); + generateBeginStmtTrace(Stmt, LTS, EntryBBMap); for (auto PI = pred_begin(EntryBB), PE = pred_end(EntryBB); PI != PE; ++PI) if (!R->contains(*PI)) { |

