[polly] r213779 - [Refactor] Unify IslAst print methods
Johannes Doerfert
jdoerfert at codeaurora.org
Wed Jul 23 11:14:43 PDT 2014
Author: jdoerfert
Date: Wed Jul 23 13:14:43 2014
New Revision: 213779
URL: http://llvm.org/viewvc/llvm-project?rev=213779&view=rev
Log:
[Refactor] Unify IslAst print methods
+ Add const annotations to some member functions
Modified:
polly/trunk/include/polly/CodeGen/IslAst.h
polly/trunk/lib/CodeGen/IslAst.cpp
polly/trunk/test/Isl/CodeGen/single_loop_zero_iterations.ll
Modified: polly/trunk/include/polly/CodeGen/IslAst.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/CodeGen/IslAst.h?rev=213779&r1=213778&r2=213779&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/IslAst.h (original)
+++ polly/trunk/include/polly/CodeGen/IslAst.h Wed Jul 23 13:14:43 2014
@@ -59,12 +59,16 @@ class IslAstInfo : public ScopPass {
public:
static char ID;
- IslAstInfo() : ScopPass(ID), Ast(NULL) {}
+ IslAstInfo() : ScopPass(ID), S(nullptr), Ast(nullptr) {}
- /// Print a source code representation of the program.
- void pprint(llvm::raw_ostream &OS);
+ /// @brief Build the AST for the given SCoP @p S.
+ bool runOnScop(Scop &S);
+
+ /// @brief Print a source code representation of the program.
+ void printScop(llvm::raw_ostream &OS) const;
- isl_ast_node *getAst();
+ /// @brief Return a copy of the AST root node.
+ __isl_give isl_ast_node *getAst() const;
/// @brief Get the run conditon.
///
@@ -72,10 +76,7 @@ public:
/// assumptions that have been taken hold. If the run condition evaluates to
/// zero/false some assumptions do not hold and the original code needs to
/// be executed.
- __isl_give isl_ast_expr *getRunCondition();
-
- bool runOnScop(Scop &S);
- void printScop(llvm::raw_ostream &OS) const;
+ __isl_give isl_ast_expr *getRunCondition() const;
/// @name Extract information attached to an isl ast (for) node.
///
Modified: polly/trunk/lib/CodeGen/IslAst.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslAst.cpp?rev=213779&r1=213778&r2=213779&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslAst.cpp (original)
+++ polly/trunk/lib/CodeGen/IslAst.cpp Wed Jul 23 13:14:43 2014
@@ -392,14 +392,6 @@ IslAst::IslAst(Scop *Scop, Dependences &
isl_union_map *Schedule =
isl_union_map_intersect_domain(S->getSchedule(), S->getDomains());
- Function *F = Scop->getRegion().getEntry()->getParent();
- (void)F;
-
- DEBUG(dbgs() << ":: isl ast :: " << F->getName()
- << " :: " << Scop->getRegion().getNameStr() << "\n");
-
- DEBUG(dbgs() << S->getContextStr() << "\n"; isl_union_map_dump(Schedule));
-
if (DetectParallel || PollyVectorizerChoice != VECTORIZER_NONE) {
BuildInfo.Deps = &D;
BuildInfo.InParallelFor = 0;
@@ -415,8 +407,6 @@ IslAst::IslAst(Scop *Scop, Dependences &
Root = isl_ast_build_ast_from_schedule(Context, Schedule);
isl_ast_build_free(Context);
-
- DEBUG(pprint(dbgs()));
}
IslAst::~IslAst() {
@@ -424,41 +414,11 @@ IslAst::~IslAst() {
isl_ast_expr_free(RunCondition);
}
-/// Print a C like representation of the program.
-void IslAst::pprint(llvm::raw_ostream &OS) {
- isl_ast_node *Root;
- isl_ast_print_options *Options;
-
- Options = isl_ast_print_options_alloc(S->getIslCtx());
- Options = isl_ast_print_options_set_print_for(Options, &printFor, nullptr);
-
- isl_printer *P = isl_printer_to_str(S->getIslCtx());
- P = isl_printer_set_output_format(P, ISL_FORMAT_C);
-
- P = isl_printer_print_ast_expr(P, RunCondition);
- char *result = isl_printer_get_str(P);
- P = isl_printer_flush(P);
-
- OS << "\nif (" << result << ")\n\n";
- P = isl_printer_indent(P, 4);
-
- Root = getAst();
- P = isl_ast_node_print(Root, P, Options);
- result = isl_printer_get_str(P);
- OS << result << "\n";
- OS << "else\n";
- OS << " { /* original code */ }\n\n";
- isl_printer_free(P);
- isl_ast_node_free(Root);
-}
-
__isl_give isl_ast_node *IslAst::getAst() { return isl_ast_node_copy(Root); }
__isl_give isl_ast_expr *IslAst::getRunCondition() {
return isl_ast_expr_copy(RunCondition);
}
-void IslAstInfo::pprint(llvm::raw_ostream &OS) { Ast->pprint(OS); }
-
void IslAstInfo::releaseMemory() {
if (Ast) {
delete Ast;
@@ -476,22 +436,15 @@ bool IslAstInfo::runOnScop(Scop &Scop) {
Ast = new IslAst(&Scop, D);
+ DEBUG(printScop(dbgs()));
return false;
}
-__isl_give isl_ast_node *IslAstInfo::getAst() { return Ast->getAst(); }
-__isl_give isl_ast_expr *IslAstInfo::getRunCondition() {
+__isl_give isl_ast_node *IslAstInfo::getAst() const { return Ast->getAst(); }
+__isl_give isl_ast_expr *IslAstInfo::getRunCondition() const {
return Ast->getRunCondition();
}
-void IslAstInfo::printScop(raw_ostream &OS) const {
- Function *F = S->getRegion().getEntry()->getParent();
-
- OS << F->getName() << "():\n";
-
- Ast->pprint(OS);
-}
-
IslAstUserPayload *IslAstInfo::getNodePayload(__isl_keep isl_ast_node *Node) {
isl_id *Id = isl_ast_node_get_annotation(Node);
if (!Id)
@@ -523,6 +476,43 @@ bool IslAstInfo::isReductionParallel(__i
return Payload && Payload->IsReductionParallel;
}
+void IslAstInfo::printScop(raw_ostream &OS) const {
+ isl_ast_print_options *Options;
+ isl_ast_node *RootNode = getAst();
+ isl_ast_expr *RunCondition = getRunCondition();
+ char *RtCStr, *AstStr;
+
+ Scop &S = getCurScop();
+ Options = isl_ast_print_options_alloc(S.getIslCtx());
+ Options = isl_ast_print_options_set_print_for(Options, printFor, nullptr);
+
+ isl_printer *P = isl_printer_to_str(S.getIslCtx());
+ P = isl_printer_print_ast_expr(P, RunCondition);
+ RtCStr = isl_printer_get_str(P);
+ P = isl_printer_flush(P);
+ P = isl_printer_indent(P, 4);
+ P = isl_printer_set_output_format(P, ISL_FORMAT_C);
+ P = isl_ast_node_print(RootNode, P, Options);
+ AstStr = isl_printer_get_str(P);
+
+ Function *F = S.getRegion().getEntry()->getParent();
+ isl_union_map *Schedule =
+ isl_union_map_intersect_domain(S.getSchedule(), S.getDomains());
+
+ OS << ":: isl ast :: " << F->getName() << " :: " << S.getRegion().getNameStr()
+ << "\n";
+ DEBUG(dbgs() << S.getContextStr() << "\n"; isl_union_map_dump(Schedule));
+ OS << "\nif (" << RtCStr << ")\n\n";
+ OS << AstStr << "\n";
+ OS << "else\n";
+ OS << " { /* original code */ }\n\n";
+
+ isl_ast_expr_free(RunCondition);
+ isl_union_map_free(Schedule);
+ isl_ast_node_free(RootNode);
+ isl_printer_free(P);
+}
+
void IslAstInfo::getAnalysisUsage(AnalysisUsage &AU) const {
// Get the Common analysis usage of ScopPasses.
ScopPass::getAnalysisUsage(AU);
Modified: polly/trunk/test/Isl/CodeGen/single_loop_zero_iterations.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/single_loop_zero_iterations.ll?rev=213779&r1=213778&r2=213779&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/single_loop_zero_iterations.ll (original)
+++ polly/trunk/test/Isl/CodeGen/single_loop_zero_iterations.ll Wed Jul 23 13:14:43 2014
@@ -66,5 +66,4 @@ return:
}
; CHECK: for region: 'for.cond => for.end.region' in function 'main':
-; CHECK-NEXT: main():
; CHECK-NOT: Stmt_for_body(0);
More information about the llvm-commits
mailing list