pet 0.11.6
[pet.git] / inliner.h
blob68440bdc37dd7c5839627956988f9716f6239daf
1 #ifndef PET_INLINER_H
2 #define PET_INLINER_H
4 #include <string>
5 #include <utility>
6 #include <vector>
8 #include <clang/AST/ASTContext.h>
9 #include <clang/AST/Type.h>
11 #include <isl/id.h>
13 #include "expr.h"
14 #include "substituter.h"
16 /* A helper class for inlining a pet_tree of the body of a called function.
17 * It keeps track of the substitutions that need to be performed on
18 * the inlined tree, along with the assignments that need to performed
19 * before the inlined tree.
21 * In particular, for a scalar argument declared "n" in the callee
22 * and passed the expression "e" by the caller, an assignment
24 * n' = e;
26 * is added before the inlined tree and n is replaced by n' in the inlined
27 * tree. n' may have the same name as n, but it may also be different if
28 * n also appears in the caller.
29 * For an array argument declared "a" in the callee and passed
30 * the expression "X[i1,...,in]" by the caller, assignments
32 * __pet_arg_1 = i1;
33 * ...
34 * __pet_arg_n = in;
36 * are added before the inlined tree and "a" is replaced by
37 * X[__pet_arg_1,...,__pet_arg_n] in the inlined tree.
39 * The assignments are stored in "assignments".
40 * The substitutions are stored in the superclass.
42 struct pet_inliner : pet_substituter {
43 isl_ctx *ctx;
44 std::vector<std::pair<pet_expr *, pet_expr *> > assignments;
45 int &n_arg;
46 clang::ASTContext &ast_context;
48 pet_inliner(isl_ctx *ctx, int &n_arg, clang::ASTContext &ast_context) :
49 ctx(ctx), n_arg(n_arg), ast_context(ast_context) {}
51 __isl_give pet_expr *assign( __isl_take isl_id *id,
52 __isl_take pet_expr *expr);
54 void add_scalar_arg(clang::ValueDecl *decl, const std::string &name,
55 __isl_take pet_expr *expr);
56 void add_array_arg(clang::ValueDecl *decl, __isl_take pet_expr *expr,
57 int is_add);
59 __isl_give pet_tree *inline_tree(__isl_take pet_tree *tree,
60 __isl_keep isl_id *return_id);
62 ~pet_inliner();
65 #endif