PetScan::extract_index_expr: extract out pet_id_create_index_expr
[pet.git] / id.cc
blob90f5b7f5e3d4e9a84b4c25aff80faa6625d98184
1 /*
2 * Copyright 2011 Leiden University. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following
13 * disclaimer in the documentation and/or other materials provided
14 * with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY LEIDEN UNIVERSITY ''AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LEIDEN UNIVERSITY OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * The views and conclusions contained in the software and documentation
29 * are those of the authors and should not be interpreted as
30 * representing official policies, either expressed or implied, of
31 * Leiden University.
34 #include "id.h"
36 using namespace clang;
38 /* Create an isl_id that refers to the variable declarator "decl".
40 __isl_give isl_id *pet_id_from_decl(isl_ctx *ctx, ValueDecl *decl)
42 return isl_id_alloc(ctx, decl->getName().str().c_str(), decl);
45 /* Create an isl_id that refers to the variable declarator "decl", but
46 * has name "name".
48 __isl_give isl_id *pet_id_from_name_and_decl(isl_ctx *ctx, const char *name,
49 ValueDecl *decl)
51 return isl_id_alloc(ctx, name, decl);
54 /* Extract the ValueDecl that was associated to "id"
55 * in pet_id_from_decl.
57 ValueDecl *pet_id_get_decl(__isl_keep isl_id *id)
59 return (ValueDecl *) isl_id_get_user(id);
62 /* Construct a pet_expr representing an index expression for an access
63 * to the variable represented by "id".
65 __isl_give pet_expr *pet_id_create_index_expr(__isl_take isl_id *id)
67 isl_space *space;
69 if (!id)
70 return NULL;
72 space = isl_space_alloc(isl_id_get_ctx(id), 0, 0, 0);
73 space = isl_space_set_tuple_id(space, isl_dim_out, id);
75 return pet_expr_from_index(isl_multi_pw_aff_zero(space));