mblock_t Class Reference

Microcode of one basic block. More...

Public Member Functions

void mark_lists_dirty (void)
 
void request_propagation (void)
 
bool needs_propagation (void) const
 
void request_demote64 (void)
 
bool lists_dirty (void) const
 
bool lists_ready (void) const
 
int make_lists_ready (void)
 
int npred (void) const
 Get number of block predecessors.
 
int nsucc (void) const
 Get number of block successors.
 
int pred (int n) const
 
int succ (int n) const
 
bool empty (void) const
 
void print (vd_printer_t &vp) const
 Print block contents. More...
 
void dump (void) const
 Dump block info. More...
 
void vdump_block (const char *title, va_list va) const
 
void dump_block (const char *title,...) const
 
minsn_tinsert_into_block (minsn_t *nm, minsn_t *om)
 Insert instruction into the doubly linked list. More...
 
minsn_tremove_from_block (minsn_t *m)
 Remove instruction from the doubly linked list. More...
 
int for_all_insns (minsn_visitor_t &mv)
 Visit all instructions. More...
 
int for_all_ops (mop_visitor_t &mv)
 Visit all operands. More...
 
int for_all_uses (mlist_t *list, minsn_t *i1, minsn_t *i2, mlist_mop_visitor_t &mmv)
 Visit all operands that use LIST. More...
 
int optimize_insn (minsn_t *m, int optflags=OPTI_MINSTKREF|OPTI_COMBINSNS)
 Optimize one instruction in the context of the block. More...
 
int optimize_block (void)
 Optimize a basic block. More...
 
int build_lists (bool kill_deads)
 Build def-use lists and eliminate deads. More...
 
void append_use_list (mlist_t *list, const mop_t &op, maymust_t maymust, bitrange_t mask=MAXRANGE) const
 Append use-list of an operand. More...
 
void append_def_list (mlist_t *list, const mop_t &op, maymust_t maymust) const
 Append def-list of an operand. More...
 
mlist_t build_use_list (const minsn_t &ins, maymust_t maymust) const
 Build use-list of an instruction. More...
 
mlist_t build_def_list (const minsn_t &ins, maymust_t maymust) const
 Build def-list of an instruction. More...
 
bool is_used (mlist_t *list, const minsn_t *i1, const minsn_t *i2, maymust_t maymust=MAY_ACCESS) const
 Is the list used by the specified instruction range? More...
 
const minsn_tfind_first_use (mlist_t *list, const minsn_t *i1, const minsn_t *i2, maymust_t maymust=MAY_ACCESS) const
 Find the first insn that uses the specified list in the insn range. More...
 
minsn_tfind_first_use (mlist_t *list, minsn_t *i1, const minsn_t *i2, maymust_t maymust=MAY_ACCESS) const
 
bool is_redefined (const mlist_t &list, const minsn_t *i1, const minsn_t *i2, maymust_t maymust=MAY_ACCESS) const
 Is the list redefined by the specified instructions? More...
 
const minsn_tfind_redefinition (const mlist_t &list, const minsn_t *i1, const minsn_t *i2, maymust_t maymust=MAY_ACCESS) const
 Find the first insn that redefines any part of the list in the insn range. More...
 
minsn_tfind_redefinition (const mlist_t &list, minsn_t *i1, const minsn_t *i2, maymust_t maymust=MAY_ACCESS) const
 
bool is_rhs_redefined (minsn_t *ins, minsn_t *i1, minsn_t *i2)
 Is the right hand side of the instruction redefined the insn range? "right hand side" corresponds to the source operands of the instruction. More...
 
minsn_tfind_access (const mop_t &op, minsn_t **parent, const minsn_t *mend, int fdflags) const
 Find the instruction that accesses the specified operand. More...
 
minsn_tfind_def (const mop_t &op, minsn_t **p_i1, const minsn_t *i2, int fdflags)
 
minsn_tfind_use (const mop_t &op, minsn_t **p_i1, const minsn_t *i2, int fdflags)
 
bool get_valranges (valrng_t *res, const vivl_t &vivl, int vrflags) const
 Find possible values. More...
 
void make_nop (minsn_t *m)
 Erase the instruction (convert it to nop) and mark the lists dirty. More...
 

Public Attributes

mblock_tnextb
 next block in the doubly linked list
 
