From 9d0da09f045bb9163224074dd2222bdca2f3bf03 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 9 Mar 2017 10:06:08 +0100 Subject: [PATCH] extract out (nearly) shared pet_expr_access_from_id Both PetScan and pet_inliner need to create an access expression from an isl_id. Although the implementations are not identical, they are very similar. Replace the two implementations by a single shared implementation. Signed-off-by: Sven Verdoolaege --- expr_plus.cc | 14 ++++++++++++++ expr_plus.h | 4 ++++ inliner.cc | 6 ++---- scan.cc | 4 +--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/expr_plus.cc b/expr_plus.cc index 2cc1f3e..284404c 100644 --- a/expr_plus.cc +++ b/expr_plus.cc @@ -119,3 +119,17 @@ __isl_give pet_expr *pet_expr_access_from_index(QualType qt, return index; } + +/* Construct an access pet_expr for an access + * to the variable represented by "id". + */ +__isl_give pet_expr *pet_expr_access_from_id(__isl_take isl_id *id, + ASTContext &ast_context) +{ + QualType qt; + pet_expr *expr; + + qt = pet_id_get_array_type(id); + expr = pet_id_create_index_expr(id); + return pet_expr_access_from_index(qt, expr, ast_context); +} diff --git a/expr_plus.h b/expr_plus.h index cdabf08..2945684 100644 --- a/expr_plus.h +++ b/expr_plus.h @@ -4,9 +4,13 @@ #include #include +#include + #include __isl_give pet_expr *pet_expr_access_from_index(clang::QualType qt, __isl_take pet_expr *index, clang::ASTContext &ast_context); +__isl_give pet_expr *pet_expr_access_from_id(__isl_take isl_id *id, + clang::ASTContext &ast_context); #endif diff --git a/inliner.cc b/inliner.cc index 6ae651c..2344abc 100644 --- a/inliner.cc +++ b/inliner.cc @@ -34,6 +34,7 @@ #include "clang.h" #include "expr.h" +#include "expr_plus.h" #include "id.h" #include "inliner.h" @@ -46,12 +47,9 @@ using namespace clang; __isl_give pet_expr *pet_inliner::assign( __isl_take isl_id *id, QualType qt, __isl_take pet_expr *expr) { - int type_size; pet_expr *var; - var = pet_id_create_index_expr(id); - type_size = pet_clang_get_type_size(qt, ast_context); - var = pet_expr_set_type_size(var, type_size); + var = pet_expr_access_from_id(id, ast_context); assignments.push_back(pair(var, expr)); diff --git a/scan.cc b/scan.cc index 920003b..695921a 100644 --- a/scan.cc +++ b/scan.cc @@ -1547,9 +1547,7 @@ __isl_give pet_tree *PetScan::extract(CompoundStmt *stmt, name = generate_new_name(name); id = pet_id_from_name_and_decl(ctx, name.c_str(), decl); - expr = pet_id_create_index_expr(id); - expr = pet_expr_access_from_index(decl->getType(), expr, - ast_context); + expr = pet_expr_access_from_id(id, ast_context); id = pet_id_from_decl(ctx, decl); substituter.add_sub(id, expr); used_names.insert(name); -- 2.11.4.GIT