1132718Skan/* Definitions for the branch prediction routines in the GNU compiler. 2169689Skan Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc. 390075Sobrien 490075SobrienThis file is part of GCC. 590075Sobrien 690075SobrienGCC is free software; you can redistribute it and/or modify it under 790075Sobrienthe terms of the GNU General Public License as published by the Free 890075SobrienSoftware Foundation; either version 2, or (at your option) any later 990075Sobrienversion. 1090075Sobrien 1190075SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY 1290075SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or 1390075SobrienFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1490075Sobrienfor more details. 1590075Sobrien 1690075SobrienYou should have received a copy of the GNU General Public License 1790075Sobrienalong with GCC; see the file COPYING. If not, write to the Free 18169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 19169689Skan02110-1301, USA. */ 2090075Sobrien 2190075Sobrien/* Before including this file, you should define a macro: 2290075Sobrien 2390075Sobrien DEF_PREDICTOR (ENUM, NAME, HITRATE) 2490075Sobrien 2590075Sobrien This macro will be called once for each predictor. The ENUM will 2690075Sobrien be of type `enum predictor', and will enumerate all supported 2790075Sobrien predictors. The order of DEF_PREDICTOR calls is important, as 2890075Sobrien in the first match combining heuristics, the predictor appearing 2990075Sobrien first in this file will win. 3090075Sobrien 3190075Sobrien NAME is used in the debugging output to determine predictor type. 3290075Sobrien 3390075Sobrien HITRATE is the probability that edge predicted by predictor as taken 3490075Sobrien will be really taken (so it should be always above 3590075Sobrien REG_BR_PROB_BASE / 2). */ 3690075Sobrien 3790075Sobrien 3890075Sobrien/* A value used as final outcome of all heuristics. */ 3990075SobrienDEF_PREDICTOR (PRED_COMBINED, "combined", PROB_ALWAYS, 0) 4090075Sobrien 4190075Sobrien/* An outcome estimated by Dempster-Shaffer theory. */ 4290075SobrienDEF_PREDICTOR (PRED_DS_THEORY, "DS theory", PROB_ALWAYS, 0) 4390075Sobrien 44169689Skan/* A combined heuristics using probability determined by first 4590075Sobrien matching heuristics from this list. */ 4690075SobrienDEF_PREDICTOR (PRED_FIRST_MATCH, "first match", PROB_ALWAYS, 0) 4790075Sobrien 4890075Sobrien/* Heuristic applying when no heuristic below applies. */ 4990075SobrienDEF_PREDICTOR (PRED_NO_PREDICTION, "no prediction", PROB_ALWAYS, 0) 5090075Sobrien 5190075Sobrien/* Mark unconditional jump as taken. */ 5290075SobrienDEF_PREDICTOR (PRED_UNCONDITIONAL, "unconditional jump", PROB_ALWAYS, 5390075Sobrien PRED_FLAG_FIRST_MATCH) 5490075Sobrien 5590075Sobrien/* Use number of loop iterations determined by loop unroller to set 5690075Sobrien probability. We don't want to use Dempster-Shaffer theory here, 5790075Sobrien as the predictions is exact. */ 5890075SobrienDEF_PREDICTOR (PRED_LOOP_ITERATIONS, "loop iterations", PROB_ALWAYS, 5990075Sobrien PRED_FLAG_FIRST_MATCH) 6090075Sobrien 6190075Sobrien/* Hints dropped by user via __builtin_expect feature. */ 6290075SobrienDEF_PREDICTOR (PRED_BUILTIN_EXPECT, "__builtin_expect", PROB_VERY_LIKELY, 6390075Sobrien PRED_FLAG_FIRST_MATCH) 6490075Sobrien 65117395Skan/* Branch containing goto is probably not taken. */ 66117395SkanDEF_PREDICTOR (PRED_CONTINUE, "continue", HITRATE (56), 0) 67117395Skan 6890075Sobrien/* Branch to basic block containing call marked by noreturn attribute. */ 6990075SobrienDEF_PREDICTOR (PRED_NORETURN, "noreturn call", HITRATE (99), 7090075Sobrien PRED_FLAG_FIRST_MATCH) 7190075Sobrien 7290075Sobrien/* Loopback edge is taken. */ 7390075SobrienDEF_PREDICTOR (PRED_LOOP_BRANCH, "loop branch", HITRATE (89), 7490075Sobrien PRED_FLAG_FIRST_MATCH) 7590075Sobrien 76117395Skan/* Edge causing loop to terminate is probably not taken. */ 7790075SobrienDEF_PREDICTOR (PRED_LOOP_EXIT, "loop exit", HITRATE (90), 7890075Sobrien PRED_FLAG_FIRST_MATCH) 7990075Sobrien 8090075Sobrien/* Condition emitted by preconditiong code to ensure that variable 8190075Sobrien setting number of iterations is greater than initial value of iterator. */ 8290075SobrienDEF_PREDICTOR (PRED_LOOP_CONDITION, "loop condition", PROB_VERY_LIKELY, 0) 8390075Sobrien 8490075Sobrien/* Preconditioning makes linear list of branches. */ 8590075SobrienDEF_PREDICTOR (PRED_LOOP_PRECONDITIONING, "loop preconditioning", PROB_VERY_LIKELY, 0) 8690075Sobrien 8790075Sobrien/* Copied condition for the first iteration of loop is probably true. */ 8890075SobrienDEF_PREDICTOR (PRED_LOOP_HEADER, "loop header", HITRATE (64), 0) 8990075Sobrien 9090075Sobrien/* Pointers are usually not NULL. */ 9190075SobrienDEF_PREDICTOR (PRED_POINTER, "pointer", HITRATE (81), 0) 92169689SkanDEF_PREDICTOR (PRED_TREE_POINTER, "pointer (on trees)", HITRATE (81), 0) 9390075Sobrien 9490075Sobrien/* NE is probable, EQ not etc... */ 9590075SobrienDEF_PREDICTOR (PRED_OPCODE_POSITIVE, "opcode values positive", HITRATE (79), 0) 9690075SobrienDEF_PREDICTOR (PRED_OPCODE_NONEQUAL, "opcode values nonequal", HITRATE (71), 0) 9790075SobrienDEF_PREDICTOR (PRED_FPOPCODE, "fp_opcode", HITRATE (90), 0) 98169689SkanDEF_PREDICTOR (PRED_TREE_OPCODE_POSITIVE, "opcode values positive (on trees)", HITRATE (79), 0) 99169689SkanDEF_PREDICTOR (PRED_TREE_OPCODE_NONEQUAL, "opcode values nonequal (on trees)", HITRATE (71), 0) 100169689SkanDEF_PREDICTOR (PRED_TREE_FPOPCODE, "fp_opcode (on trees)", HITRATE (90), 0) 10190075Sobrien 10290075Sobrien/* Branch guarding call is probably taken. */ 10390075SobrienDEF_PREDICTOR (PRED_CALL, "call", HITRATE (70), 0) 10490075Sobrien 10590075Sobrien/* Branch causing function to terminate is probably not taken. */ 106117395SkanDEF_PREDICTOR (PRED_EARLY_RETURN, "early return", HITRATE (67), 0) 107169689SkanDEF_PREDICTOR (PRED_TREE_EARLY_RETURN, "early return (on trees)", HITRATE (67), 0) 108117395Skan 109117395Skan/* Branch containing goto is probably not taken. */ 110117395SkanDEF_PREDICTOR (PRED_GOTO, "goto", HITRATE (70), 0) 111117395Skan 112117395Skan/* Branch ending with return constant is probably not taken. */ 113117395SkanDEF_PREDICTOR (PRED_CONST_RETURN, "const return", HITRATE (95), 0) 114117395Skan 115117395Skan/* Branch ending with return negative constant is probably not taken. */ 116117395SkanDEF_PREDICTOR (PRED_NEGATIVE_RETURN, "negative return", HITRATE (96), 0) 117117395Skan 118117395Skan/* Branch ending with return; is probably not taken */ 119117395SkanDEF_PREDICTOR (PRED_NULL_RETURN, "null return", HITRATE (90), 0) 120169689Skan 121169689Skan/* Branches to a mudflap bounds check are extremely unlikely. */ 122169689SkanDEF_PREDICTOR (PRED_MUDFLAP, "mudflap check", HITRATE (99), 0) 123