mblock_tprevb
 previous block in the doubly linked list
 
uint32 flags
 combination of Basic block properties bits
 
ea_t start
 start address
 
ea_t end
 end address note: we can not rely on start/end addresses very much because instructions are propagated between blocks
 
minsn_thead
 pointer to the first instruction of the block
 
minsn_ttail
 pointer to the last instruction of the block
 
mbl_array_tmba
 the parent micro block array
 
int serial
 block number
 
mblock_type_t type
 block type (BLT_NONE - not computed yet)
 
mlist_t dead_at_start
 data that is dead at the block entry
 
mlist_t mustbuse
 data that must be used by the block
 
mlist_t maybuse
 data that may be used by the block
 
mlist_t mustbdef
 data that must be defined by the block
 
mlist_t maybdef
 data that may be defined by the block
 
mlist_t dnu
 data that is defined but not used in the block
 
sval_t maxbsp
 maximal sp value in the block (0...stacksize)
 
sval_t minbstkref
 lowest stack location accessible with indirect addressing (offset from the stack bottom) initially it is 0 (not computed)
 
sval_t minbargref
 the same for arguments
 
intvec_t predset
 control flow graph: list of our predecessors use npred() and pred() to access it
 
intvec_t succset
 control flow graph: list of our successors use nsucc() and succ() to access it
 
char reserved []
 

Friends

class codegen_t
 

Detailed Description

Microcode of one basic block.

All blocks are part of a doubly linked list as well as can be addressed by indexing the mba->natural array. A block contains a doubly linked list of instructions, various localtion lists that are used for data flow analysis and other attributes.

Examples:
hexrays_sample10.cpp, hexrays_sample11.cpp, and hexrays_sample12.cpp.

Definition at line 3527 of file hexrays.hpp.

Member Function Documentation

◆ append_def_list()

void mblock_t::append_def_list ( mlist_t list,
const mop_t op,
maymust_t  maymust 
) const

Append def-list of an operand.

This function calculates list of locations that may or must be modified by the operand and appends it to LIST.

Parameters
listptr to the output buffer. we will append to it.
opoperand to calculate the def list of
maymustshould we calculate 'may-def' or 'must-def' list? see maymust_t for more details.

Definition at line 10285 of file hexrays.hpp.

References hexdsp.

◆ append_use_list()

void mblock_t::append_use_list ( mlist_t list,
const mop_t op,
maymust_t  maymust,
bitrange_t  mask = MAXRANGE 
) const

Append use-list of an operand.

This function calculates list of locations that may or must be used by the operand and appends it to LIST.

Parameters
listptr to the output buffer. we will append to it.
opoperand to calculate the use list of
maymustshould we calculate 'may-use' or 'must-use' list? see maymust_t for more details.
maskif only part of the operand should be considered, a bitmask can be used to specify which part. example: op=AX,mask=0xFF means that we will consider only AL.

Definition at line 10279 of file hexrays.hpp.

References hexdsp.

◆ build_def_list()

mlist_t mblock_t::build_def_list ( const minsn_t ins,
maymust_t  maymust 
) const

Build def-list of an instruction.

This function calculates list of locations that may or must be modified by the instruction. Examples: "stx ebx.4, ds.2, eax.4", may-list: all aliasable memory "stx ebx.4, ds.2, eax.4", must-list: empty Since STX uses EAX for indirect access, it may modify any aliasable memory. On the other hand, we can not tell for sure which memory cells will be modified, this is why the must-list is empty.

Parameters
insinstruction to calculate the def list of
maymustshould we calculate 'may-def' or 'must-def' list? see maymust_t for more details.
Returns
the calculated def-list
Examples:
hexrays_sample12.cpp.

Definition at line 10299 of file hexrays.hpp.

References hexdsp.

◆ build_lists()

int mblock_t::build_lists ( bool  kill_deads)

Build def-use lists and eliminate deads.

Parameters
kill_deadsdo delete dead instructions?
Returns
the number of eliminated instructions Better mblock_t::call make_lists_ready() rather than this function.

Definition at line 10273 of file hexrays.hpp.

References hexdsp.

◆ build_use_list()

mlist_t mblock_t::build_use_list ( const minsn_t ins,
maymust_t  maymust 
) const

Build use-list of an instruction.

