Skip to content

Commit

Permalink
[Expression Propagation] remove propagation limit (#348)
Browse files Browse the repository at this point in the history
* Create draft PR for #44

* removed configurations and corresponding function

* removed corresponding tests

* Fix removed stages

* Removed limit options

* Fix stage order

* Fix resolving conflict mistake

---------

Co-authored-by: fnhartmann <[email protected]>
Co-authored-by: fnhartmann <[email protected]>
Co-authored-by: fnhartmann <[email protected]>
  • Loading branch information
4 people authored Dec 6, 2023
1 parent fcb7292 commit 2f0294a
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 333 deletions.
28 changes: 0 additions & 28 deletions decompiler/pipeline/commons/expressionpropagationcommons.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ class ExpressionPropagationBase(PipelineStage, ABC):
name = "expression-propagation-base"

def __init__(self):
self._limit: Optional[int] = None
self._limits: Dict[Instruction, int]
self._use_map: UseMap
self._def_map: DefMap
self._pointers_info: Optional[Pointers] = None
Expand All @@ -43,7 +41,6 @@ def __init__(self):

def run(self, task: DecompilerTask):
"""Execute the expression propagation on the current ControlFlowGraph."""
self._parse_options(task)
iteration = 0
# execute until there are no more changes
while self.perform(task.graph, iteration):
Expand Down Expand Up @@ -89,15 +86,6 @@ def _definition_can_be_propagated_into_target(self, definition: Assignment, targ
"""
pass

def _parse_options(self, task: DecompilerTask):
"""Parse the config options for this pipeline stage."""
self._limit = task.options.getint(f"{self.name}.maximum_instruction_complexity")
self._limits = {
Branch: min(self._limit, task.options.getint(f"{self.name}.maximum_branch_complexity")),
Call: min(self._limit, task.options.getint(f"{self.name}.maximum_call_complexity")),
Assignment: min(self._limit, task.options.getint(f"{self.name}.maximum_assignment_complexity")),
}

def _initialize_maps(self, cfg: ControlFlowGraph) -> None:
"""
Fills use and def maps.
Expand Down Expand Up @@ -205,22 +193,6 @@ def _operation_is_propagated_in_phi(self, target: Instruction, definition: Assig
do not allow phi arguments to be unary or binary operations"""
return isinstance(target, Phi) and isinstance(definition.value, Operation)

def _resulting_instruction_is_too_long(self, target: Instruction, definition: Assignment) -> bool:
"""Instruction after expression propagation should not be longer than a given limit
we already test that only vars and constants are propagated in phi,
therefore the length of phi after propagation will be constant;
same with propagating instructions like e.g. a = b or a = 10.
"""
if self._is_phi(target) or self._is_copy_assignment(definition):
return False
limit = self._limits.get(type(target), self._limit)
if self._is_call_assignment(target):
limit = self._limits[Call]
count = len([expr for expr in self._find_subexpressions(target) if expr == definition.destination])
propagated_complexity = target.complexity + (definition.value.complexity - definition.destination.complexity) * count
return propagated_complexity > limit

def _is_address_assignment(self, definition: Assignment) -> bool:
"""
Currently propagating a = &x into uses of a causes problems (see test21 in test_memory). So for the moment is not propagated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def _definition_can_be_propagated_into_target(self, definition: Assignment, targ
or self._is_address_assignment(definition)
or self._contains_global_variable(definition)
or self._operation_is_propagated_in_phi(target, definition)
or self._resulting_instruction_is_too_long(target, definition)
or self._is_invalid_propagation_into_address_operation(target, definition)
or self._is_dereference_assignment(definition)
)
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ def _definition_can_be_propagated_into_target(self, definition: Assignment, targ
or self._is_address_assignment(definition)
or self._contains_global_variable(definition)
or self._operation_is_propagated_in_phi(target, definition)
or self._resulting_instruction_is_too_long(target, definition)
or self._is_invalid_propagation_into_address_operation(target, definition)
or self._is_dereference_assignment(definition)
or self._definition_value_could_be_modified_via_memory_access_between_definition_and_target(definition, target)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def _definition_can_be_propagated_into_target(self, definition: Assignment, targ
or self._contains_global_variable(definition)
or self._operation_is_propagated_in_phi(target, definition)
or self._is_invalid_propagation_into_address_operation(target, definition)
or self._resulting_instruction_is_too_long(target, definition)
or self._is_aliased_postponed_for_propagation(target, definition)
or self._definition_value_could_be_modified_via_memory_access_between_definition_and_target(definition, target)
or self._pointer_value_used_in_definition_could_be_modified_via_memory_access_between_definition_and_target(definition, target)
Expand Down
126 changes: 0 additions & 126 deletions decompiler/util/default.json
Original file line number Diff line number Diff line change
@@ -1,130 +1,4 @@
[
{
"title": "Expression Propagation",
"description": "Settings for the expression propagation pipeline stages:",
"options": [
{
"dest": "expression-propagation.maximum_instruction_complexity",
"default": 100,
"title": "EP maximum instruction complexity",
"type": "number",
"description": "Maximum complexity for an instruction to be propagated",
"is_hidden_from_gui": true,
"is_hidden_from_cli": false,
"argument_name": "--ep-max-instruction-complexity"
},
{
"dest": "expression-propagation.maximum_branch_complexity",
"default": 100,
"title": "EP maximum branch complexity",
"type": "number",
"description": "Maximum complexity for a branch to be propagated",
"is_hidden_from_gui": true,
"is_hidden_from_cli": false,
"argument_name": "--ep-max-branch-complexity"
},
{
"dest": "expression-propagation.maximum_call_complexity",
"default": 100,
"title": "EP maximum call complexity",
"type": "number",
"description": "Maximum complexity for a call to be propagated",
"is_hidden_from_gui": true,
"is_hidden_from_cli": false,
"argument_name": "--ep-max-call-complexity"
},
{
"dest": "expression-propagation.maximum_assignment_complexity",
"default": 100,
"title": "EP maximum assignment complexity",
"type": "number",
"description": "Maximum complexity for an assignment to be propagated",
"is_hidden_from_gui": true,
"is_hidden_from_cli": false,
"argument_name": "--ep-max-assignment-complexity"
},
{
"dest": "expression-propagation-memory.maximum_instruction_complexity",
"default": 100,
"title": "EPM maximum instruction complexity",
"type": "number",
"description": "Maximum complexity for an instruction to be propagated (consider memory access)",
"is_hidden_from_gui": true,
"is_hidden_from_cli": false,
"argument_name": "--epm-max-instruction-complexity"
},
{
"dest": "expression-propagation-memory.maximum_branch_complexity",
"default": 100,
"title": "EPM maximum branch complexity",
"type": "number",
"description": "Maximum complexity for a branch to be propagated (consider memory access)",
"is_hidden_from_gui": true,
"is_hidden_from_cli": false,
"argument_name": "--epm-max-branch-complexity"
},
{
"dest": "expression-propagation-memory.maximum_call_complexity",
"default": 100,
"title": "EPM maximum call complexity",
"type": "number",
"description": "Maximum complexity for a call to be propagated (consider memory access)",
"is_hidden_from_gui": true,
"is_hidden_from_cli": false,
"argument_name": "--epm-max-call-complexity"
},
{
"dest": "expression-propagation-memory.maximum_assignment_complexity",
"default": 100,
"title": "EPM maximum assignment complexity",
"type": "number",
"description": "Maximum complexity for an assignment to be propagated (consider memory access)",
"is_hidden_from_gui": true,
"is_hidden_from_cli": false,
"argument_name": "--epm-max-assignment-complexity"
},
{
"dest": "expression-propagation-function-call.maximum_instruction_complexity",
"default": 100,
"title": "EPFC maximum instruction complexity",
"type": "number",
"description": "Maximum complexity for an instruction to be propagated (consider function calls)",
"is_hidden_from_gui": true,
"is_hidden_from_cli": false,
"argument_name": "--epfc-max-instruction-complexity"
},
{
"dest": "expression-propagation-function-call.maximum_branch_complexity",
"default": 100,
"title": "EPFC maximum branch complexity",
"type": "number",
"description": "Maximum complexity for a branch to be propagated (consider function calls)",
"is_hidden_from_gui": true,
"is_hidden_from_cli": false,
"argument_name": "--epfc-max-branch-complexity"
},
{
"dest": "expression-propagation-function-call.maximum_call_complexity",
"default": 100,
"title": "EPFC maximum call complexity",
"type": "number",
"description": "Maximum complexity for a call to be propagated (consider function calls)",
"is_hidden_from_gui": true,
"is_hidden_from_cli": false,
"argument_name": "--epfc-max-call-complexity"
},
{
"dest": "expression-propagation-function-call.maximum_assignment_complexity",
"default": 100,
"title": "EPFC maximum assignment complexity",
"type": "number",
"description": "Maximum complexity for an assignment to be propagated (consider function calls)",
"is_hidden_from_gui": true,
"is_hidden_from_cli": false,
"argument_name": "--epfc-max-assignment-complexity"
}
]
},
{
"title": "Code Elimination",
"description": "Dead code, and common subexpression elimination settings:",
Expand Down
Loading

0 comments on commit 2f0294a

Please sign in to comment.