Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

nci/suif/suif2b/utils/expression_utils.cpp File Reference

#include "common/system_specific.h"
#include "common/suif_indexed_list.h"
#include "expression_utils.h"
#include "suifkernel/utilities.h"
#include "basicnodes/basic.h"
#include "basicnodes/basic_factory.h"
#include "basicnodes/basic_constants.h"
#include "suifnodes/suif.h"
#include "suifnodes/suif_factory.h"
#include "cfenodes/cfe.h"
#include "typebuilder/type_builder.h"
#include "symbol_utils.h"
#include "semantic_helper.h"
#include "type_utils.h"
#include "cloning_utils.h"
#include "suifkernel/module_subsystem.h"
#include "fold_table.h"

Functions

IInteger restrict_int_to_data_type (DataType *t, const IInteger &ii)
 Restrict an iinteger to the bit_size, signed-ness use 2s complement on overflow.

IInteger get_expression_constant (const Expression *exp)
 Get an integer constant from an expression. More...

bool is_variable_modified (const VariableSymbol* var, ExecutionObject* obj)
 Checks whether the variable var is modified inside obj. More...

bool is_expr_modified (const Expression* expr, ExecutionObject* obj)
 Checks whether the value of expression expr is modified inside obj. More...

Expression* create_const_op (SuifEnv *env,int value)
IntConstant* create_int_constant ( SuifEnv* suif_env, IInteger i )
 Create an integer constant. More...

ProcedureSymbol* get_procedure_from_address_op (const Expression *procedure_address)
ProcedureSymbol* get_procedure_target_from_call (const CallStatement *st)
 Get the procedure to be called by a call statement.

ProcedureSymbol* get_procedure_target_from_call (const ExecutionObject *call)
ProcedureDefinition* get_procedure_definition (const ExecutionObject *eo)
SuifObjectremove_suif_object (SuifObject *obj)
 Remove an object from its owner, and clear its parent pointer. More...

Expression* replace_expression (Expression *expr, Expression *replacement)
 replace an expression with a new expression A thin and somewhat redundent wrapper around expr->get_parent()->replace(expr,replacement);.

Statement* replace_statement (Statement *stmt, Statement *replacement)
 Replace a statement with a new statement.

Statement* remove_statement (Statement *loc)
 remove the statement If it's parent is a statement list, we will do the appropriate removal. More...

Statement* insert_statement_before (Statement *loc, Statement *the_statement)
 Smart statement insert. More...

Statement* insert_statement_after (Statement *loc, Statement *the_statement)
 Insert statement after the given statement Similar optimizations to insert_statement_before apply.

Statement* get_expression_owner (Expression *expr)
 find the statement at the base of this expression tree.

bool is_target_label (CodeLabelSymbol *target_label, Statement *st)
 Return true if the target_label could a branch target for the Statement For code labels with their address taken, the result is always true.

void insert_statement_after_loop_body (WhileStatement *the_loop, Statement *the_statement)
 Insert a statement at the end of a loop body. More...

void insert_statement_after_loop_body (DoWhileStatement *the_loop, Statement *the_statement)
 Insert a statement at the end of a loop body. More...

void insert_statement_after_loop_body (ForStatement *the_loop, Statement *the_statement)
 Insert a statement at the end of a loop body. More...

void force_dest_not_expr (Expression *expr, list<StoreVariableStatement*> &dismantled)
list<StoreVariableStatement*>* force_dest_not_expr (Expression *expr)
 Turn the expression into a store of a variable. More...

bool is_void_dest (Expression *expr)
 Return true if there is no destination for an expression. More...

Statement* build_assign (VariableSymbol *dst, Expression *expr)
 Create an assignment statement.

Statement* build_assign (VariableSymbol *dst, VariableSymbol *src)
 Create an assignment statement.

Expression* build_cast (Expression *expr, DataType *t)
 Create a cast.

void inline_call (CallStatement *the_call, ProcedureSymbol *target_proc)
 If target_proc is 0, find the direct target from the call. More...

Expression* clone_if_needed (Expression *e)
 Clone an expression if it has a parent. More...

