Ghidra 11.3.2
Ghidra internal decompiler documentation.
Loading...
Searching...
No Matches
ghidra::RuleIgnoreNan Class Reference

Remove certain NaN operations by assuming their result is always false. More...

Inheritance diagram for ghidra::RuleIgnoreNan:
[legend]
Collaboration diagram for ghidra::RuleIgnoreNan:
[legend]

Public Member Functions

 RuleIgnoreNan (const string &g)
 Constructor.
 
virtual Ruleclone (const ActionGroupList &grouplist) const
 Clone the Rule.
 
virtual void getOpList (vector< uint4 > &oplist) const
 List of op codes this rule operates on.
 
virtual int4 applyOp (PcodeOp *op, Funcdata &data)
 Attempt to apply this Rule.
 
- Public Member Functions inherited from ghidra::Rule
 Rule (const string &g, uint4 fl, const string &nm)
 Construct given group, properties name.
 
virtual ~Rule (void)
 Destructor.
 
const string & getName (void) const
 Return the name of this Rule.
 
const string & getGroup (void) const
 Return the group this Rule belongs to.
 
uint4 getNumTests (void)
 Get number of attempted applications.
 
uint4 getNumApply (void)
 Get number of successful applications.
 
void setBreak (uint4 tp)
 Set a breakpoint on this Rule.
 
void clearBreak (uint4 tp)
 Clear a breakpoint on this Rule.
 
void clearBreakPoints (void)
 Clear all breakpoints on this Rule.
 
void turnOnWarnings (void)
 Enable warnings for this Rule.
 
void turnOffWarnings (void)
 Disable warnings for this Rule.
 
bool isDisabled (void) const
 Return true if this Rule is disabled.
 
void setDisable (void)
 Disable this Rule (within its pool)
 
void clearDisable (void)
 Enable this Rule (within its pool)
 
bool checkActionBreak (void)
 Check if an action breakpoint is turned on.
 
uint4 getBreakPoint (void) const
 Return breakpoint toggles.
 
virtual void reset (Funcdata &data)
 Reset this Rule.
 
virtual void resetStats (void)
 Reset Rule statistics.
 
virtual void printStatistics (ostream &s) const
 Print statistics for this Rule.
 

Static Private Member Functions

static bool checkBackForCompare (Varnode *floatVar, Varnode *root)
 Check if a boolean Varnode incorporates a floating-point comparison with the given value.
 
static bool isAnotherNan (Varnode *vn)
 Test if the given Varnode is produced by a NaN operation.
 
static VarnodetestForComparison (Varnode *floatVar, PcodeOp *op, int4 slot, OpCode matchCode, int4 &count, Funcdata &data)
 Test if a boolean expression incorporates a floating-point comparison, and remove the NaN data-flow if it does.
 

Additional Inherited Members

- Public Types inherited from ghidra::Rule
enum  typeflags { type_disable = 1 , rule_debug = 2 , warnings_on = 4 , warnings_given = 8 }
 Properties associated with a Rule. More...
 

Detailed Description

Remove certain NaN operations by assuming their result is always false.

This rule can be configured to remove either all FLOAT_NAN operations or only those that protect floating-point comparisons.

Member Function Documentation

◆ applyOp()

int4 ghidra::RuleIgnoreNan::applyOp ( PcodeOp op,
Funcdata data 
)
virtual

Attempt to apply this Rule.

This method contains the main logic for applying the Rule. It must use a given PcodeOp as the point at which the Rule applies. If it does apply, changes are made directly to the function and 1 (non-zero) is returned, otherwise 0 is returned.

Parameters
opis the given PcodeOp where the Rule may apply
datais the function to which to apply

Reimplemented from ghidra::Rule.

