Fixed whitespace.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172271 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael Gottesman 2013-01-11 23:08:52 +00:00
parent 66de2af815
commit dcf669560e

View File

@ -448,8 +448,8 @@ static bool CleanupPointerRootUsers(GlobalVariable *GV,
Dead[i].second->eraseFromParent(); Dead[i].second->eraseFromParent();
Instruction *I = Dead[i].first; Instruction *I = Dead[i].first;
do { do {
if (isAllocationFn(I, TLI)) if (isAllocationFn(I, TLI))
break; break;
Instruction *J = dyn_cast<Instruction>(I->getOperand(0)); Instruction *J = dyn_cast<Instruction>(I->getOperand(0));
if (!J) if (!J)
break; break;
@ -2589,18 +2589,18 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
if (StoreInst *SI = dyn_cast<StoreInst>(CurInst)) { if (StoreInst *SI = dyn_cast<StoreInst>(CurInst)) {
if (!SI->isSimple()) { if (!SI->isSimple()) {
DEBUG(dbgs() << "Store is not simple! Can not evaluate.\n"); DEBUG(dbgs() << "Store is not simple! Can not evaluate.\n");
return false; // no volatile/atomic accesses. return false; // no volatile/atomic accesses.
} }
Constant *Ptr = getVal(SI->getOperand(1)); Constant *Ptr = getVal(SI->getOperand(1));
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ptr)) { if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ptr)) {
DEBUG(dbgs() << "Folding constant ptr expression: " << *Ptr); DEBUG(dbgs() << "Folding constant ptr expression: " << *Ptr);
Ptr = ConstantFoldConstantExpression(CE, TD, TLI); Ptr = ConstantFoldConstantExpression(CE, TD, TLI);
DEBUG(dbgs() << "; To: " << *Ptr << "\n"); DEBUG(dbgs() << "; To: " << *Ptr << "\n");
} }
if (!isSimpleEnoughPointerToCommit(Ptr)) { if (!isSimpleEnoughPointerToCommit(Ptr)) {
// If this is too complex for us to commit, reject it. // If this is too complex for us to commit, reject it.
DEBUG(dbgs() << "Pointer is too complex for us to evaluate store."); DEBUG(dbgs() << "Pointer is too complex for us to evaluate store.");
return false; return false;
} }
@ -2609,14 +2609,14 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
// If this might be too difficult for the backend to handle (e.g. the addr // If this might be too difficult for the backend to handle (e.g. the addr
// of one global variable divided by another) then we can't commit it. // of one global variable divided by another) then we can't commit it.
if (!isSimpleEnoughValueToCommit(Val, SimpleConstants, TD)) { if (!isSimpleEnoughValueToCommit(Val, SimpleConstants, TD)) {
DEBUG(dbgs() << "Store value is too complex to evaluate store. " << *Val DEBUG(dbgs() << "Store value is too complex to evaluate store. " << *Val
<< "\n"); << "\n");
return false; return false;
} }
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ptr)) { if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ptr)) {
if (CE->getOpcode() == Instruction::BitCast) { if (CE->getOpcode() == Instruction::BitCast) {
DEBUG(dbgs() << "Attempting to resolve bitcast on constant ptr.\n"); DEBUG(dbgs() << "Attempting to resolve bitcast on constant ptr.\n");
// If we're evaluating a store through a bitcast, then we need // If we're evaluating a store through a bitcast, then we need
// to pull the bitcast off the pointer type and push it onto the // to pull the bitcast off the pointer type and push it onto the
// stored value. // stored value.
@ -2645,8 +2645,8 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
// If we can't improve the situation by introspecting NewTy, // If we can't improve the situation by introspecting NewTy,
// we have to give up. // we have to give up.
} else { } else {
DEBUG(dbgs() << "Failed to bitcast constant ptr, can not " DEBUG(dbgs() << "Failed to bitcast constant ptr, can not "
"evaluate.\n"); "evaluate.\n");
return false; return false;
} }
} }
@ -2655,7 +2655,7 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
// onto the stored value. // onto the stored value.
Val = ConstantExpr::getBitCast(Val, NewTy); Val = ConstantExpr::getBitCast(Val, NewTy);
DEBUG(dbgs() << "Evaluated bitcast: " << *Val << "\n"); DEBUG(dbgs() << "Evaluated bitcast: " << *Val << "\n");
} }
} }
@ -2665,25 +2665,25 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
getVal(BO->getOperand(0)), getVal(BO->getOperand(0)),
getVal(BO->getOperand(1))); getVal(BO->getOperand(1)));
DEBUG(dbgs() << "Found a BinaryOperator! Simplifying: " << *InstResult DEBUG(dbgs() << "Found a BinaryOperator! Simplifying: " << *InstResult
<< "\n"); << "\n");
} else if (CmpInst *CI = dyn_cast<CmpInst>(CurInst)) { } else if (CmpInst *CI = dyn_cast<CmpInst>(CurInst)) {
InstResult = ConstantExpr::getCompare(CI->getPredicate(), InstResult = ConstantExpr::getCompare(CI->getPredicate(),
getVal(CI->getOperand(0)), getVal(CI->getOperand(0)),
getVal(CI->getOperand(1))); getVal(CI->getOperand(1)));
DEBUG(dbgs() << "Found a CmpInst! Simplifying: " << *InstResult DEBUG(dbgs() << "Found a CmpInst! Simplifying: " << *InstResult
<< "\n"); << "\n");
} else if (CastInst *CI = dyn_cast<CastInst>(CurInst)) { } else if (CastInst *CI = dyn_cast<CastInst>(CurInst)) {
InstResult = ConstantExpr::getCast(CI->getOpcode(), InstResult = ConstantExpr::getCast(CI->getOpcode(),
getVal(CI->getOperand(0)), getVal(CI->getOperand(0)),
CI->getType()); CI->getType());
DEBUG(dbgs() << "Found a Cast! Simplifying: " << *InstResult DEBUG(dbgs() << "Found a Cast! Simplifying: " << *InstResult
<< "\n"); << "\n");
} else if (SelectInst *SI = dyn_cast<SelectInst>(CurInst)) { } else if (SelectInst *SI = dyn_cast<SelectInst>(CurInst)) {
InstResult = ConstantExpr::getSelect(getVal(SI->getOperand(0)), InstResult = ConstantExpr::getSelect(getVal(SI->getOperand(0)),
getVal(SI->getOperand(1)), getVal(SI->getOperand(1)),
getVal(SI->getOperand(2))); getVal(SI->getOperand(2)));
DEBUG(dbgs() << "Found a Select! Simplifying: " << *InstResult DEBUG(dbgs() << "Found a Select! Simplifying: " << *InstResult
<< "\n"); << "\n");
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(CurInst)) { } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(CurInst)) {
Constant *P = getVal(GEP->getOperand(0)); Constant *P = getVal(GEP->getOperand(0));
SmallVector<Constant*, 8> GEPOps; SmallVector<Constant*, 8> GEPOps;
@ -2694,32 +2694,32 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
ConstantExpr::getGetElementPtr(P, GEPOps, ConstantExpr::getGetElementPtr(P, GEPOps,
cast<GEPOperator>(GEP)->isInBounds()); cast<GEPOperator>(GEP)->isInBounds());
DEBUG(dbgs() << "Found a GEP! Simplifying: " << *InstResult DEBUG(dbgs() << "Found a GEP! Simplifying: " << *InstResult
<< "\n"); << "\n");
} else if (LoadInst *LI = dyn_cast<LoadInst>(CurInst)) { } else if (LoadInst *LI = dyn_cast<LoadInst>(CurInst)) {
if (!LI->isSimple()) { if (!LI->isSimple()) {
DEBUG(dbgs() << "Found a Load! Not a simple load, can not evaluate.\n"); DEBUG(dbgs() << "Found a Load! Not a simple load, can not evaluate.\n");
return false; // no volatile/atomic accesses. return false; // no volatile/atomic accesses.
} }
Constant *Ptr = getVal(LI->getOperand(0)); Constant *Ptr = getVal(LI->getOperand(0));
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ptr)) { if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ptr)) {
Ptr = ConstantFoldConstantExpression(CE, TD, TLI); Ptr = ConstantFoldConstantExpression(CE, TD, TLI);
DEBUG(dbgs() << "Found a constant pointer expression, constant " DEBUG(dbgs() << "Found a constant pointer expression, constant "
"folding: " << *Ptr << "\n"); "folding: " << *Ptr << "\n");
} }
InstResult = ComputeLoadResult(Ptr); InstResult = ComputeLoadResult(Ptr);
if (InstResult == 0) { if (InstResult == 0) {
DEBUG(dbgs() << "Failed to compute load result. Can not evaluate load." DEBUG(dbgs() << "Failed to compute load result. Can not evaluate load."
"\n"); "\n");
return false; // Could not evaluate load. return false; // Could not evaluate load.
} }
DEBUG(dbgs() << "Evaluated load: " << *InstResult << "\n"); DEBUG(dbgs() << "Evaluated load: " << *InstResult << "\n");
} else if (AllocaInst *AI = dyn_cast<AllocaInst>(CurInst)) { } else if (AllocaInst *AI = dyn_cast<AllocaInst>(CurInst)) {
if (AI->isArrayAllocation()) { if (AI->isArrayAllocation()) {
DEBUG(dbgs() << "Found an array alloca. Can not evaluate.\n"); DEBUG(dbgs() << "Found an array alloca. Can not evaluate.\n");
return false; // Cannot handle array allocs. return false; // Cannot handle array allocs.
} }
Type *Ty = AI->getType()->getElementType(); Type *Ty = AI->getType()->getElementType();
AllocaTmps.push_back(new GlobalVariable(Ty, false, AllocaTmps.push_back(new GlobalVariable(Ty, false,
@ -2733,30 +2733,30 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
// Debug info can safely be ignored here. // Debug info can safely be ignored here.
if (isa<DbgInfoIntrinsic>(CS.getInstruction())) { if (isa<DbgInfoIntrinsic>(CS.getInstruction())) {
DEBUG(dbgs() << "Ignoring debug info.\n"); DEBUG(dbgs() << "Ignoring debug info.\n");
++CurInst; ++CurInst;
continue; continue;
} }
// Cannot handle inline asm. // Cannot handle inline asm.
if (isa<InlineAsm>(CS.getCalledValue())) { if (isa<InlineAsm>(CS.getCalledValue())) {
DEBUG(dbgs() << "Found inline asm, can not evaluate.\n"); DEBUG(dbgs() << "Found inline asm, can not evaluate.\n");
return false; return false;
} }
if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(CS.getInstruction())) { if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(CS.getInstruction())) {
if (MemSetInst *MSI = dyn_cast<MemSetInst>(II)) { if (MemSetInst *MSI = dyn_cast<MemSetInst>(II)) {
if (MSI->isVolatile()) { if (MSI->isVolatile()) {
DEBUG(dbgs() << "Can not optimize a volatile memset " << DEBUG(dbgs() << "Can not optimize a volatile memset " <<
"intrinsic.\n"); "intrinsic.\n");
return false; return false;
} }
Constant *Ptr = getVal(MSI->getDest()); Constant *Ptr = getVal(MSI->getDest());
Constant *Val = getVal(MSI->getValue()); Constant *Val = getVal(MSI->getValue());
Constant *DestVal = ComputeLoadResult(getVal(Ptr)); Constant *DestVal = ComputeLoadResult(getVal(Ptr));
if (Val->isNullValue() && DestVal && DestVal->isNullValue()) { if (Val->isNullValue() && DestVal && DestVal->isNullValue()) {
// This memset is a no-op. // This memset is a no-op.
DEBUG(dbgs() << "Ignoring no-op memset.\n"); DEBUG(dbgs() << "Ignoring no-op memset.\n");
++CurInst; ++CurInst;
continue; continue;
} }
@ -2764,7 +2764,7 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
if (II->getIntrinsicID() == Intrinsic::lifetime_start || if (II->getIntrinsicID() == Intrinsic::lifetime_start ||
II->getIntrinsicID() == Intrinsic::lifetime_end) { II->getIntrinsicID() == Intrinsic::lifetime_end) {
DEBUG(dbgs() << "Ignoring lifetime intrinsic.\n"); DEBUG(dbgs() << "Ignoring lifetime intrinsic.\n");
++CurInst; ++CurInst;
continue; continue;
} }
@ -2773,9 +2773,9 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
// We don't insert an entry into Values, as it doesn't have a // We don't insert an entry into Values, as it doesn't have a
// meaningful return value. // meaningful return value.
if (!II->use_empty()) { if (!II->use_empty()) {
DEBUG(dbgs() << "Found unused invariant_start. Cant evaluate.\n"); DEBUG(dbgs() << "Found unused invariant_start. Cant evaluate.\n");
return false; return false;
} }
ConstantInt *Size = cast<ConstantInt>(II->getArgOperand(0)); ConstantInt *Size = cast<ConstantInt>(II->getArgOperand(0));
Value *PtrArg = getVal(II->getArgOperand(1)); Value *PtrArg = getVal(II->getArgOperand(1));
Value *Ptr = PtrArg->stripPointerCasts(); Value *Ptr = PtrArg->stripPointerCasts();
@ -2785,26 +2785,26 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
Size->getValue().getLimitedValue() >= Size->getValue().getLimitedValue() >=
TD->getTypeStoreSize(ElemTy)) { TD->getTypeStoreSize(ElemTy)) {
Invariants.insert(GV); Invariants.insert(GV);
DEBUG(dbgs() << "Found a global var that is an invariant: " << *GV DEBUG(dbgs() << "Found a global var that is an invariant: " << *GV
<< "\n"); << "\n");
} else { } else {
DEBUG(dbgs() << "Found a global var, but can not treat it as an " DEBUG(dbgs() << "Found a global var, but can not treat it as an "
"invariant.\n"); "invariant.\n");
} }
} }
// Continue even if we do nothing. // Continue even if we do nothing.
++CurInst; ++CurInst;
continue; continue;
} }
DEBUG(dbgs() << "Unknown intrinsic. Can not evaluate.\n"); DEBUG(dbgs() << "Unknown intrinsic. Can not evaluate.\n");
return false; return false;
} }
// Resolve function pointers. // Resolve function pointers.
Function *Callee = dyn_cast<Function>(getVal(CS.getCalledValue())); Function *Callee = dyn_cast<Function>(getVal(CS.getCalledValue()));
if (!Callee || Callee->mayBeOverridden()) { if (!Callee || Callee->mayBeOverridden()) {
DEBUG(dbgs() << "Can not resolve function pointer.\n"); DEBUG(dbgs() << "Can not resolve function pointer.\n");
return false; // Cannot resolve. return false; // Cannot resolve.
} }
@ -2816,34 +2816,34 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
// If this is a function we can constant fold, do it. // If this is a function we can constant fold, do it.
if (Constant *C = ConstantFoldCall(Callee, Formals, TLI)) { if (Constant *C = ConstantFoldCall(Callee, Formals, TLI)) {
InstResult = C; InstResult = C;
DEBUG(dbgs() << "Constant folded function call. Result: " << DEBUG(dbgs() << "Constant folded function call. Result: " <<
*InstResult << "\n"); *InstResult << "\n");
} else { } else {
DEBUG(dbgs() << "Can not constant fold function call.\n"); DEBUG(dbgs() << "Can not constant fold function call.\n");
return false; return false;
} }
} else { } else {
if (Callee->getFunctionType()->isVarArg()) { if (Callee->getFunctionType()->isVarArg()) {
DEBUG(dbgs() << "Can not constant fold vararg function call.\n"); DEBUG(dbgs() << "Can not constant fold vararg function call.\n");
return false; return false;
} }
Constant *RetVal; Constant *RetVal;
// Execute the call, if successful, use the return value. // Execute the call, if successful, use the return value.
ValueStack.push_back(new DenseMap<Value*, Constant*>); ValueStack.push_back(new DenseMap<Value*, Constant*>);
if (!EvaluateFunction(Callee, RetVal, Formals)) { if (!EvaluateFunction(Callee, RetVal, Formals)) {
DEBUG(dbgs() << "Failed to evaluate function.\n"); DEBUG(dbgs() << "Failed to evaluate function.\n");
return false; return false;
} }
delete ValueStack.pop_back_val(); delete ValueStack.pop_back_val();
InstResult = RetVal; InstResult = RetVal;
if (InstResult != NULL) { if (InstResult != NULL) {
DEBUG(dbgs() << "Successfully evaluated function. Result: " << DEBUG(dbgs() << "Successfully evaluated function. Result: " <<
InstResult << "\n\n"); InstResult << "\n\n");
} else { } else {
DEBUG(dbgs() << "Successfully evaluated function. Result: 0\n\n"); DEBUG(dbgs() << "Successfully evaluated function. Result: 0\n\n");
} }
} }
} else if (isa<TerminatorInst>(CurInst)) { } else if (isa<TerminatorInst>(CurInst)) {
DEBUG(dbgs() << "Found a terminator instruction.\n"); DEBUG(dbgs() << "Found a terminator instruction.\n");
@ -2873,7 +2873,7 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
NextBB = 0; NextBB = 0;
} else { } else {
// invoke, unwind, resume, unreachable. // invoke, unwind, resume, unreachable.
DEBUG(dbgs() << "Can not handle terminator."); DEBUG(dbgs() << "Can not handle terminator.");
return false; // Cannot handle this terminator. return false; // Cannot handle this terminator.
} }
@ -2883,7 +2883,7 @@ bool Evaluator::EvaluateBlock(BasicBlock::iterator CurInst,
} else { } else {
// Did not know how to evaluate this! // Did not know how to evaluate this!
DEBUG(dbgs() << "Failed to evaluate block due to unhandled instruction." DEBUG(dbgs() << "Failed to evaluate block due to unhandled instruction."
"\n"); "\n");
return false; return false;
} }