class VISIBILITY_HIDDEN JumpThreading : public FunctionPass {
public:
static char ID; // Pass identification
- JumpThreading() : FunctionPass((intptr_t)&ID) {}
+ JumpThreading() : FunctionPass(&ID) {}
bool runOnFunction(Function &F);
bool ThreadBlock(BasicBlock *BB);
bool ProcessBranchOnLogical(Value *V, BasicBlock *BB, bool isAnd);
bool ProcessBranchOnCompare(CmpInst *Cmp, BasicBlock *BB);
};
- char JumpThreading::ID = 0;
- RegisterPass<JumpThreading> X("jump-threading", "Jump Threading");
}
+char JumpThreading::ID = 0;
+static RegisterPass<JumpThreading>
+X("jump-threading", "Jump Threading");
+
// Public interface to the Jump Threading pass
FunctionPass *llvm::createJumpThreadingPass() { return new JumpThreading(); }
/// getJumpThreadDuplicationCost - Return the cost of duplicating this block to
/// thread across it.
static unsigned getJumpThreadDuplicationCost(const BasicBlock *BB) {
- BasicBlock::const_iterator I = BB->begin();
/// Ignore PHI nodes, these will be flattened when duplication happens.
- while (isa<PHINode>(*I)) ++I;
+ BasicBlock::const_iterator I = BB->getFirstNonPHI();
// Sum up the cost of each instruction until we get to the terminator. Don't
// include the terminator because the copy won't include it.
/// ThreadBlock - If there are any predecessors whose control can be threaded
/// through to a successor, transform them now.
bool JumpThreading::ThreadBlock(BasicBlock *BB) {
- // See if this block ends with a branch of switch. If so, see if the
+ // See if this block ends with a branch or switch. If so, see if the
// condition is a phi node. If so, and if an entry of the phi node is a
// constant, we can thread the block.
Value *Condition;
// If this is a binary operator tree of the same AND/OR opcode, check the
// LHS/RHS.
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(V))
- if (isAnd && BO->getOpcode() == Instruction::And ||
- !isAnd && BO->getOpcode() == Instruction::Or) {
+ if ((isAnd && BO->getOpcode() == Instruction::And) ||
+ (!isAnd && BO->getOpcode() == Instruction::Or)) {
if (ProcessBranchOnLogical(BO->getOperand(0), BB, isAnd))
return true;
if (ProcessBranchOnLogical(BO->getOperand(1), BB, isAnd))
// We found a use of I outside of BB. Create a new stack slot to
// break this inter-block usage pattern.
- if (!isa<StructType>(I->getType())) {
- DemoteRegToStack(*I);
- continue;
- }
-
- // Alternatively, I must be a call or invoke that returns multiple retvals.
- // We can't use 'DemoteRegToStack' because that will create loads and
- // stores of aggregates which is not valid yet. If I is a call, we can just
- // pull all the getresult instructions up to this block. If I is an invoke,
- // we are out of luck.
- BasicBlock::iterator IP = I; ++IP;
- for (Value::use_iterator UI = I->use_begin(), E = I->use_end();
- UI != E; ++UI)
- cast<GetResultInst>(UI)->moveBefore(IP);
+ DemoteRegToStack(*I);
}
// We are going to have to map operands from the original BB block to the new