36 #define DEBUG_NAME "compiler2/ConstantPropagationPass"
40 "constantpropagationpass","constantpropagationpass",compiler2_stat)
42 "number of nodes which could be folded",compiler2_constantpropagationpass_stat)
44 "number of PHIInsts which could be replaced",compiler2_constantpropagationpass_stat)
52 template <
typename T, Instruction::InstID ID>
53 struct BinaryOperation :
public std::binary_function<T,T,T> {
54 T operator()(
const T &lhs,
const T &rhs)
const ;
59 struct BinaryOperation<T, Instruction::ADDInstID> :
60 public std::binary_function<T,T,T> {
68 struct BinaryOperation<T, Instruction::SUBInstID> :
69 public std::binary_function<T,T,T> {
77 struct BinaryOperation<T, Instruction::MULInstID> :
78 public std::binary_function<T,T,T> {
86 struct BinaryOperation<T, Instruction::DIVInstID> :
87 public std::binary_function<T,T,T> {
95 struct BinaryOperation<T, Instruction::ANDInstID> :
96 public std::binary_function<T,T,T> {
103 template <
typename T>
115 assert(0 &&
"not implemented");
127 switch (inst->get_type()) {
130 op1->get_Int(), op2->get_Int()), Type::IntType());
133 op1->get_Long(), op2->get_Long()), Type::LongType());
136 op1->get_Float(), op2->get_Float()), Type::FloatType());
139 op1->get_Double(), op2->get_Double()), Type::DoubleType());
147 template <
typename T, Instruction::InstID ID>
149 T operator()(
const T &
op)
const;
153 template <
typename T>
155 public std::unary_function<T,T> {
162 template <
typename T>
168 assert(0 &&
"not implemented");
177 CONSTInst *
op = inst->get_operand(0)->to_Instruction()->to_CONSTInst();
179 assert(inst->get_type() == op->get_type());
181 switch (inst->get_type()) {
184 op->get_Int()), Type::IntType());
187 op->get_Long()), Type::LongType());
190 op->get_Float()), Type::FloatType());
193 op->get_Double()), Type::DoubleType());
200 template <
typename T>
202 switch (inst->get_type()) {
204 return new CONSTInst((int32_t) op, Type::IntType());
206 return new CONSTInst((int64_t) op, Type::LongType());
208 return new CONSTInst((
float) op, Type::FloatType());
210 return new CONSTInst((
double) op, Type::DoubleType());
218 CONSTInst *
op = inst->get_operand(0)->to_Instruction()->to_CONSTInst();
221 switch (op->get_type()) {
240 }
else if (inst->to_UnaryInst()) {
242 }
else if (inst->to_BinaryInst()) {
266 LOG(
"replace " << inst <<
" by " << c <<
nl);
272 assert(inst->op_size() > 0);
273 CONSTInst *firstOp = inst->get_operand(0)->to_Instruction()->to_CONSTInst();
275 e = inst->op_end();
i !=
e;
i++) {
276 CONSTInst *
op = (*i)->to_Instruction()->to_CONSTInst();
279 switch (inst->get_type()) {
281 equal = firstOp->get_Int() == op->get_Int();
284 equal = firstOp->get_Long() == op->get_Long();
287 equal = firstOp->get_Float() == op->get_Float();
290 equal = firstOp->get_Double() == op->get_Double();
304 return inst->is_arithmetic()
Template specialization for NEGInstID.
#define STATISTICS(x)
Wrapper for statistics only code.
Value * get_operand(size_t i)
virtual Instruction * to_Instruction()
#define STAT_REGISTER_SUBGROUP(var, name, description, group)
Register a statistics group and add it to a group.
Template specialization for DIVInstID.
virtual bool run(JITData &JD)
Run the Pass.
UserListTy::const_iterator user_begin() const
virtual CONSTInst * to_CONSTInst()
WorkListTy workList
This work list is used by the algorithm to store the instructions which have to be reconsidered...
_Base::const_iterator const_iterator
T operator()(const T &lhs, const T &rhs) const
T operator()(const T &lhs, const T &rhs) const
T operator()(const T &lhs, const T &rhs) const
UserListTy::const_iterator user_end() const
InstBoolMapTy inWorkList
will be used to look up whether an instruction is currently contained in the worklist to avoid insert...
InstIntMapTy constantOperands
used to track for each instruction the number of its operands which are already known to be constant ...
OperandListTy::const_iterator const_op_iterator
T operator()(const T &op) const
void add_schedule_before()
Schedule before PassName.
InstID get_opcode() const
return the opcode of the instruction
CONSTInst * foldBinaryInst(BinaryInst *inst)
CONSTInst * foldUnaryInst(UnaryInst *inst)
T operator()(const T &lhs, const T &rhs) const
void replace_value(Value *v)
Replace this Value this the new one in all users.
T unaryOperate(Instruction::InstID ID, const T &op)
function wrapper for UnaryOperation
Template specialization for MULInstID.
Template specialization for SUBInstID.
Template specialization for ADDInstID.
Stores the interdependencies of a pass.
virtual PassUsage & get_PassUsage(PassUsage &PA) const
Set the requirements for the pass.
#define STAT_REGISTER_GROUP_VAR(type, var, init, name, description, group)
Register an statistics variable and add it to a group.
bool has_only_constant_operands(Instruction *inst)
void add_Instruction(Instruction *I)
Add instructions to a Method.
T operator()(const T &lhs, const T &rhs) const
GlobalValueNumberingPass.
InstructionListTy::const_iterator const_iterator
const_iterator end() const
bool can_be_statically_evaluated(Instruction *inst)
CONSTInst * foldInstruction(Instruction *inst)
#define LOG(STMT)
Analogous to DEBUG.
CONSTInst * castOperate(CASTInst *inst, const T &op)
UnaryOperation function object class.
#define STAT_DECLARE_GROUP(var)
Declare an external group (or subgroup).
const_iterator begin() const
T binaryOperate(Instruction::InstID ID, const T &lhs, const T &rhs)
function wrapper for BinaryOperation
CONSTInst * foldCASTInst(CASTInst *inst)
void propagate(Instruction *inst)
static PassRegistry< BasicBlockSchedulingPass > X("BasicBlockSchedulingPass")
void replace_by_constant(Instruction *isnt, CONSTInst *c, Method *M)
void add_requires()
PassName is required.