This function calculates list of locations that may or must be used by the instruction. Examples: "ldx ds.2, eax.4, ebx.4", may-list: all aliasable memory "ldx ds.2, eax.4, ebx.4", must-list: empty Since LDX uses EAX for indirect access, it may access any aliasable memory. On the other hand, we can not tell for sure which memory cells will be accessed, this is why the must-list is empty.

Parameters
insinstruction to calculate the use list of
maymustshould we calculate 'may-use' or 'must-use' list? see maymust_t for more details.
Returns
the calculated use-list
Examples:
hexrays_sample12.cpp.

Definition at line 10291 of file hexrays.hpp.

References hexdsp.

◆ dump()

void mblock_t::dump ( void  ) const

Dump block info.

This function is useful for debugging, see mbl_array_t::dump for info

Definition at line 10219 of file hexrays.hpp.

References hexdsp.

◆ find_access()

minsn_t * mblock_t::find_access ( const mop_t op,
minsn_t **  parent,
const minsn_t mend,
int  fdflags 
) const

Find the instruction that accesses the specified operand.

This function search inside one block.

Parameters
opoperand to search for
p_i1ptr to ptr to a top level instruction. denotes the beginning of the search range.
i2end instruction of the range (must be a top level insn) i2 is excluded from the range. it can be specified as NULL. i1 and i2 must belong to the same block. combination of bits for mblock_t::find_access bits
Returns
the instruction that accesses the operand. this instruction may be a sub-instruction. to find out the top level instruction, check out *p_i1. NULL means 'not found'.

Definition at line 10325 of file hexrays.hpp.

References hexdsp.

◆ find_first_use()

const minsn_t * mblock_t::find_first_use ( mlist_t list,
const minsn_t i1,
const minsn_t i2,
maymust_t  maymust = MAY_ACCESS 
) const

Find the first insn that uses the specified list in the insn range.

Parameters
listlist of locations. LIST may be modified by the function: redefined locations will be removed from it.
i1starting instruction of the range (must be a top level insn)
i2end instruction of the range (must be a top level insn) i2 is excluded from the range. it can be specified as NULL. i1 and i2 must belong to the same block.
maymustshould we search in 'may-access' or 'must-access' mode?
Returns
pointer to such instruction or NULL. Upon return LIST will contain only locations not redefined by insns [i1..result]

Definition at line 10307 of file hexrays.hpp.

References hexdsp.

◆ find_redefinition()

const minsn_t * mblock_t::find_redefinition ( const mlist_t list,
const minsn_t i1,
const minsn_t i2,
maymust_t  maymust = MAY_ACCESS 
) const

Find the first insn that redefines any part of the list in the insn range.

Parameters
listlist of locations to check.
i1starting instruction of the range (must be a top level insn)
i2end instruction of the range (must be a top level insn) i2 is excluded from the range. it can be specified as NULL. i1 and i2 must belong to the same block.
maymustshould we search in 'may-access' or 'must-access' mode?
Returns
pointer to such instruction or NULL.

Definition at line 10313 of file hexrays.hpp.

References hexdsp.

◆ for_all_insns()

int mblock_t::for_all_insns ( minsn_visitor_t mv)

Visit all instructions.

This function visits subinstructions too.

Parameters
mvinstruction visitor
Returns
zero or the value returned by mv.visit_insn() See also mbl_array_t::for_all_topinsns()

Definition at line 10243 of file hexrays.hpp.

References hexdsp.

◆ for_all_ops()

int mblock_t::for_all_ops ( mop_visitor_t mv)

Visit all operands.

This function visit subinstruction operands too.

Parameters
mvoperand visitor
Returns
zero or the value returned by mv.visit_mop()

Definition at line 10249 of file hexrays.hpp.

References hexdsp.

◆ for_all_uses()

int mblock_t::for_all_uses ( mlist_t list,
minsn_t i1,
minsn_t i2,
mlist_mop_visitor_t mmv 
)

Visit all operands that use LIST.

Parameters
listptr to the list of locations. it may be modified: parts that get redefined by the instructions in [i1,i2) will be deleted.
i1starting instruction. must be a top level insn.
i2ending instruction (excluded). must be a top level insn.
mmvoperand visitor
Returns
zero or the value returned by mmv.visit_mop()

Definition at line 10255 of file hexrays.hpp.

References hexdsp.

