aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-profile.c
diff options
context:
space:
mode:
authorBernd Schmidt <bernd.schmidt@analog.com>2006-01-11 17:40:46 +0000
committerBernd Schmidt <bernd.schmidt@analog.com>2006-01-11 17:40:46 +0000
commit337db89251de80f8ff7a00b2d71bc333c630b6e4 (patch)
treed3188ec1672ccdf9f1225cc766a1dc386c4f0d32 /gcc/tree-profile.c
parentefb5461014d0abdd5751d82ad1b4d0c61685dbdd (diff)
Merged revisions 96681,96683-96686,96689-96692,96698-96701,96705,96708,96710,96712,96714-96715,96719-96720,96725,96730,96733,96735-96737,96739-96740,96743,96745,96748,96753,96755,96759-96762,96764-96765,96768,96770-96771,96774,96776-96778,96782,96784-96785,96788,96790,96795-96803,96808,96812-96814,96816-96832,96834,96836-96837,96844,96847,96849-96853,96855,96862,96867,96870,96872,96879-96881,96883-96884,96889,96891-96895,96899,96902-96905,96908,96911,96913,96915-96917,96919-96921,96923-96924,96926-96927,96931-96935,96937-96939,96941,96944,96947-96948,96951,96953-96954,96957-96958,96960,96963,96966-96968,96980-96985,96988-96990,96995-96996,96998,97000,97003-97005,97013-97016,97018-97019,97024,97026,97028-97029,97031-97034,97036,97038-97039,97041,97044,97046-97048,97050,97054,97057-97063,97065,97070,97074,97076-97077,97079,97081-97086,97089,97091,97109,97111-97116,97120,97122-97123,97125-97130,97132-97136,97139,97143,97146-97148,97150-97153,97156-97157,97160-97161,97164-97192,97194-97197,97199-97200,97202,97204,97207-97212,97217,97220-97223,97229,97233,97236-97243,97249-97253,97255,97258,97263-97264,97267,97270,97273,97276-97278,97281-97285,97287,97289-97290,97292,97295,97298-97299,97301,97303,97308,97312-97314,97317-97319,97321-97322,97325-97326,97330-97334,97336-97344,97347-97349,97351-97352,97358,97360-97364,97367,97369-97370,97372-97373,97376-97381,97383,97385-97397,97399-97400,97402-97403,97406,97409,97411-97412,97414,97416-97417,97422,97424,97428-97430,97434-97438,97440-97441,97444,97446,97449,97452-97453,97455-97458,97461,97470,97472-97473,97475-97476,97478-97479,97481,97484-97486,97489-97493,97495-97496,97498,97511,97522,97525-97527,97529,97532-97533,97536-97538,97540-97551,97554-97555,97557-97558,97560-97561,97565,97567,97569-97572,97574-97578,97580-97582,97587,97589,97593-97599,97601-97602,97604-97605,97607,97609,97611,97613,97617,97620,97622,97624,97627,97631,97633,97635-97636,97640-97641,97643-97646,97648,97650,97652-97656,97659-97663,97666,97668,97671,97673-97674,97676-97678,97681,97685-97686,97691,97694,97696,97699-97702,97705,97708-97713,97719,97722-97723,97726,97728,97730-97731,97733,97737-97740,97742,97746-97747,97749,97751,97756,97759-97760,97763,97765,97770,97772-97773,97775,97778-97779,97781-97782,97784,97787-97788,97790,97792-97793,97795-97797,97804-97805,97807-97810,97813,97815-97819,97822,97825-97828,97830,97832,97836-97842,97846,97849,97851,97854,97857,97860-97862,97866,97868-97873,97880,97884-97887,97890,97894-97895,97897,97902-97908,97910-97912,97916,97919-97924,97928-97932,97935,97937-97941,97943-97951,97955,97958,97961,97964-97966,97968,97971-97974,97976-97983,97986-97988,97991,97994,97999-98001,98003,98009-98010,98012,98017-98023,98026-98029,98031-98032,98034,98039-98040,98044,98047-98048,98051-98053,98058,98061-98068,98070-98073,98076-98080,98082-98095,98097,98099,98101-98107,98110-98111,98118,98121,98127-98128,98131-98137,98140-98144,98146,98148-98149,98152,98154-98156,98159,98161-98162,98165-98168,98173-98174,98179,98183-98184,98186-98187,98189-98193,98195-98196,98199-98200,98202-98203,98206,98208-98210,98213,98216,98218,98220-98223,98225,98227,98232-98234,98236-98239,98242,98244-98245,98247,98252,98257-98260,98262,98265-98266,98269,98271,98273,98278,98283,98285-98288,98295,98297,98303,98307,98309-98313,98315-98316,98318-98321,98323-98324,98326-98335,98338-98343,98345-98350,98352,98355,98357,98362,98365-98379,98381,98384-98400,98402-98403,98405-98408,98412-98414,98416-98421,98425,98428-98430,98432-98451,98453,98456-98458,98460-98462,98464,98466,98468-98469,98471-98473,98476,98478,98482,98486,98493-98504,98507-98508,98510-98511,98513-98519,98522-98523,98527-98528,98530,98534,98540,98542-98544,98548-98551,98555,98559-98562,98567,98569-98570,98573-98574,98578-98583,98585-98587,98589,98594,98596-98603,98605-98607,98610-98611,98613-98622,98624,98631-98637,98640,98643-98644,98649-98650,98654,98658-98660,98663-98665,98668-98669,98673-98674,98676,98678-98679,98681,98684-98686,98691,98693-98695,98699,98708,98711-98712,98714-98715,98717,98723-98724,98726,98728,98730-98735,98737-98738,98740,98744-98746,98749,98752-98753,98755-98756,98762-98771,98774-98776,98778-98780,98782-98783,98785-98786,98788-98789,98791-98793,98795-98798,98800,98805,98808,98813-98814,98816-98818,98828-98829,98831-98832,98835-98837,98840,98843-98845,98848,98850-98854,98861-98862,98866-98868,98871-98875,98877-98886,98890,98893,98896,98898,98900-98901,98906-98908,98910-98916,98919,98922,98924,98928-98929,98932,98934-98936,98938-98942,98944,98947,98949-98950,98952,98955,98958,98961-98962,98966,98968,98975-98981,98983-98989,98991-98994,98998-99000,99006,99008,99010-99013,99016,99018-99021,99028,99032-99033,99035,99037-99038,99041,99043,99046-99047,99052,99054,99059,99064,99067-99068,99071-99072,99076,99080,99082-99083,99085-99086,99089,99091,99093-99096,99099-99100,99103-99105,99109,99111,99113-99115,99118,99121-99123,99125-99126,99131,99133,99135,99144,99152,99155-99158,99160-99164,99167-99175,99177,99179-99180,99182-99183,99185-99188,99196-99197,99200,99203-99211,99216-99225,99227,99230,99232,99234-99236,99238,99244,99247,99250-99257,99261-99262,99264-99265,99268-99269,99272-99275,99277,99279,99281-99282,99284,99287-99291,99296,99300-99306,99309,99314-99317,99319,99322,99324-99326,99329-99332,99334,99336-99337,99341,99343-99352,99355-99360,99362-99363,99365-99366,99370,99373,99375-99384,99386,99388,99391,99393-99395,99398-99399,99405-99408,99410-99411,99413,99415,99419,99421-99422,99424-99425,99429,99431-99433,99435,99441-99444,99446-99464,99466-99467,99470-99478,99483,99485,99487,99492-99493,99495-99499,99503,99505-99506,99508-99510,99513-99514,99516-99521,99523-99529,99535-99541,99544-99548,99553,99556,99558-99560,99563,99566,99568-99570,99573-99574,99577-99586,99588,99591-99592,99596-99597,99602,99604-99610,99613,99615,99617,99619,99621,99623,99625-99627,99631-99633,99635-99637,99640,99642-99643,99646-99648,99650,99652,99654-99660,99662-99664,99666,99668-99670,99672-99676,99679-99680,99684,99687,99691-99705,99708,99710-99711,99714-99716,99719-99724,99726,99728-99729,99731-99733,99735-99742,99745-99750,99755,99757,99759-99760,99765,99767,99769,99773-99775,99777-99779,99782-99783,99785,99787,99789,99791-99792,99794,99796,99799-99801,99803,99806,99810-99817,99823-99835,99837-99840,99842-99844,99846-99862,99871,99877-99882,99884-99885,99889-99890,99892-99893,99896-99897,99899-99901,99903-99904,99906,99908,99910,99916,99919-99920,99922-99928,99930,99933,99935-99936,99939,99941-99946,99948-99953,99957,99960,99966-99967,99971-99972,99974,99976-99978,99981-99982,99984,99986,99988,99993,99996-99997,99999 via svnmerge from
svn+ssh://gcc.gnu.org/svn/gcc/trunk git-svn-id: https://gcc.gnu.org/svn/gcc/branches/reload-branch@109594 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-profile.c')
-rw-r--r--gcc/tree-profile.c188
1 files changed, 131 insertions, 57 deletions
diff --git a/gcc/tree-profile.c b/gcc/tree-profile.c
index 145c7213158..2c91fc3859f 100644
--- a/gcc/tree-profile.c
+++ b/gcc/tree-profile.c
@@ -1,6 +1,6 @@
/* Calculate branch probabilities, and basic block execution counts.
Copyright (C) 1990, 1991, 1992, 1993, 1994, 1996, 1997, 1998, 1999,
- 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+ 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
Contributed by James E. Wilson, UC Berkeley/Cygnus Support;
based on some ideas from Dain Samples of UC Berkeley.
Further mangling by Bob Manson, Cygnus Support.
@@ -24,30 +24,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/* Generate basic block profile instrumentation and auxiliary files.
- Profile generation is optimized, so that not all arcs in the basic
- block graph need instrumenting. First, the BB graph is closed with
- one entry (function start), and one exit (function exit). Any
- ABNORMAL_EDGE cannot be instrumented (because there is no control
- path to place the code). We close the graph by inserting fake
- EDGE_FAKE edges to the EXIT_BLOCK, from the sources of abnormal
- edges that do not go to the exit_block. We ignore such abnormal
- edges. Naturally these fake edges are never directly traversed,
- and so *cannot* be directly instrumented. Some other graph
- massaging is done. To optimize the instrumentation we generate the
- BB minimal span tree, only edges that are not on the span tree
- (plus the entry point) need instrumenting. From that information
- all other edge counts can be deduced. By construction all fake
- edges must be on the spanning tree. We also attempt to place
- EDGE_CRITICAL edges on the spanning tree.
-
- The auxiliary file generated is <dumpbase>.bbg. The format is
- described in full in gcov-io.h. */
-
-/* ??? Register allocation should use basic block execution counts to
- give preference to the most commonly executed blocks. */
-
-/* ??? Should calculate branch probabilities before instrumenting code, since
- then we can use arc counts to help decide which arcs to instrument. */
+ Tree-based version. See profile.c for overview. */
#include "config.h"
#include "system.h"
@@ -67,7 +44,12 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#include "tree-pass.h"
#include "timevar.h"
#include "value-prof.h"
+#include "ggc.h"
+static GTY(()) tree gcov_type_node;
+static GTY(()) tree tree_interval_profiler_fn;
+static GTY(()) tree tree_pow2_profiler_fn;
+static GTY(()) tree tree_one_value_profiler_fn;
/* Do initialization work for the edge profiler. */
@@ -75,6 +57,43 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
static void
tree_init_edge_profiler (void)
{
+ tree interval_profiler_fn_type;
+ tree pow2_profiler_fn_type;
+ tree one_value_profiler_fn_type;
+ tree gcov_type_ptr;
+
+ if (!gcov_type_node)
+ {
+ gcov_type_node = get_gcov_type ();
+ gcov_type_ptr = build_pointer_type (gcov_type_node);
+
+ /* void (*) (gcov_type *, gcov_type, int, unsigned) */
+ interval_profiler_fn_type
+ = build_function_type_list (void_type_node,
+ gcov_type_ptr, gcov_type_node,
+ integer_type_node,
+ unsigned_type_node, NULL_TREE);
+ tree_interval_profiler_fn
+ = build_fn_decl ("__gcov_interval_profiler",
+ interval_profiler_fn_type);
+
+ /* void (*) (gcov_type *, gcov_type) */
+ pow2_profiler_fn_type
+ = build_function_type_list (void_type_node,
+ gcov_type_ptr, gcov_type_node,
+ NULL_TREE);
+ tree_pow2_profiler_fn = build_fn_decl ("__gcov_pow2_profiler",
+ pow2_profiler_fn_type);
+
+ /* void (*) (gcov_type *, gcov_type) */
+ one_value_profiler_fn_type
+ = build_function_type_list (void_type_node,
+ gcov_type_ptr, gcov_type_node,
+ NULL_TREE);
+ tree_one_value_profiler_fn
+ = build_fn_decl ("__gcov_one_value_profiler",
+ one_value_profiler_fn_type);
+ }
}
/* Output instructions as GIMPLE trees to increment the edge
@@ -84,33 +103,56 @@ tree_init_edge_profiler (void)
static void
tree_gen_edge_profiler (int edgeno, edge e)
{
- tree tmp1 = create_tmp_var (GCOV_TYPE_NODE, "PROF");
- tree tmp2 = create_tmp_var (GCOV_TYPE_NODE, "PROF");
+ tree tmp1 = create_tmp_var (gcov_type_node, "PROF");
+ tree tmp2 = create_tmp_var (gcov_type_node, "PROF");
tree ref = tree_coverage_counter_ref (GCOV_COUNTER_ARCS, edgeno);
- tree stmt1 = build (MODIFY_EXPR, GCOV_TYPE_NODE, tmp1, ref);
- tree stmt2 = build (MODIFY_EXPR, GCOV_TYPE_NODE, tmp2,
- build (PLUS_EXPR, GCOV_TYPE_NODE,
+ tree stmt1 = build (MODIFY_EXPR, gcov_type_node, tmp1, ref);
+ tree stmt2 = build (MODIFY_EXPR, gcov_type_node, tmp2,
+ build (PLUS_EXPR, gcov_type_node,
tmp1, integer_one_node));
- tree stmt3 = build (MODIFY_EXPR, GCOV_TYPE_NODE, ref, tmp2);
+ tree stmt3 = build (MODIFY_EXPR, gcov_type_node, ref, tmp2);
bsi_insert_on_edge (e, stmt1);
bsi_insert_on_edge (e, stmt2);
bsi_insert_on_edge (e, stmt3);
}
+/* Emits code to get VALUE to instrument at BSI, and returns the
+ variable containing the value. */
+
+static tree
+prepare_instrumented_value (block_stmt_iterator *bsi,
+ histogram_value value)
+{
+ tree val = value->hvalue.tree.value;
+ return force_gimple_operand_bsi (bsi, fold_convert (gcov_type_node, val),
+ true, NULL_TREE);
+}
+
/* Output instructions as GIMPLE trees to increment the interval histogram
counter. VALUE is the expression whose value is profiled. TAG is the
tag of the section for counters, BASE is offset of the counter position. */
static void
-tree_gen_interval_profiler (histogram_value value ATTRIBUTE_UNUSED,
- unsigned tag ATTRIBUTE_UNUSED,
- unsigned base ATTRIBUTE_UNUSED)
+tree_gen_interval_profiler (histogram_value value, unsigned tag, unsigned base)
{
- /* FIXME implement this. */
-#ifdef ENABLE_CHECKING
- internal_error ("unimplemented functionality");
-#endif
- gcc_unreachable ();
+ tree stmt = value->hvalue.tree.stmt;
+ block_stmt_iterator bsi = bsi_for_stmt (stmt);
+ tree ref = tree_coverage_counter_ref (tag, base), ref_ptr;
+ tree args, call, val;
+ tree start = build_int_cst_type (integer_type_node, value->hdata.intvl.int_start);
+ tree steps = build_int_cst_type (unsigned_type_node, value->hdata.intvl.steps);
+
+ ref_ptr = force_gimple_operand_bsi (&bsi,
+ build_addr (ref),
+ true, NULL_TREE);
+ val = prepare_instrumented_value (&bsi, value);
+ args = tree_cons (NULL_TREE, ref_ptr,
+ tree_cons (NULL_TREE, val,
+ tree_cons (NULL_TREE, start,
+ tree_cons (NULL_TREE, steps,
+ NULL_TREE))));
+ call = build_function_call_expr (tree_interval_profiler_fn, args);
+ bsi_insert_before (&bsi, call, BSI_SAME_STMT);
}
/* Output instructions as GIMPLE trees to increment the power of two histogram
@@ -118,15 +160,22 @@ tree_gen_interval_profiler (histogram_value value ATTRIBUTE_UNUSED,
of the section for counters, BASE is offset of the counter position. */
static void
-tree_gen_pow2_profiler (histogram_value value ATTRIBUTE_UNUSED,
- unsigned tag ATTRIBUTE_UNUSED,
- unsigned base ATTRIBUTE_UNUSED)
+tree_gen_pow2_profiler (histogram_value value, unsigned tag, unsigned base)
{
- /* FIXME implement this. */
-#ifdef ENABLE_CHECKING
- internal_error ("unimplemented functionality");
-#endif
- gcc_unreachable ();
+ tree stmt = value->hvalue.tree.stmt;
+ block_stmt_iterator bsi = bsi_for_stmt (stmt);
+ tree ref = tree_coverage_counter_ref (tag, base), ref_ptr;
+ tree args, call, val;
+
+ ref_ptr = force_gimple_operand_bsi (&bsi,
+ build_addr (ref),
+ true, NULL_TREE);
+ val = prepare_instrumented_value (&bsi, value);
+ args = tree_cons (NULL_TREE, ref_ptr,
+ tree_cons (NULL_TREE, val,
+ NULL_TREE));
+ call = build_function_call_expr (tree_pow2_profiler_fn, args);
+ bsi_insert_before (&bsi, call, BSI_SAME_STMT);
}
/* Output instructions as GIMPLE trees for code to find the most common value.
@@ -134,15 +183,22 @@ tree_gen_pow2_profiler (histogram_value value ATTRIBUTE_UNUSED,
section for counters, BASE is offset of the counter position. */
static void
-tree_gen_one_value_profiler (histogram_value value ATTRIBUTE_UNUSED,
- unsigned tag ATTRIBUTE_UNUSED,
- unsigned base ATTRIBUTE_UNUSED)
+tree_gen_one_value_profiler (histogram_value value, unsigned tag, unsigned base)
{
- /* FIXME implement this. */
-#ifdef ENABLE_CHECKING
- internal_error ("unimplemented functionality");
-#endif
- gcc_unreachable ();
+ tree stmt = value->hvalue.tree.stmt;
+ block_stmt_iterator bsi = bsi_for_stmt (stmt);
+ tree ref = tree_coverage_counter_ref (tag, base), ref_ptr;
+ tree args, call, val;
+
+ ref_ptr = force_gimple_operand_bsi (&bsi,
+ build_addr (ref),
+ true, NULL_TREE);
+ val = prepare_instrumented_value (&bsi, value);
+ args = tree_cons (NULL_TREE, ref_ptr,
+ tree_cons (NULL_TREE, val,
+ NULL_TREE));
+ call = build_function_call_expr (tree_one_value_profiler_fn, args);
+ bsi_insert_before (&bsi, call, BSI_SAME_STMT);
}
/* Output instructions as GIMPLE trees for code to find the most common value
@@ -166,7 +222,8 @@ tree_gen_const_delta_profiler (histogram_value value ATTRIBUTE_UNUSED,
If it is, set up hooks for tree-based profiling.
Gate for pass_tree_profile. */
-static bool do_tree_profiling (void)
+static bool
+do_tree_profiling (void)
{
if (flag_tree_based_profiling
&& (profile_arc_flag || flag_test_coverage || flag_branch_probabilities))
@@ -184,11 +241,26 @@ static FILE *tree_profile_dump_file (void) {
return dump_file;
}
+static void
+tree_profiling (void)
+{
+ branch_prob ();
+ if (flag_branch_probabilities
+ && flag_profile_values
+ && flag_value_profile_transformations)
+ value_profile_transformations ();
+ /* The above could hose dominator info. Currently there is
+ none coming in, this is a safety valve. It should be
+ easy to adjust it, if and when there is some. */
+ free_dominance_info (CDI_DOMINATORS);
+ free_dominance_info (CDI_POST_DOMINATORS);
+}
+
struct tree_opt_pass pass_tree_profile =
{
"tree_profile", /* name */
do_tree_profiling, /* gate */
- branch_prob, /* execute */
+ tree_profiling, /* execute */
NULL, /* sub */
NULL, /* next */
0, /* static_pass_number */
@@ -211,3 +283,5 @@ struct profile_hooks tree_profile_hooks =
tree_gen_const_delta_profiler,/* gen_const_delta_profiler */
tree_profile_dump_file /* profile_dump_file */
};
+
+#include "gt-tree-profile.h"