HPCToolkit
x86-jump.c
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 /******************************************************************************
48  * includes
49  *****************************************************************************/
50 
51 #include <messages/messages.h>
52 
53 #include "x86-build-intervals.h"
54 #include "x86-decoder.h"
55 #include "x86-process-inst.h"
56 #include "x86-canonical.h"
57 #include "x86-jump.h"
59 #include "x86-unwind-analysis.h"
60 #include "x86-interval-arg.h"
61 
62 
63 /******************************************************************************
64  * interface operations
65  *****************************************************************************/
66 
68 process_unconditional_branch(xed_decoded_inst_t *xptr, bool irdebug,
69  interval_arg_t *iarg)
70 {
71  unwind_interval *next = iarg->current;
72 
73  if ((iarg->highwatermark).state == HW_UNINITIALIZED) {
74  (iarg->highwatermark).uwi = iarg->current;
75  (iarg->highwatermark).state = HW_INITIALIZED;
76  }
77 
78  reset_to_canonical_interval(xptr, &next, irdebug, iarg);
79 
80  TMSG(TAIL_CALL,"checking for tail call via unconditional branch @ %p",iarg->ins);
81  void *possible = x86_get_branch_target(iarg->ins, xptr);
82  if (possible == NULL) {
83  TMSG(TAIL_CALL,"indirect unconditional branch ==> possible tail call");
84  UWI_RECIPE(next)->has_tail_calls = true;
85  }
86  else if ((possible >= iarg->end) || ((uintptr_t)possible < UWI_START_ADDR(iarg->first))) {
87  TMSG(TAIL_CALL,"unconditional branch to address %p outside of current routine (%p to %p)",
88  possible, UWI_START_ADDR(iarg->first), iarg->end);
89  UWI_RECIPE(next)->has_tail_calls = true;
90  }
91 
92  return next;
93 }
94 
95 
97 process_conditional_branch(xed_decoded_inst_t *xptr,
98  interval_arg_t *iarg)
99 {
100  highwatermark_t *hw_tmp = &(iarg->highwatermark);
101  if (hw_tmp->state == HW_UNINITIALIZED) {
102  hw_tmp->uwi = iarg->current;
103  hw_tmp->state = HW_INITIALIZED;
104  }
105 
106  TMSG(TAIL_CALL,"checking for tail call via unconditional branch @ %p",iarg->ins);
107  void *possible = x86_get_branch_target(iarg->ins, xptr);
108  if (possible == NULL) {
109  TMSG(TAIL_CALL,"indirect unconditional branch ==> possible tail call");
110  UWI_RECIPE(iarg->current)->has_tail_calls = true;
111  }
112  else if ((possible > iarg->end) || ((uintptr_t)possible < UWI_START_ADDR(iarg->first))) {
113  TMSG(TAIL_CALL,"unconditional branch to address %p outside of current routine (%p to %p)",
114  possible, UWI_START_ADDR(iarg->first), iarg->end);
115  UWI_RECIPE(iarg->current)->has_tail_calls = true;
116  }
117 
118  return iarg->current;
119 }
bitree_uwi_t * first
#define HW_INITIALIZED
Definition: x86-canonical.c:54
void reset_to_canonical_interval(xed_decoded_inst_t *xptr, unwind_interval **next, bool irdebug, interval_arg_t *iarg)
Definition: x86-canonical.c:76
bitree_uwi_t * current
unwind_interval * process_conditional_branch(xed_decoded_inst_t *xptr, interval_arg_t *iarg)
Definition: x86-jump.c:97
#define UWI_RECIPE(btuwi)
void * x86_get_branch_target(void *ins, xed_decoded_inst_t *xptr)
highwatermark_t highwatermark
#define TMSG(f,...)
Definition: messages.h:93
#define HW_UNINITIALIZED
Definition: x86-canonical.c:58
unwind_interval * process_unconditional_branch(xed_decoded_inst_t *xptr, bool irdebug, interval_arg_t *iarg)
Definition: x86-jump.c:68
#define UWI_START_ADDR(btuwi)
#define NULL
Definition: ElfHelper.cpp:85
bitree_uwi_t unwind_interval