Expression* build_dyadic_expression (LString op,Expression *left,Expression *right)
 Build a dyadic expression Constant folding is done if needed. More...

Expression* build_monadic_expression (LString op,Expression *subexp)
 Build a monadic expression. More...

Expression* fold_and_replace_constants (Expression *expr)
 Return a constant folded version of the source expression. More...

Statement* fold_and_replace_constants (Statement *stmt)
 Return a constant folded version of the statement. More...

void add_targets (Statement* the_stmt, list<CodeLabelSymbol*>& targets)
 Add jump targets that are possibly contained in stmt to the list of targets targets. More...

void get_jumps_from_outside (ScopedObject* scope, searchable_list<CodeLabelSymbol*>& targets)
 Appends all jumps from outside of the scope to targets.

bool has_jumps_going_inside (ScopedObject* scope)
 Returns true of the scoped object has a jump going into it from the outside.

Expression* clone_expression (Expression *expr)
 Clone an expression. More...


Function Documentation

void add_targets ( Statement * stmt,
list<CodeLabelSymbol *>& targets)

Add jump targets that are possibly contained in stmt to the list of targets targets.

If the statement isn't a jump of some sort, nothing is added to the list.

Warning:
This currently doesn't support indirect jumps.

Statement * build_assign ( VariableSymbol * dest,
VariableSymbol * src)

Create an assignment statement.

Statement * build_assign ( VariableSymbol * dest,
Expression * expr)

Create an assignment statement.

Expression * build_cast ( Expression * expr,
DataType * t)

Create a cast.

Expression * build_dyadic_expression ( LString op,
Expression * left,
Expression * right)

Build a dyadic expression Constant folding is done if needed.

(very minimal at present) If constant folding occurs, and the parameter expressions have no parent, they are deleted. If no folding occurs and the parameter expressions have parents, they are cloned

Expression * build_monadic_expression ( LString op,
Expression * subexp)

Build a monadic expression.

The monadic equivalent of the above

Expression * clone_expression ( Expression * expr)

Clone an expression.

All references to non-owned objects will remain

Expression * clone_if_needed ( Expression * subexp)

Clone an expression if it has a parent.

\warning. Think before doing this. Cloning an expression will result in two evaluations of the expression. Perhaps you want to assign to a variable and use that instead. Most often used with constants

Expression * create_const_op ( SuifEnv * env,
int value)

IntConstant * create_int_constant ( SuifEnv * suif_env,
IInteger i)

Create an integer constant.

The type will be the type for word_type taken fromt the target information block

Statement * fold_and_replace_constants ( Statement * statement)

Return a constant folded version of the statement.

Branches or If Statements will be simplified, Empty StatementLists will be removed. The expressions used by the statementes will be simplified. WARNING. This may update the IR node that the statement is attached to. Be careful when using this while walking.

This constant folder is extensible. To add a new IR node folding routine: include "utils/fold_table.h"

FoldTable *fold_table = FoldTable::get_fold_table(suif_env); fold_table->add_statement_fold_fn(IR_meta_class_name, fn);

Expression * fold_and_replace_constants ( Expression * expr)

Return a constant folded version of the source expression.

Any portion of the expression determined to be constant will be replaced with a constant expression. Any replaced expressions (including the source expression) will be either re-used or tossed in the trash

These routines do not yet fold Floating Point constants.

WARNING. This may update the IR node that the expression is attached to. Be careful when using this while walking.

This constant folder is extensible. To add a new IR Expression node folding routine or a new Binary or Unary opcode routine: include "utils/fold_table.h"

FoldTable *fold_table = FoldTable::get_fold_table(suif_env); fold_table->add_binary_fold_fn(opcode, fn); fold_table->add_unary_fold_fn(opcode, fn); fold_table->add_expression_fold_fn(IR_meta_class_name, fn);

list<StoreVariableStatement *>* force_dest_not_expr<StoreVariableStatement*> ( Expression * expr)

Turn the expression into a store of a variable.

followed by a reference. This can cause major code changes if the expression is in a do-while or while-do loop test.

