HPCToolkit
x86-lea.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 
48 #include "x86-decoder.h"
49 #include "x86-lea.h"
50 #include "x86-interval-arg.h"
51 
53 
55 process_lea(xed_decoded_inst_t *xptr, const xed_inst_t *xi, interval_arg_t *iarg)
56 {
57  highwatermark_t *hw_tmp = &(iarg->highwatermark);
58  unwind_interval *next = iarg->current;
59  const xed_operand_t *op0 = xed_inst_operand(xi, 0);
60  xed_operand_enum_t op0_name = xed_operand_name(op0);
61 
62  if ((op0_name == XED_OPERAND_REG0)) {
63  x86recipe_t *xr = UWI_RECIPE(next);
64  x86registers_t reg = xr->reg;
65  xed_reg_enum_t regname = xed_decoded_inst_get_reg(xptr, op0_name);
66  char *next_ins = nextInsn(iarg, xptr);
67  if (x86_isReg_BP(regname)) {
68  //=======================================================================
69  // action: clobbering the base pointer; begin a new SP_RELATIVE interval
70  // note: we don't check that BP is BP_SAVED; we might have to
71  //=======================================================================
72  reg.bp_status = BP_HOSED;
73  next = new_ui(next_ins, RA_SP_RELATIVE, &reg);
75  (UWI_RECIPE(hw_tmp->uwi)->reg.sp_ra_pos == xr->reg.sp_ra_pos)) {
76  hw_tmp->uwi = next;
77  hw_tmp->state = HW_NEW_STATE(hw_tmp->state, HW_BP_OVERWRITTEN);
78  }
79  } else if (x86_isReg_SP(regname)) {
80  if (xr->ra_status == RA_SP_RELATIVE || xr->ra_status == RA_STD_FRAME) {
81  unsigned int memops = xed_decoded_inst_number_of_memory_operands(xptr);
82  if (memops > 0) {
83  int mem_op_index = 0;
84 
85  xed_reg_enum_t basereg =
86  xed_decoded_inst_get_base_reg(xptr, mem_op_index);
87 
88  if (x86_isReg_SP(basereg)) {
89  //==================================================================
90  // the LEA instruction adjusts SP with a displacement.
91  // begin a new interval where sp_ra_pos is adjusted by the
92  // displacement.
93  //==================================================================
94  xed_int64_t disp =
95  xed_decoded_inst_get_memory_displacement(xptr, mem_op_index);
96  reg.sp_ra_pos -= disp;
97  reg.sp_bp_pos -= disp;
98  next = new_ui(next_ins, xr->ra_status, &reg);
99 
100  if (disp < 0) {
101  if (HW_TEST_STATE(hw_tmp->state, 0, HW_SP_DECREMENTED)) {
102  //--------------------------------------------------------------
103  // set the highwatermark and canonical interval upon seeing
104  // the FIRST subtract (using lea with negative displacement)
105  // from SP; take no action on subsequent subtracts.
106  // test case: pthread_cond_wait@@GLIBC_2.3.2 in
107  // 3.10.0-327.el7.centos.mpsp_1.3.1.45.x86_64
108  //
109  // 5 November 2016 -- John Mellor-Crummey
110  //--------------------------------------------------------------
111  hw_tmp->uwi = next;
112  hw_tmp->succ_inst_ptr = next_ins;
113  hw_tmp->state = HW_NEW_STATE(hw_tmp->state, HW_SP_DECREMENTED);
114  iarg->canonical_interval = next;
115  }
116  }
117  }
118  }
119  }
120  }
121  }
122  return next;
123 }
#define HW_NEW_STATE(state, set)
bitree_uwi_t * current
#define HW_BP_SAVED
Definition: x86-canonical.c:55
#define UWI_RECIPE(btuwi)
#define HW_BP_OVERWRITTEN
Definition: x86-canonical.c:56
x86registers_t reg
bitree_uwi_t * canonical_interval
static char * nextInsn(uint32_t *insn)
#define HW_SP_DECREMENTED
Definition: x86-canonical.c:57
highwatermark_t highwatermark
unwind_interval * new_ui(char *startaddr, sp_ty_t sp_ty, ra_ty_t ra_ty, int sp_arg, int ra_arg)
#define HW_TEST_STATE(state, is_set, is_clear)
unwind_interval * process_lea(xed_decoded_inst_t *xptr, const xed_inst_t *xi, interval_arg_t *iarg)
Definition: x86-lea.c:55
bitree_uwi_t unwind_interval