IDA C++ SDK 9.2
Loading...
Searching...
No Matches
mblock_t Class Reference

Microcode of one basic block. More...

#include <hexrays.hpp>

Public Member Functions

void mark_lists_dirty ()
void request_propagation ()
bool needs_propagation () const
void request_demote64 ()
bool lists_dirty () const
bool lists_ready () const
int make_lists_ready ()
int npred () const
 Get number of block predecessors.
int nsucc () const
 Get number of block successors.
int pred (int n) const
int succ (int n) const
 mblock_t ()=delete
virtual ~mblock_t ()
 HEXRAYS_MEMORY_ALLOCATION_FUNCS () bool empty() const
void hexapi print (vd_printer_t &vp) const
 Print block contents.
void hexapi dump () const
 Dump block info.
 AS_PRINTF (2, 0) void hexapi vdump_block(const char *title
 AS_PRINTF (2, 3) void dump_block(const char *title
 va_start (va, title)
 vdump_block (title, va)
 va_end (va)
minsn_t *hexapi insert_into_block (minsn_t *nm, minsn_t *om)
 Insert instruction into the doubly linked list.
minsn_t *hexapi remove_from_block (minsn_t *m)
 Remove instruction from the doubly linked list.
int hexapi for_all_insns (minsn_visitor_t &mv)
 Visit all instructions.
int hexapi for_all_ops (mop_visitor_t &mv)
 Visit all operands.
int hexapi for_all_uses (mlist_t *list, minsn_t *i1, minsn_t *i2, mlist_mop_visitor_t &mmv)
 Visit all operands that use LIST.
int hexapi optimize_insn (minsn_t *m, int optflags=OPTI_MINSTKREF|OPTI_COMBINSNS)
 Optimize one instruction in the context of the block.
int hexapi optimize_block ()
 Optimize a basic block.
int hexapi build_lists (bool kill_deads)
 Build def-use lists and eliminate deads.
int hexapi optimize_useless_jump ()
 Remove a jump at the end of the block if it is useless.
void hexapi append_use_list (mlist_t *list, const mop_t &op, maymust_t maymust, bitrange_t mask=MAXRANGE) const
 Append use-list of an operand.
void hexapi append_def_list (mlist_t *list, const mop_t &op, maymust_t maymust) const
 Append def-list of an operand.
mlist_t hexapi build_use_list (const minsn_t &ins, maymust_t maymust) const
 Build use-list of an instruction.
mlist_t hexapi build_def_list (const minsn_t &ins, maymust_t maymust) const
 Build def-list of an instruction.
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?
const minsn_t *hexapi 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.
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?
const minsn_t *hexapi 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.
minsn_tfind_redefinition (const mlist_t &list, minsn_t *i1, const minsn_t *i2, maymust_t maymust=MAY_ACCESS) const
bool hexapi is_rhs_redefined (const minsn_t *ins, const minsn_t *i1, const minsn_t *i2) const
 Is the right hand side of the instruction redefined the insn range?
minsn_t *hexapi find_access (const mop_t &op, minsn_t **parent, const minsn_t *mend, int fdflags) const
 Find the instruction that accesses the specified operand.
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 hexapi get_valranges (valrng_t *res, const vivl_t &vivl, int vrflags) const
 Find possible values for a block.
bool hexapi get_valranges (valrng_t *res, const vivl_t &vivl, const minsn_t *m, int vrflags) const
 Find possible values for an instruction.
void make_nop (minsn_t *m)
 Erase the instruction (convert it to nop) and mark the lists dirty.
size_t hexapi get_reginsn_qty () const
 Calculate number of regular instructions in the block.
bool is_call_block () const
bool is_unknown_call () const
bool is_nway () const
bool is_branch () const
bool is_simple_goto_block () const
bool is_simple_jcnd_block () const

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 cannot 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
mba_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 []
va_list va const
 const

Friends

class codegen_t

Detailed Description

Microcode of one basic block.

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

Constructor & Destructor Documentation

◆ mblock_t()

mblock_t::mblock_t ( )
delete

◆ ~mblock_t()

virtual mblock_t::~mblock_t ( )
virtual

Member Function Documentation

◆ mark_lists_dirty()

void mblock_t::mark_lists_dirty ( )
inline

◆ request_propagation()

void mblock_t::request_propagation ( )
inline

◆ needs_propagation()

bool mblock_t::needs_propagation ( ) const
inline

◆ request_demote64()

void mblock_t::request_demote64 ( )
inline

◆ lists_dirty()

bool mblock_t::lists_dirty ( ) const
inline

◆ lists_ready()

bool mblock_t::lists_ready ( ) const
inline

◆ make_lists_ready()

int mblock_t::make_lists_ready ( )
inline

◆ npred()

int mblock_t::npred ( ) const
inline

Get number of block predecessors.

◆ nsucc()

int mblock_t::nsucc ( ) const
inline

Get number of block successors.

◆ pred()

int mblock_t::pred ( int n) const
inline

◆ succ()

int mblock_t::succ ( int n) const
inline

◆ HEXRAYS_MEMORY_ALLOCATION_FUNCS()

mblock_t::HEXRAYS_MEMORY_ALLOCATION_FUNCS ( ) const
inline

◆ print()

void mblock_t::print ( vd_printer_t & vp) const
inline

Print block contents.

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

◆ dump()

void mblock_t::dump ( ) const
inline

Dump block info.

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

◆ AS_PRINTF() [1/2]

mblock_t::AS_PRINTF ( 2 ,
0  ) const

◆ AS_PRINTF() [2/2]

mblock_t::AS_PRINTF ( 2 ,
3  ) const

◆ va_start()

mblock_t::va_start ( va ,
title  )

◆ vdump_block()

mblock_t::vdump_block ( title ,
va  )

◆ va_end()

mblock_t::va_end ( va )

◆ insert_into_block()

minsn_t *hexapi 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 nullptr, then the instruction will be inserted at the beginning of the list NM will be inserted immediately after OM
Returns
pointer to NM

◆ remove_from_block()

minsn_t * mblock_t::remove_from_block ( minsn_t * m)
inline

Remove instruction from the doubly linked list.

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

◆ for_all_insns()

int mblock_t::for_all_insns ( minsn_visitor_t & mv)
inline

Visit all instructions.

This function visits subinstructions too.

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

◆ for_all_ops()

int mblock_t::for_all_ops ( mop_visitor_t & mv)
inline

Visit all operands.

This function visit subinstruction operands too.

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

◆ for_all_uses()

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

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()

◆ optimize_insn()

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

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). This function performs only intrablock modifications. See also minsn_t::optimize_solo()

◆ optimize_block()

int mblock_t::optimize_block ( )
inline

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

◆ build_lists()

int mblock_t::build_lists ( bool kill_deads)
inline

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.

◆ optimize_useless_jump()

int mblock_t::optimize_useless_jump ( )
inline

Remove a jump at the end of the block if it is useless.

This function preserves any side effects when removing a useless jump. Both conditional and unconditional jumps are handled (and jtbl too). This function deletes useless jumps, not only replaces them with a nop. (please note that \optimize_insn does not handle useless jumps).

Returns
number of changes made to the block

◆ append_use_list()

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

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.

◆ append_def_list()

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

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.

◆ build_use_list()

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

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 cannot 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

◆ build_def_list()

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

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 cannot 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

◆ is_used()

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

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 nullptr. i1 and i2 must belong to the same block.
maymustshould we search in 'may-access' or 'must-access' mode?

◆ find_first_use() [1/2]

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
inline

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 nullptr. 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 nullptr. Upon return LIST will contain only locations not redefined by insns [i1..result]

◆ find_first_use() [2/2]

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

◆ 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
inline

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 nullptr. i1 and i2 must belong to the same block.
maymustshould we search in 'may-access' or 'must-access' mode?

◆ find_redefinition() [1/2]

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
inline

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 nullptr. 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 nullptr.

◆ find_redefinition() [2/2]

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

◆ is_rhs_redefined()

bool mblock_t::is_rhs_redefined ( const minsn_t * ins,
const minsn_t * i1,
const minsn_t * i2 ) const
inline

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 nullptr. i1 and i2 must belong to the same block.

◆ find_access()

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

Find the instruction that accesses the specified operand.

This function search inside one block.

Parameters
opoperand to search for
[in,out]parentptr to ptr to a top level instruction. in: denotes the beginning of the search range. out: denotes the parent of the found instruction.
mendend instruction of the range (must be a top level insn) mend is excluded from the range. it can be specified as nullptr. parent and mend must belong to the same block.
fdflagscombination 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 *parent. nullptr means 'not found'.

◆ find_def()

minsn_t * mblock_t::find_def ( const mop_t & op,
minsn_t ** p_i1,
const minsn_t * i2,
int fdflags )
inline

◆ find_use()

minsn_t * mblock_t::find_use ( const mop_t & op,
minsn_t ** p_i1,
const minsn_t * i2,
int fdflags )
inline

◆ get_valranges() [1/2]

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

Find possible values for a block.

Parameters
resset of value ranges
vivlwhat to search for
vrflagscombination of bits for get_valranges bits

◆ get_valranges() [2/2]

bool mblock_t::get_valranges ( valrng_t * res,
const vivl_t & vivl,
const minsn_t * m,
int vrflags ) const
inline

Find possible values for an instruction.

Parameters
resset of value ranges
vivlwhat to search for
minsn to search value ranges at.
See also
bits for get_valranges bits
Parameters
vrflagscombination of bits for get_valranges bits

◆ make_nop()

void mblock_t::make_nop ( minsn_t * m)
inline

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.

◆ get_reginsn_qty()

size_t mblock_t::get_reginsn_qty ( ) const
inline

Calculate number of regular instructions in the block.

Assertions are skipped by this function.

Returns
Number of non-assertion instructions in the block.

◆ is_call_block()

bool mblock_t::is_call_block ( ) const
inline

◆ is_unknown_call()

bool mblock_t::is_unknown_call ( ) const
inline

◆ is_nway()

bool mblock_t::is_nway ( ) const
inline

◆ is_branch()

bool mblock_t::is_branch ( ) const
inline

◆ is_simple_goto_block()

bool mblock_t::is_simple_goto_block ( ) const
inline

◆ is_simple_jcnd_block()

bool mblock_t::is_simple_jcnd_block ( ) const
inline

◆ codegen_t

friend class codegen_t
friend

Member Data Documentation

◆ nextb

mblock_t* mblock_t::nextb

next block in the doubly linked list

◆ prevb

mblock_t* mblock_t::prevb

previous block in the doubly linked list

◆ flags

uint32 mblock_t::flags

combination of Basic block properties bits

◆ start

ea_t mblock_t::start

start address

◆ end

ea_t mblock_t::end

end address note: we cannot rely on start/end addresses very much because instructions are propagated between blocks

◆ head

minsn_t* mblock_t::head

pointer to the first instruction of the block

◆ tail

minsn_t* mblock_t::tail

pointer to the last instruction of the block

◆ mba

mba_t* mblock_t::mba

the parent micro block array

◆ serial

int mblock_t::serial

block number

◆ type

mblock_type_t mblock_t::type

block type (BLT_NONE - not computed yet)

◆ dead_at_start

mlist_t mblock_t::dead_at_start

data that is dead at the block entry

◆ mustbuse

mlist_t mblock_t::mustbuse

data that must be used by the block

◆ maybuse

mlist_t mblock_t::maybuse

data that may be used by the block

◆ mustbdef

mlist_t mblock_t::mustbdef

data that must be defined by the block

◆ maybdef

mlist_t mblock_t::maybdef

data that may be defined by the block

◆ dnu

mlist_t mblock_t::dnu

data that is defined but not used in the block

◆ maxbsp

sval_t mblock_t::maxbsp

maximal sp value in the block (0...stacksize)

◆ minbstkref

sval_t mblock_t::minbstkref

lowest stack location accessible with indirect addressing (offset from the stack bottom) initially it is 0 (not computed)

◆ minbargref

sval_t mblock_t::minbargref

the same for arguments

◆ predset

intvec_t mblock_t::predset

control flow graph: list of our predecessors use npred() and pred() to access it

◆ succset

intvec_t mblock_t::succset

control flow graph: list of our successors use nsucc() and succ() to access it

◆ reserved

char mblock_t::reserved[]

◆ const [1/2]

va_list va mblock_t::const

◆ const [2/2]

mblock_t::const
Initial value:
{
va_list va
const tinfo_t const char va_list va
Definition hexrays.hpp:7301

The documentation for this class was generated from the following file: