- }
- return Modified;
-}
-
-inline static bool
-ConstantFoldUnaryInst(Method *M, Method::inst_iterator &DI,
- UnaryOperator *Op, ConstPoolVal *D) {
- ConstPoolVal *ReplaceWith =
- ConstantFoldUnaryInstruction(Op->getInstType(), D);
-
- if (!ReplaceWith) return false; // Nothing new to change...
-
-
- // Add the new value to the constant pool...
- M->getConstantPool().insert(ReplaceWith);
-
- // Replaces all of the uses of a variable with uses of the constant.
- Op->replaceAllUsesWith(ReplaceWith);
-
- // Remove the operator from the list of definitions...
- Op->getParent()->getInstList().remove(DI.getInstructionIterator());
-
- // The new constant inherits the old name of the operator...
- if (Op->hasName()) ReplaceWith->setName(Op->getName());
-
- // Delete the operator now...
- delete Op;
- return true;
-}
-
-inline static bool
-ConstantFoldBinaryInst(Method *M, Method::inst_iterator &DI,
- BinaryOperator *Op,
- ConstPoolVal *D1, ConstPoolVal *D2) {
- ConstPoolVal *ReplaceWith =
- ConstantFoldBinaryInstruction(Op->getInstType(), D1, D2);
- if (!ReplaceWith) return false; // Nothing new to change...
-
- // Add the new value to the constant pool...
- M->getConstantPool().insert(ReplaceWith);
-
- // Replaces all of the uses of a variable with uses of the constant.
- Op->replaceAllUsesWith(ReplaceWith);
-
- // Remove the operator from the list of definitions...
- Op->getParent()->getInstList().remove(DI.getInstructionIterator());
-
- // The new constant inherits the old name of the operator...
- if (Op->hasName()) ReplaceWith->setName(Op->getName());
-
- // Delete the operator now...
- delete Op;
- return true;
-}