Skip to content

Commit

Permalink
Compiler plugin: added handling of MEM_REF tree offset.
Browse files Browse the repository at this point in the history
MEM_REF trees have both base and offset subtrees.
Only the base expression was used, thus read/write
were not inserted for the right locations in the
case where the offset was not 0.
  • Loading branch information
guillon committed Feb 25, 2013
1 parent 80d70f0 commit bf4d177
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions Compiler/ReadWriteCalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,11 @@ void get_offset_and_base(tree expr, tree *offset, tree *base){

get_offset_and_base(ref_base, offset, base);

}
else if( TREE_CODE(ref_base) == MEM_REF ){
/*Base Case! We have a base value here!*/
*base = get_base(ref_base);
*offset = TREE_OPERAND(ref_base, 1);
}else{

/*Base Case! We have a base value here!*/
Expand Down Expand Up @@ -564,7 +569,7 @@ void get_offset_and_base(tree expr, tree *offset, tree *base){
void insert_rd_comp_ref(tree expr, gimple stmt, basic_block bb, gimple_stmt_iterator *gsi){

tree offset = NULL;
tree base = NULL;
tree base = NULL;

get_offset_and_base(expr, &offset, &base);

Expand All @@ -583,7 +588,7 @@ void insert_rd_comp_ref(tree expr, gimple stmt, basic_block bb, gimple_stmt_iter
void insert_rd_arr_ref(tree expr, gimple stmt, basic_block bb, gimple_stmt_iterator *gsi){

tree offset = NULL;
tree base = NULL;
tree base = NULL;

tree ref_base = TREE_OPERAND(expr,0);
if( TREE_CODE(ref_base) == STRING_CST ){ return; }
Expand All @@ -604,14 +609,15 @@ void insert_rd_arr_ref(tree expr, gimple stmt, basic_block bb, gimple_stmt_itera
/*Handle a read in an MEM_REF tree*/
void insert_rd_mem_ref(tree expr, gimple stmt, basic_block bb, gimple_stmt_iterator *gsi){

/*expr is a MEM_REF*/
tree ptr = TREE_OPERAND(expr,0);
tree base = TREE_OPERAND(expr, 0);
tree offset = TREE_OPERAND(expr, 1);

/*ptr is an SSA_NAME*/
if( can_escape( ptr ) ){
tree final_addr = fold_build_pointer_plus(base, offset);

if( can_escape( base ) ){

bool hoisted = false;
insert_rd(ptr,bb,gsi,&hoisted);
insert_rd(final_addr,bb,gsi,&hoisted);

}

Expand Down Expand Up @@ -639,7 +645,7 @@ void insert_wr_comp_ref(tree expr, gimple stmt, basic_block bb, gimple_stmt_iter
void insert_wr_arr_ref(tree expr, gimple stmt, basic_block bb, gimple_stmt_iterator *gsi){

tree offset = NULL;
tree base = NULL;
tree base = NULL;

tree ref_base = TREE_OPERAND(expr,0);
if( TREE_CODE(ref_base) == STRING_CST ){ return; }
Expand All @@ -659,13 +665,14 @@ void insert_wr_arr_ref(tree expr, gimple stmt, basic_block bb, gimple_stmt_itera
/*Handle a write in an MEM_REF tree*/
void insert_wr_mem_ref(tree expr, gimple stmt, basic_block bb, gimple_stmt_iterator *gsi){

/*expr is a MEM_REF*/
tree ptr = TREE_OPERAND(expr,0);
tree base = TREE_OPERAND(expr, 0);
tree offset = TREE_OPERAND(expr, 1);

/*ptr is an SSA_NAME*/
if( can_escape( ptr ) ){
tree final_addr = fold_build_pointer_plus(base, offset);

if( can_escape( base ) ){

insert_wr(ptr,bb,gsi);
insert_wr(final_addr,bb,gsi);

}

Expand Down

0 comments on commit bf4d177

Please sign in to comment.