◆ get_valranges()

bool mblock_t::get_valranges ( valrng_t res,
const vivl_t vivl,
int  vrflags 
) const

Find possible values.

Parameters
resset of value ranges
keywhat to search for
vrflagscombination of bits for get_valranges bits
Examples:
hexrays_sample15.cpp.

Definition at line 10331 of file hexrays.hpp.

References hexdsp.

◆ insert_into_block()

minsn_t * mblock_t::insert_into_block ( minsn_t nm,
minsn_t om 
)

Insert instruction into the doubly linked list.

Parameters
nmnew instruction
omexisting instruction, part of the doubly linked list if NULL, then the instruction will be inserted at the beginning of the list NM will be inserted immediately after OM
Returns
pointer to NM

Definition at line 10231 of file hexrays.hpp.

References hexdsp.

◆ is_redefined()

bool mblock_t::is_redefined ( const mlist_t list,
const minsn_t i1,
const minsn_t i2,
maymust_t  maymust = MAY_ACCESS 
) const

Is the list redefined by the specified instructions?

Parameters
listlist of locations to check.
i1starting instruction of the range (must be a top level insn)
i2end instruction of the range (must be a top level insn) i2 is excluded from the range. it can be specified as NULL. i1 and i2 must belong to the same block.
maymustshould we search in 'may-access' or 'must-access' mode?

Definition at line 3810 of file hexrays.hpp.

◆ is_rhs_redefined()

bool mblock_t::is_rhs_redefined ( minsn_t ins,
minsn_t i1,
minsn_t i2 
)

Is the right hand side of the instruction redefined the insn range? "right hand side" corresponds to the source operands of the instruction.

Parameters
insinstruction to consider
i1starting instruction of the range (must be a top level insn)
i2end instruction of the range (must be a top level insn) i2 is excluded from the range. it can be specified as NULL. i1 and i2 must belong to the same block.

Definition at line 10319 of file hexrays.hpp.

References hexdsp.

◆ is_used()

bool mblock_t::is_used ( mlist_t list,
const minsn_t i1,
const minsn_t i2,
maymust_t  maymust = MAY_ACCESS 
) const

Is the list used by the specified instruction range?

Parameters
listlist of locations. LIST may be modified by the function: redefined locations will be removed from it.
i1starting instruction of the range (must be a top level insn)
i2end instruction of the range (must be a top level insn) i2 is excluded from the range. it can be specified as NULL. i1 and i2 must belong to the same block.
maymustshould we search in 'may-access' or 'must-access' mode?

Definition at line 3780 of file hexrays.hpp.

◆ make_nop()

void mblock_t::make_nop ( minsn_t m)

Erase the instruction (convert it to nop) and mark the lists dirty.

This is the recommended function to use because it also marks the block use-def lists dirty.

Definition at line 3916 of file hexrays.hpp.

References minsn_t::_make_nop().

◆ optimize_block()

int mblock_t::optimize_block ( void  )

Optimize a basic block.

Usually there is no need to call this function explicitly because the decompiler will call it itself if optinsn_t::func or optblock_t::func return non-zero.

Returns
number of changes made to the block

Definition at line 10267 of file hexrays.hpp.

References hexdsp.

◆ optimize_insn()

int mblock_t::optimize_insn ( minsn_t m,
int  optflags = OPTI_MINSTKREF|OPTI_COMBINSNS 
)

Optimize one instruction in the context of the block.

Parameters
mpointer to a top level instruction
optflagscombination of optimization flags bits
Returns
number of changes made to the block This function may change other instructions in the block too. However, it will not destroy top level instructions (it may convert them to nop's). See also minsn_t::optimize_solo()

Definition at line 10261 of file hexrays.hpp.

References hexdsp.

◆ print()

void mblock_t::print ( vd_printer_t vp) const

Print block contents.

Parameters
vpprint helpers class. it can be used to direct the printed info to any destination

Definition at line 10213 of file hexrays.hpp.

References hexdsp.

◆ remove_from_block()

minsn_t * mblock_t::remove_from_block ( minsn_t m)

Remove instruction from the doubly linked list.

Parameters
minstruction to remove The removed iinstruction is not deleted, the caller gets its ownership
Returns
pointer to the next instruction

Definition at line 10237 of file hexrays.hpp.

References hexdsp.