2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief Instrumentation of graphs.
24 * @author Michael Beck
29 #include "irgraph_t.h"
33 #include "instrument.h"
36 * Adds a Call at the beginning of the given irg.
38 void instrument_initcall(ir_graph *irg, ir_entity *ent) {
39 const ir_edge_t *edge;
40 ir_node *initial_exec;
43 ir_node *adr, *call, *new_mem;
44 ir_node *first_block = NULL;
45 int i, idx, need_new_block;
50 /* find the first block */
51 initial_exec = get_irg_initial_exec(irg);
52 start_block = get_irg_start_block(irg);
54 foreach_out_edge(initial_exec, edge) {
55 ir_node *succ = get_edge_src_irn(edge);
57 if (succ != start_block && is_Block(succ)) {
58 /* found the first block */
63 if (first_block == NULL) {
64 panic("Cannot find first block of irg %+F", irg);
67 /* check if this block has only one predecessor */
70 for (i = get_Block_n_cfgpreds(first_block) - 1; i >= 0; --i) {
71 ir_node *p = get_Block_cfgpred(first_block, i);
75 if (p == initial_exec)
82 ir_node *blk = new_r_Block(irg, 1, &initial_exec);
83 set_Block_cfgpred(first_block, idx, new_r_Jmp(blk));
89 adr = new_r_SymConst(irg, mode_P_code, sym, symconst_addr_ent);
91 call = new_r_Call(first_block, get_irg_no_mem(irg), adr, 0, NULL, get_entity_type(ent));
92 new_mem = new_r_Proj(first_block, call, mode_M, pn_Call_M_regular);
94 initial_mem = get_irg_initial_mem(irg);
95 edges_reroute(initial_mem, new_mem, irg);
96 /* beware: reroute routes anchor edges also, revert this */
97 set_irg_initial_mem(irg, initial_mem);
98 set_Call_mem(call, initial_mem);