References ghidra::Varnode::beginDescend(), ghidra::PcodeOp::code(), ghidra::CPUI_BOOL_AND, ghidra::CPUI_BOOL_NEGATE, ghidra::CPUI_BOOL_OR, ghidra::CPUI_COPY, ghidra::Varnode::endDescend(), ghidra::Funcdata::getArch(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::getOut(), ghidra::PcodeOp::getSlot(), ghidra::Varnode::isFree(), ghidra::Architecture::nan_ignore_all, ghidra::Funcdata::newConstant(), ghidra::Funcdata::opSetInput(), ghidra::Funcdata::opSetOpcode(), and testForComparison().

◆ checkBackForCompare()

bool ghidra::RuleIgnoreNan::checkBackForCompare ( Varnode floatVar,
Varnode root 
)
staticprivate

Check if a boolean Varnode incorporates a floating-point comparison with the given value.

The Varnode can either be the direct output of a comparison, or it can be a BOOL_OR or BOOL_AND, combining output from the comparison.

Parameters
floatVaris the given value the comparison must take as input
rootis the boolean Varnode
Returns
true if the boolean Varnode incorporates the comparison

References ghidra::PcodeOp::code(), ghidra::CPUI_BOOL_AND, ghidra::CPUI_BOOL_NEGATE, ghidra::CPUI_BOOL_OR, ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), ghidra::PcodeOp::getOpcode(), ghidra::PcodeOp::isBoolOutput(), ghidra::TypeOp::isFloatingPointOp(), ghidra::Varnode::isWritten(), and ghidra::PcodeOp::numInput().

Referenced by testForComparison().

◆ clone()

virtual Rule * ghidra::RuleIgnoreNan::clone ( const ActionGroupList grouplist) const
inlinevirtual

Clone the Rule.

If this Rule is a member of one of the groups in the grouplist, this returns a clone of the Rule, otherwise NULL is returned.

Parameters
grouplistis the list of groups being cloned
Returns
the cloned Rule or NULL

Implements ghidra::Rule.

References ghidra::ActionGroupList::contains(), and ghidra::Rule::getGroup().

◆ getOpList()

void ghidra::RuleIgnoreNan::getOpList ( vector< uint4 > &  oplist) const
virtual

List of op codes this rule operates on.

Populate the given array with all possible OpCodes this Rule might apply to. By default, this method returns all possible OpCodes

Parameters
oplistis the array to populate

Reimplemented from ghidra::Rule.

References ghidra::CPUI_FLOAT_NAN.

◆ isAnotherNan()

bool ghidra::RuleIgnoreNan::isAnotherNan ( Varnode vn)
staticprivate

Test if the given Varnode is produced by a NaN operation.

The Varnode can be the direct or negated output of a NaN.

Parameters
vnis the given Varnode
Returns
true if the Varnode is the output of the NaN

References ghidra::PcodeOp::code(), ghidra::CPUI_BOOL_NEGATE, ghidra::CPUI_FLOAT_NAN, ghidra::Varnode::getDef(), ghidra::PcodeOp::getIn(), and ghidra::Varnode::isWritten().

Referenced by testForComparison().

◆ testForComparison()

Varnode * ghidra::RuleIgnoreNan::testForComparison ( Varnode floatVar,
PcodeOp op,
int4  slot,
OpCode  matchCode,
int4 &  count,
Funcdata data 
)
staticprivate

Test if a boolean expression incorporates a floating-point comparison, and remove the NaN data-flow if it does.

The given PcodeOp takes input from a NaN operation through a specific slot. We look for a floating-point comparison PcodeOp (FLOAT_LESS, FLOAT_LESSEQUAL, FLOAT_EQUAL, or FLOAT_NOTEQUAL) that is combined with the given PcodeOp and has the same input Varnode as the NaN. The data-flow must be combined either through a BOOL_OR or BOOL_AND operation, or the given PcodeOp must be a CBRANCH that protects immediate control-flow to another CBRANCH taking the result of the comparison as input. If a matching comparison is found, the NaN input to the given PcodeOp is removed, assuming the output of the NaN operation is always false. Input from an unmodified NaN result must be combined through a BOOL_OR, but a NaN result that has been negated must combine through a BOOL_AND.

Parameters
floatVaris the input Varnode to NaN operation
opis the given PcodeOp to test
slotis the input index of the NaN operation
matchCodeis BOOL_AND if the NaN result has been negated, BOOL_OR if not
countis incremented if a comparison is found and the NaN input is removed
datais the function
Returns
the output of the given PcodeOp if it has an opcode matching matchCode

References checkBackForCompare(), ghidra::PcodeOp::code(), ghidra::CPUI_BOOL_OR, ghidra::CPUI_CBRANCH, ghidra::CPUI_COPY, ghidra::PcodeOp::getIn(), ghidra::FlowBlock::getOut(), ghidra::PcodeOp::getOut(), ghidra::PcodeOp::getParent(), isAnotherNan(), ghidra::PcodeOp::isBooleanFlip(), ghidra::FlowBlock::lastOp(), ghidra::Funcdata::newConstant(), ghidra::Funcdata::opRemoveInput(), ghidra::Funcdata::opSetInput(), and ghidra::Funcdata::opSetOpcode().

Referenced by applyOp().


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