From e55cde29278536214b3470f80da9a6b017bf0cdf Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Sun, 8 Jan 2012 18:30:42 +0100 Subject: [PATCH] pass value_bounds to PetScan We will use these value_bounds in the next commit. Signed-off-by: Sven Verdoolaege --- pet.cc | 28 +++++++++++++++++++--------- scan.cc | 2 ++ scan.h | 15 +++++++++++---- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/pet.cc b/pet.cc index 04c2ddb..4ba8076 100644 --- a/pet.cc +++ b/pet.cc @@ -388,11 +388,22 @@ struct PetASTConsumer : public ASTConsumer { bool autodetect; isl_ctx *ctx; struct pet_scop *scop; + PragmaValueBoundsHandler *vb_handler; PetASTConsumer(isl_ctx *ctx, Preprocessor &PP, ASTContext &ast_context, ScopLoc &loc, const char *function, bool autodetect) : ctx(ctx), PP(PP), ast_context(ast_context), loc(loc), - scop(NULL), function(function), autodetect(autodetect) { } + scop(NULL), function(function), autodetect(autodetect), + vb_handler(NULL) { } + + void handle_value_bounds(Sema *sema) { + vb_handler = new PragmaValueBoundsHandler(ctx, *sema); + PP.AddPragmaHandler(vb_handler); + } + + __isl_give isl_union_map *get_value_bounds() { + return isl_union_map_copy(vb_handler->value_bounds); + } virtual HandleTopLevelDeclReturn HandleTopLevelDecl(DeclGroupRef dg) { DeclGroupRef::iterator it; @@ -400,6 +411,7 @@ struct PetASTConsumer : public ASTConsumer { if (scop) return HandleTopLevelDeclContinue; for (it = dg.begin(); it != dg.end(); ++it) { + isl_union_map *vb = vb_handler->value_bounds; FunctionDecl *fd = dyn_cast(*it); if (!fd) continue; @@ -409,7 +421,8 @@ struct PetASTConsumer : public ASTConsumer { fd->getNameInfo().getAsString() != function) continue; if (autodetect) { - PetScan ps(ctx, PP, ast_context, loc, 1); + PetScan ps(PP, ast_context, loc, 1, + isl_union_map_copy(vb)); scop = ps.scan(fd); if (scop) break; @@ -423,7 +436,8 @@ struct PetASTConsumer : public ASTConsumer { continue; if (SM.getFileOffset(fd->getLocEnd()) < loc.start) continue; - PetScan ps(ctx, PP, ast_context, loc, 0); + PetScan ps(PP, ast_context, loc, 0, + isl_union_map_copy(vb)); scop = ps.scan(fd); break; } @@ -600,7 +614,6 @@ static struct pet_scop *scop_extract_from_C_source(isl_ctx *ctx, isl_set *context_value; pet_scop *scop; set live_out; - PragmaValueBoundsHandler *vb_handler; isl_union_map *value_bounds; CompilerInstance *Clang = new CompilerInstance(); @@ -657,8 +670,7 @@ static struct pet_scop *scop_extract_from_C_source(isl_ctx *ctx, context_value = isl_set_universe(dim); PP.AddPragmaHandler(new PragmaParameterHandler(*sema, context, context_value)); - vb_handler = new PragmaValueBoundsHandler(ctx, *sema); - PP.AddPragmaHandler(vb_handler); + consumer.handle_value_bounds(sema); Diags.getClient()->BeginSourceFile(Clang->getLangOpts(), &PP); ParseAST(*sema); @@ -681,13 +693,11 @@ static struct pet_scop *scop_extract_from_C_source(isl_ctx *ctx, scop = pet_scop_anonymize(scop); - value_bounds = isl_union_map_copy(vb_handler->value_bounds); + update_arrays(scop, consumer.get_value_bounds(), live_out); delete sema; delete Clang; - update_arrays(scop, value_bounds, live_out); - return scop; } diff --git a/scan.cc b/scan.cc index 0a2a1e1..d35380a 100644 --- a/scan.cc +++ b/scan.cc @@ -248,6 +248,8 @@ PetScan::~PetScan() for (it = expressions.begin(); it != expressions.end(); ++it) isl_pw_aff_free(*it); + + isl_union_map_free(value_bounds); } /* Called if we found something we (currently) cannot handle. diff --git a/scan.h b/scan.h index 6fdb50d..db30e54 100644 --- a/scan.h +++ b/scan.h @@ -62,10 +62,17 @@ struct PetScan { */ std::set expressions; - PetScan(isl_ctx *ctx, clang::Preprocessor &PP, - clang::ASTContext &ast_context, ScopLoc &loc, int autodetect) : - ctx(ctx), PP(PP), ast_context(ast_context), loc(loc), - autodetect(autodetect), + /* A union of mappings of the form + * { identifier[] -> [i] : lower_bound <= i <= upper_bound } + */ + isl_union_map *value_bounds; + + PetScan(clang::Preprocessor &PP, + clang::ASTContext &ast_context, ScopLoc &loc, int autodetect, + __isl_take isl_union_map *value_bounds) : + ctx(isl_union_map_get_ctx(value_bounds)), PP(PP), + ast_context(ast_context), loc(loc), + autodetect(autodetect), value_bounds(value_bounds), n_stmt(0), n_test(0), partial(0), allow_nested(true), nesting_enabled(false) { } -- 2.11.4.GIT