If new statements are required, they will be returned It is possible to create Multiple statements from a single expression.

void force_dest_not_expr ( Expression * expr,
list<StoreVariableStatement *>& dismantled)

IInteger get_expression_constant ( const Expression * exp)

Get an integer constant from an expression.

Returns indeterminate if the expression is not an integer constant

Statement * get_expression_owner ( Expression * expr)

find the statement at the base of this expression tree.

void get_jumps_from_outside ( ScopedObject * scope,
searchable_list<CodeLabelSymbol *>& targets)

Appends all jumps from outside of the scope to targets.

ProcedureDefinition * get_procedure_definition ( const ExecutionObject * eo)

ProcedureSymbol * get_procedure_from_address_op ( const Expression * procedure_address)

ProcedureSymbol * get_procedure_target_from_call ( const ExecutionObject * call)

ProcedureSymbol * get_procedure_target_from_call ( const CallStatement * call)

Get the procedure to be called by a call statement.

bool has_jumps_going_inside ( ScopedObject * scope)

Returns true of the scoped object has a jump going into it from the outside.

void inline_call ( CallStatement * the_call,
ProcedureSymbol * target_proc)

If target_proc is 0, find the direct target from the call.

otherwise, the target proc should be consistent with the call's address operand. (Original comment preserved - no idea what this does)

Statement * insert_statement_after ( Statement * loc,
Statement * the_statement)

Insert statement after the given statement Similar optimizations to insert_statement_before apply.

void insert_statement_after_loop_body ( ForStatement * the_loop,
Statement * the_statement)

Insert a statement at the end of a loop body.

If the loop continue label is used a new continue label will be created and an explicit label will be placed before the inserted statement.

void insert_statement_after_loop_body ( DoWhileStatement * the_loop,
Statement * the_statement)

Insert a statement at the end of a loop body.

If the loop continue label is used a new continue label will be created and an explicit label will be placed before the inserted statement.

void insert_statement_after_loop_body ( WhileStatement * the_loop,
Statement * the_statement)

Insert a statement at the end of a loop body.

If the loop continue label is used a new continue label will be created and an explicit label will be placed before the inserted statement.

Statement * insert_statement_before ( Statement * loc,
Statement * the_statement)

Smart statement insert.

Puts the existing statement into a statement list and inserts in that statement list, if neccessary. If loc is already in a statement list, or is a statement list itself, the existing statement is used.

Returns the list into which the insertion was made

bool is_expr_modified ( const Expression * expr,
ExecutionObject * obj)

Checks whether the value of expression expr is modified inside obj.

Notice that the results are likely to be overly consirvsative at this point, as no real mod analysis is performed.

bool is_target_label ( CodeLabelSymbol * target_label,
Statement * the_statement)

Return true if the target_label could a branch target for the Statement For code labels with their address taken, the result is always true.

bool is_variable_modified ( const VariableSymbol * var,
ExecutionObject * obj)

Checks whether the variable var is modified inside obj.

Notice that the results are likely to be overly consirvsative at this point, as no real mod analysis is performed.

bool is_void_dest ( Expression * expr)

Return true if there is no destination for an expression.

Currently, this means that it is an Eval Statement.

Statement * remove_statement ( Statement * the_statement)

remove the statement If it's parent is a statement list, we will do the appropriate removal.

If not, we will replace it with a new empty statement list.

SuifObject * remove_suif_object ( SuifObject * obj)

Remove an object from its owner, and clear its parent pointer.

This should be moved to somewhere else

Expression * replace_expression ( Expression * expr,
Expression * replacement)

replace an expression with a new expression A thin and somewhat redundent wrapper around expr->get_parent()->replace(expr,replacement);.

Statement * replace_statement ( Statement * stmt,
Statement * replacement)

Replace a statement with a new statement.

IInteger restrict_int_to_data_type ( DataType * t,
const IInteger & ii)

Restrict an iinteger to the bit_size, signed-ness use 2s complement on overflow.


Generated at Mon Jul 31 13:42:27 2000 for NCI SUIF by doxygen 1.1.2 written by Dimitri van Heesch, © 1997-2000