InsertPos->getParent()->getInstList().insert(InsertPos, this);
}
+/// insertAfter - Insert an unlinked instructions into a basic block
+/// immediately after the specified instruction.
+void Instruction::insertAfter(Instruction *InsertPos) {
+ InsertPos->getParent()->getInstList().insertAfter(InsertPos, this);
+}
+
/// moveBefore - Unlink this instruction from its current basic block and
/// insert it into the basic block that MovePos lives in, right before
/// MovePos.
// Standard binary operators...
case Add: return "add";
+ case FAdd: return "fadd";
case Sub: return "sub";
+ case FSub: return "fsub";
case Mul: return "mul";
+ case FMul: return "fmul";
case UDiv: return "udiv";
case SDiv: return "sdiv";
case FDiv: return "fdiv";
/// isIdenticalTo - Return true if the specified instruction is exactly
/// identical to the current one. This means that all operands match and any
/// extra information (e.g. load is volatile) agree.
-bool Instruction::isIdenticalTo(Instruction *I) const {
+bool Instruction::isIdenticalTo(const Instruction *I) const {
if (getOpcode() != I->getOpcode() ||
getNumOperands() != I->getNumOperands() ||
getType() != I->getType())
CI->getAttributes().getRawPointer() ==
cast<CallInst>(I)->getAttributes().getRawPointer();
if (const InvokeInst *CI = dyn_cast<InvokeInst>(this))
- return CI->getCallingConv() == cast<CallInst>(I)->getCallingConv() &&
+ return CI->getCallingConv() == cast<InvokeInst>(I)->getCallingConv() &&
CI->getAttributes().getRawPointer() ==
- cast<CallInst>(I)->getAttributes().getRawPointer();
+ cast<InvokeInst>(I)->getAttributes().getRawPointer();
if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(this)) {
if (IVI->getNumIndices() != cast<InsertValueInst>(I)->getNumIndices())
return false;
}
// isSameOperationAs
-bool Instruction::isSameOperationAs(Instruction *I) const {
- if (getOpcode() != I->getOpcode() || getType() != I->getType() ||
- getNumOperands() != I->getNumOperands())
+// This should be kept in sync with isEquivalentOperation in
+// lib/Transforms/IPO/MergeFunctions.cpp.
+bool Instruction::isSameOperationAs(const Instruction *I) const {
+ if (getOpcode() != I->getOpcode() ||
+ getNumOperands() != I->getNumOperands() ||
+ getType() != I->getType())
return false;
// We have two instructions of identical opcode and #operands. Check to see
CI->getAttributes().getRawPointer() ==
cast<CallInst>(I)->getAttributes().getRawPointer();
if (const InvokeInst *CI = dyn_cast<InvokeInst>(this))
- return CI->getCallingConv() == cast<CallInst>(I)->getCallingConv() &&
+ return CI->getCallingConv() == cast<InvokeInst>(I)->getCallingConv() &&
CI->getAttributes().getRawPointer() ==
- cast<CallInst>(I)->getAttributes().getRawPointer();
+ cast<InvokeInst>(I)->getAttributes().getRawPointer();
if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(this)) {
if (IVI->getNumIndices() != cast<InsertValueInst>(I)->getNumIndices())
return false;
continue;
}
- unsigned UseOperand = UI.getOperandNo();
- if (PN->getIncomingBlock(UseOperand/2) != BB)
+ if (PN->getIncomingBlock(UI) != BB)
return true;
}
return false;
}
}
+/// mayThrow - Return true if this instruction may throw an exception.
+///
+bool Instruction::mayThrow() const {
+ if (const CallInst *CI = dyn_cast<CallInst>(this))
+ return !CI->doesNotThrow();
+ return false;
+}
+
/// isAssociative - Return true if the instruction is associative:
///
-/// Associative operators satisfy: x op (y op z) === (x op y) op z)
+/// Associative operators satisfy: x op (y op z) === (x op y) op z
///
-/// In LLVM, the Add, Mul, And, Or, and Xor operators are associative, when not
-/// applied to floating point types.
+/// In LLVM, the Add, Mul, And, Or, and Xor operators are associative.
///
bool Instruction::isAssociative(unsigned Opcode, const Type *Ty) {
- if (Opcode == And || Opcode == Or || Opcode == Xor)
- return true;
-
- // Add/Mul reassociate unless they are FP or FP vectors.
- if (Opcode == Add || Opcode == Mul)
- return !Ty->isFPOrFPVector();
- return 0;
+ return Opcode == And || Opcode == Or || Opcode == Xor ||
+ Opcode == Add || Opcode == Mul;
}
/// isCommutative - Return true if the instruction is commutative:
bool Instruction::isCommutative(unsigned op) {
switch (op) {
case Add:
+ case FAdd:
case Mul:
+ case FMul:
case And:
case Or:
case Xor: