Difference: SloMudFlap ( vs. 1)

Revision 12008-06-06 - IanChristopher

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="SLODoc"

tree-mudflap.c

Overview

  • tree-mudflap.c is the most sigificantly modified file in gcc-slo. It is part of the second pass of gcc-slo.
  • It cogs with librd by creating external method calls. These calls include function entries, exits, psuedo basic block based access analysis, and access counters.
  • First, it builds a gimple tree of psudeo basic blocks. Next, it inserts new basic blocks to the end of the programs nodes which control the connection to librd.
  • Additionally, it creates the .memaccess_info, .bb_info, and .functon_info files.
  • There seems to be a lot of dead code in this file.

Code Documentation

-- Note: Some methods are not documented because they are either part of the original gcc or are simple enough. Also, some of this is taken directly from the code.

  • void construct_instrumentation_at_end_of_bb (tree tmp_check_var, basic_block* cond_bb, basic_block* incr_bb, basic_block* call_bb, basic_block current_bb)
    • This is probably the most important method in the file for SLO. It builds the the instructions of what to do after each basic block of code. First, it creates call_bb and incr_bb. Next, cond_bb is created to decide where control flow should be directed to after the basic block is finished. Finally, call_bb and incr_bb are connected to cond_bb which in turn is connected to the current basic block.
      • cond_bb decides where execution moves next - either call_bb or incr_bb.
      • call_bb creates a call to __process_recorded_memaccesses_in_basicblock (sampled_reuses.cpp in librd), which analyzes the accesses.
      • incr_bb just keeps track of the number of accesses, but does not actually analyze anything.
    • FROM CODE:
    • In basic block cond_bb:
    • _Bool need_to_insert_address = __nr_accesses_since_last_traced <= nr_memrefs;
    • _Bool tmp_need_recheck = tmp_check = 0;
    • _Bool call_condition = tmp_need_recheck | need_to_insert_address
    • if (call_condition) goto call_bb;
    • FALL_THRU to incr_bb; *
    • In basic block call_bb:
    • call __process_recorded_memaccesses_in_basicblock (int nr_refs, void** accesstrace, int* ref_nrs,
    • const char* sourcefilename); *
    • In basic block incr_bb:
    • current_timestamp += nr_memrefs;
    • need_to_insert_address -= nr_memrefs;
    • Still need to add
    • jump instructions at end of call_bb and incr_bb.

  • void output_memaccess_info_about_basicblock_and_instrument_pseudo_bbs (int function_nr, int* min_pseudo_bb_nr, int* max_pseudo_bb_nr)
    • creates .memaccess_info and .bb_info files for SLO

  • void instrument_basicblock (void)
    • creates .functon_info files,

  • void instrument_basicblock_init (void)
    • builds some other function calls to the external librd methods (instrument_memaccess_init builds the others)

  • void instrument_memaccess_init (void)
    • builds most of the new program tree, including large amounts of external librd method calls

  • int next_bb_nr (pseudo_bb_iterator current_pseudo_bb, int current_nr)
    • find and return the next BB number

  • pseudo_bb_iterator get_start_of_next_pseudo_bb (const pseudo_bb_iterator current_pseudo_bb)
    • return an iterator which moves over pBB

  • void advance_pseudo_bb_through_next_memaccess (pseudo_bb_iterator* pbi, int* ref_nr, block_stmt_iterator* instrumentation_code)
    • Advance_pseudo_bb_through_next_memaccess advances pbi to point to just beyond the next memory access in the current pseudo-bb. If there are no more memory references in the current pseudo-basic block, ref_nr is set to -1, and pseudo_bb_end_p (pbi) becomes true.

  • int get_memref_nr_of_instruction (tree s)
    • returns the memory reference of the instruction being instrumented

  • tree construct_replacement_for_orig_memaccess_instr (tree orig_instr, tree tmp_check_var, int nr_of_ref_in_bb)-
    • Replace the code *__ADDRESS_TRACE[refnr] = addr;
    • with
    • __ADDRESS_TRACE[offset] = addr;
    • unsigned char tmp_check; // at start of basic block.
    • voidp_addr = (void*) addr;
    • ul_addr = (unsigned long) voidp_addr;
    • addr_index = ul_addr & im_hash_array_size_mask_cst;
    • tmp_check = HASH_ARRAY[addr_index]; // for first memory reference in basic block
    • tmp_check |= HASH_ARRAY[addr_index]; // for subsequent references in basic block

  • void writeout_memory_accesses_to_info_file (pseudo_bb_iterator current_pseudo_bb, int pseudo_bb_nr)
    • .memaccess_info file, the number of memory references are written to memrefs_in_current_bb, and nr_memrefs_in_current_bb are set, so that the appropriate code can be inserted at the end of the pseudo-bb by the function calling writeout_memory_accesses_to_info_file.

  • void advance_pseudo_bb_through_next_memaccess (pseudo_bb_iterator* pbi, int* ref_nr, block_stmt_iterator* instrumentation_code)
    • advance_pseudo_bb_through_next_memaccess advances pbi to point to just beyond the next memory access in the current pseudo-bb. If there are no more memory references in the current pseudo-basic block, ref_nr is set to -1, and pseudo_bb_end_p (pbi) becomes true

  • int is_function_call_pseudo_bb (pseudo_bb_iterator pbi)
    • is_function_call_pseudo_bb returns true if pbi points to a pseudo-bb that contains only a function call. Otherwise, it contains no function calls and false is returned.

  • int check_if_fresh_pbi_is_function_call_pbi (block_stmt_iterator i)
    • check_if_fresh_pbi_is_function_call_pbi returns true if the statement pointed to by i is a function call that start a new pseudo-bb.

  • int function_is_pseudo_bb_border (tree function_decl)
    • function_is_pseudo_bb_border returns true if this function needs to be a basic block of its own (i.e. starts a new pseudo-bb). The only functions that do not start pseudo-bbs are the ones that are inserted by the instrumentation process earlier. */

  • tree check_no_function_calls_inside (tree* tp, int *walk_subtrees, void *data)
    • check_no_function_calls_inside will assertion fail when there are function call nodes in the tree that is walked.

  • tree build_instrument_memaccess_for (tree addr, tree ref_nr /*, tree size, const char* filename, int linenr, int colnr*/)
    • build_instrument_memaccess_for creates the instrumentation code for a memory access.
    • The generated code is similar to the code below.
    • __ADDRESS_TRACE[refnr] = addr;
    • This marks the memory access.
    • During basic block instrumentation, this is translated to:
    • __ADDRESS_TRACE[offset] = addr;
    • unsigned char tmp_check; // at start of basic block.
    • voidp_addr = (void*) addr;
    • ul_addr = (unsigned long) voidp_addr;
    • addr_index = ul_addr & im_hash_array_size_mask_cst;
    • tmp_check = HASH_ARRAY[addr_index]; // for first memory reference in basic block
    • tmp_check |= HASH_ARRAY[addr_index]; // for subsequent references in basic block

-- IanChristopher - 06 Jun 2008

 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding URCS? Send feedback