diff options
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/IPO/GlobalOpt.cpp | 28 | ||||
-rw-r--r-- | lib/Transforms/Scalar/CodeGenPrepare.cpp | 6 | ||||
-rw-r--r-- | lib/Transforms/Scalar/IndVarSimplify.cpp | 23 | ||||
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 27 | ||||
-rw-r--r-- | lib/Transforms/Scalar/LICM.cpp | 4 | ||||
-rw-r--r-- | lib/Transforms/Scalar/LoopStrengthReduce.cpp | 60 | ||||
-rw-r--r-- | lib/Transforms/Scalar/LoopUnswitch.cpp | 8 | ||||
-rw-r--r-- | lib/Transforms/Scalar/MemCpyOptimizer.cpp | 7 | ||||
-rw-r--r-- | lib/Transforms/Scalar/PredicateSimplifier.cpp | 38 | ||||
-rw-r--r-- | lib/Transforms/Scalar/Reassociate.cpp | 27 | ||||
-rw-r--r-- | lib/Transforms/Scalar/SCCP.cpp | 4 | ||||
-rw-r--r-- | lib/Transforms/Scalar/ScalarReplAggregates.cpp | 24 | ||||
-rw-r--r-- | lib/Transforms/Scalar/TailDuplication.cpp | 2 | ||||
-rw-r--r-- | lib/Transforms/Utils/BasicInliner.cpp | 20 | ||||
-rw-r--r-- | lib/Transforms/Utils/CodeExtractor.cpp | 15 | ||||
-rw-r--r-- | lib/Transforms/Utils/SimplifyCFG.cpp | 41 | ||||
-rw-r--r-- | lib/Transforms/Utils/UnrollLoop.cpp | 15 |
17 files changed, 180 insertions, 169 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index f218c12914..4deb3f4d6a 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -552,7 +552,7 @@ static GlobalVariable *SRAGlobal(GlobalVariable *GV, const TargetData &TD, if (NewGlobals.empty()) return 0; - DOUT << "PERFORMING GLOBAL SRA ON: " << *GV; + DEBUG(errs() << "PERFORMING GLOBAL SRA ON: " << *GV); Constant *NullInt = Constant::getNullValue(Type::getInt32Ty(Context)); @@ -781,14 +781,14 @@ static bool OptimizeAwayTrappingUsesOfLoads(GlobalVariable *GV, Constant *LV, } if (Changed) { - DOUT << "OPTIMIZED LOADS FROM STORED ONCE POINTER: " << *GV; + DEBUG(errs() << "OPTIMIZED LOADS FROM STORED ONCE POINTER: " << *GV); ++NumGlobUses; } // If we nuked all of the loads, then none of the stores are needed either, // nor is the global. if (AllNonStoreUsesGone) { - DOUT << " *** GLOBAL NOW DEAD!\n"; + DEBUG(errs() << " *** GLOBAL NOW DEAD!\n"); CleanupConstantGlobalUsers(GV, 0, Context); if (GV->use_empty()) { GV->eraseFromParent(); @@ -823,7 +823,7 @@ static void ConstantPropUsersOf(Value *V, LLVMContext &Context) { static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, MallocInst *MI, LLVMContext &Context) { - DOUT << "PROMOTING MALLOC GLOBAL: " << *GV << " MALLOC = " << *MI; + DEBUG(errs() << "PROMOTING MALLOC GLOBAL: " << *GV << " MALLOC = " << *MI); ConstantInt *NElements = cast<ConstantInt>(MI->getArraySize()); if (NElements->getZExtValue() != 1) { @@ -1269,7 +1269,7 @@ static void RewriteUsesOfLoadForHeapSRoA(LoadInst *Load, /// it up into multiple allocations of arrays of the fields. static GlobalVariable *PerformHeapAllocSRoA(GlobalVariable *GV, MallocInst *MI, LLVMContext &Context){ - DOUT << "SROA HEAP ALLOC: " << *GV << " MALLOC = " << *MI; + DEBUG(errs() << "SROA HEAP ALLOC: " << *GV << " MALLOC = " << *MI); const StructType *STy = cast<StructType>(MI->getAllocatedType()); // There is guaranteed to be at least one use of the malloc (storing @@ -1587,7 +1587,7 @@ static bool TryToShrinkGlobalToBoolean(GlobalVariable *GV, Constant *OtherVal, if (!isa<LoadInst>(I) && !isa<StoreInst>(I)) return false; - DOUT << " *** SHRINKING TO BOOL: " << *GV; + DEBUG(errs() << " *** SHRINKING TO BOOL: " << *GV); // Create the new global, initializing it to false. GlobalVariable *NewGV = new GlobalVariable(Context, @@ -1666,7 +1666,7 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV, GV->removeDeadConstantUsers(); if (GV->use_empty()) { - DOUT << "GLOBAL DEAD: " << *GV; + DEBUG(errs() << "GLOBAL DEAD: " << *GV); GV->eraseFromParent(); ++NumDeleted; return true; @@ -1709,7 +1709,7 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV, GS.AccessingFunction->getName() == "main" && GS.AccessingFunction->hasExternalLinkage() && GV->getType()->getAddressSpace() == 0) { - DOUT << "LOCALIZING GLOBAL: " << *GV; + DEBUG(errs() << "LOCALIZING GLOBAL: " << *GV); Instruction* FirstI = GS.AccessingFunction->getEntryBlock().begin(); const Type* ElemTy = GV->getType()->getElementType(); // FIXME: Pass Global's alignment when globals have alignment @@ -1726,7 +1726,7 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV, // If the global is never loaded (but may be stored to), it is dead. // Delete it now. if (!GS.isLoaded) { - DOUT << "GLOBAL NEVER LOADED: " << *GV; + DEBUG(errs() << "GLOBAL NEVER LOADED: " << *GV); // Delete any stores we can find to the global. We may not be able to // make it completely dead though. @@ -1742,7 +1742,7 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV, return Changed; } else if (GS.StoredType <= GlobalStatus::isInitializerStored) { - DOUT << "MARKING CONSTANT: " << *GV; + DEBUG(errs() << "MARKING CONSTANT: " << *GV); GV->setConstant(true); // Clean up any obviously simplifiable users now. @@ -1750,8 +1750,8 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV, // If the global is dead now, just nuke it. if (GV->use_empty()) { - DOUT << " *** Marking constant allowed us to simplify " - << "all users and delete global!\n"; + DEBUG(errs() << " *** Marking constant allowed us to simplify " + << "all users and delete global!\n"); GV->eraseFromParent(); ++NumDeleted; } @@ -1780,8 +1780,8 @@ bool GlobalOpt::ProcessInternalGlobal(GlobalVariable *GV, GV->getContext()); if (GV->use_empty()) { - DOUT << " *** Substituting initializer allowed us to " - << "simplify all users and delete global!\n"; + DEBUG(errs() << " *** Substituting initializer allowed us to " + << "simplify all users and delete global!\n"); GV->eraseFromParent(); ++NumDeleted; } else { diff --git a/lib/Transforms/Scalar/CodeGenPrepare.cpp b/lib/Transforms/Scalar/CodeGenPrepare.cpp index 9a59dca412..db6d819b05 100644 --- a/lib/Transforms/Scalar/CodeGenPrepare.cpp +++ b/lib/Transforms/Scalar/CodeGenPrepare.cpp @@ -231,7 +231,7 @@ void CodeGenPrepare::EliminateMostlyEmptyBlock(BasicBlock *BB) { BranchInst *BI = cast<BranchInst>(BB->getTerminator()); BasicBlock *DestBB = BI->getSuccessor(0); - DOUT << "MERGING MOSTLY EMPTY BLOCKS - BEFORE:\n" << *BB << *DestBB; + DEBUG(errs() << "MERGING MOSTLY EMPTY BLOCKS - BEFORE:\n" << *BB << *DestBB); // If the destination block has a single pred, then this is a trivial edge, // just collapse it. @@ -245,7 +245,7 @@ void CodeGenPrepare::EliminateMostlyEmptyBlock(BasicBlock *BB) { if (isEntry && BB != &BB->getParent()->getEntryBlock()) BB->moveBefore(&BB->getParent()->getEntryBlock()); - DOUT << "AFTER:\n" << *DestBB << "\n\n\n"; + DEBUG(errs() << "AFTER:\n" << *DestBB << "\n\n\n"); return; } } @@ -284,7 +284,7 @@ void CodeGenPrepare::EliminateMostlyEmptyBlock(BasicBlock *BB) { BB->replaceAllUsesWith(DestBB); BB->eraseFromParent(); - DOUT << "AFTER:\n" << *DestBB << "\n\n\n"; + DEBUG(errs() << "AFTER:\n" << *DestBB << "\n\n\n"); } diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index b480a372a9..790a4fc51d 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -52,10 +52,11 @@ #include "llvm/Analysis/LoopPass.h" #include "llvm/Support/CFG.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" -#include "llvm/Support/CommandLine.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/STLExtras.h" @@ -182,11 +183,11 @@ ICmpInst *IndVarSimplify::LinearFunctionTestReplace(Loop *L, else Opcode = ICmpInst::ICMP_EQ; - DOUT << "INDVARS: Rewriting loop exit condition to:\n" - << " LHS:" << *CmpIndVar << '\n' - << " op:\t" - << (Opcode == ICmpInst::ICMP_NE ? "!=" : "==") << "\n" - << " RHS:\t" << *RHS << "\n"; + DEBUG(errs() << "INDVARS: Rewriting loop exit condition to:\n" + << " LHS:" << *CmpIndVar << '\n' + << " op:\t" + << (Opcode == ICmpInst::ICMP_NE ? "!=" : "==") << "\n" + << " RHS:\t" << *RHS << "\n"); ICmpInst *Cond = new ICmpInst(BI, Opcode, CmpIndVar, ExitCnt, "exitcond"); @@ -273,8 +274,8 @@ void IndVarSimplify::RewriteLoopExitValues(Loop *L, Value *ExitVal = Rewriter.expandCodeFor(ExitValue, PN->getType(), Inst); - DOUT << "INDVARS: RLEV: AfterLoopVal = " << *ExitVal << '\n' - << " LoopVal = " << *Inst << "\n"; + DEBUG(errs() << "INDVARS: RLEV: AfterLoopVal = " << *ExitVal << '\n' + << " LoopVal = " << *Inst << "\n"); PN->setIncomingValue(i, ExitVal); @@ -401,7 +402,7 @@ bool IndVarSimplify::runOnLoop(Loop *L, LPPassManager &LPM) { ++NumInserted; Changed = true; - DOUT << "INDVARS: New CanIV: " << *IndVar << '\n'; + DEBUG(errs() << "INDVARS: New CanIV: " << *IndVar << '\n'); // Now that the official induction variable is established, reinsert // the old canonical-looking variable after it so that the IR remains @@ -506,8 +507,8 @@ void IndVarSimplify::RewriteIVExpressions(Loop *L, const Type *LargestType, NewVal->takeName(Op); User->replaceUsesOfWith(Op, NewVal); UI->setOperandValToReplace(NewVal); - DOUT << "INDVARS: Rewrote IV '" << *AR << "' " << *Op << '\n' - << " into = " << *NewVal << "\n"; + DEBUG(errs() << "INDVARS: Rewrote IV '" << *AR << "' " << *Op << '\n' + << " into = " << *NewVal << "\n"); ++NumRemoved; Changed = true; diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index cd901c0b14..6dd2641ad4 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -7831,7 +7831,7 @@ Instruction *InstCombiner::PromoteCastOfAllocation(BitCastInst &CI, ++UI; // If this instruction uses AI more than once, don't break UI. ++NumDeadInst; - DOUT << "IC: DCE: " << *User << '\n'; + DEBUG(errs() << "IC: DCE: " << *User << '\n'); EraseInstFromFunction(*User); } } @@ -8387,8 +8387,8 @@ Instruction *InstCombiner::commonIntCastTransforms(CastInst &CI) { } if (DoXForm) { - DOUT << "ICE: EvaluateInDifferentType converting expression type to avoid" - << " cast: " << CI; + DEBUG(errs() << "ICE: EvaluateInDifferentType converting expression type" + " to avoid cast: " << CI); Value *Res = EvaluateInDifferentType(SrcI, DestTy, CI.getOpcode() == Instruction::SExt); if (JustReplace) @@ -12915,14 +12915,15 @@ static void AddReachableCodeToWorklist(BasicBlock *BB, // DCE instruction if trivially dead. if (isInstructionTriviallyDead(Inst)) { ++NumDeadInst; - DOUT << "IC: DCE: " << *Inst << '\n'; + DEBUG(errs() << "IC: DCE: " << *Inst << '\n'); Inst->eraseFromParent(); continue; } // ConstantProp instruction if trivially constant. if (Constant *C = ConstantFoldInstruction(Inst, BB->getContext(), TD)) { - DOUT << "IC: ConstFold to: " << *C << " from: " << *Inst << '\n'; + DEBUG(errs() << "IC: ConstFold to: " << *C << " from: " + << *Inst << '\n'); Inst->replaceAllUsesWith(C); ++NumConstProp; Inst->eraseFromParent(); @@ -13002,7 +13003,7 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) { while (Term != BB->begin()) { // Remove instrs bottom-up BasicBlock::iterator I = Term; --I; - DOUT << "IC: DCE: " << *I << '\n'; + DEBUG(errs() << "IC: DCE: " << *I << '\n'); // A debug intrinsic shouldn't force another iteration if we weren't // going to do one without it. if (!isa<DbgInfoIntrinsic>(I)) { @@ -13027,7 +13028,7 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) { AddUsesToWorkList(*I); ++NumDeadInst; - DOUT << "IC: DCE: " << *I << '\n'; + DEBUG(errs() << "IC: DCE: " << *I << '\n'); I->eraseFromParent(); RemoveFromWorkList(I); @@ -13037,7 +13038,7 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) { // Instruction isn't dead, see if we can constant propagate it. if (Constant *C = ConstantFoldInstruction(I, F.getContext(), TD)) { - DOUT << "IC: ConstFold to: " << *C << " from: " << *I << '\n'; + DEBUG(errs() << "IC: ConstFold to: " << *C << " from: " << *I << '\n'); // Add operands to the worklist. AddUsesToWorkList(*I); @@ -13089,13 +13090,13 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) { #ifndef NDEBUG std::string OrigI; #endif - DEBUG(std::ostringstream SS; I->print(SS); OrigI = SS.str();); + DEBUG(raw_string_ostream SS(OrigI); I->print(SS); OrigI = SS.str();); if (Instruction *Result = visit(*I)) { ++NumCombined; // Should we replace the old instruction with a new one? if (Result != I) { - DOUT << "IC: Old = " << *I << '\n' - << " New = " << *Result << '\n'; + DEBUG(errs() << "IC: Old = " << *I << '\n' + << " New = " << *Result << '\n'); // Everything uses the new instruction now. I->replaceAllUsesWith(Result); @@ -13129,8 +13130,8 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) { InstParent->getInstList().erase(I); } else { #ifndef NDEBUG - DOUT << "IC: Mod = " << OrigI << '\n' - << " New = " << *I << '\n'; + DEBUG(errs() << "IC: Mod = " << OrigI << '\n' + << " New = " << *I << '\n'); #endif // If the instruction was modified, it's possible that it is now dead. diff --git a/lib/Transforms/Scalar/LICM.cpp b/lib/Transforms/Scalar/LICM.cpp index f4f20e4a52..64ca5cd1d4 100644 --- a/lib/Transforms/Scalar/LICM.cpp +++ b/lib/Transforms/Scalar/LICM.cpp @@ -466,7 +466,7 @@ bool LICM::isLoopInvariantInst(Instruction &I) { /// position, and may either delete it or move it to outside of the loop. /// void LICM::sink(Instruction &I) { - DOUT << "LICM sinking instruction: " << I; + DEBUG(errs() << "LICM sinking instruction: " << I); SmallVector<BasicBlock*, 8> ExitBlocks; CurLoop->getExitBlocks(ExitBlocks); @@ -860,7 +860,7 @@ void LICM::FindPromotableValuesInLoop( for (AliasSet::iterator I = AS.begin(), E = AS.end(); I != E; ++I) ValueToAllocaMap.insert(std::make_pair(I->getValue(), AI)); - DOUT << "LICM: Promoting value: " << *V << "\n"; + DEBUG(errs() << "LICM: Promoting value: " << *V << "\n"); } } diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 9a5a226ebb..ed32f50cc6 100644 --- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -380,9 +380,9 @@ namespace { } void BasedUser::dump() const { - cerr << " Base=" << *Base; - cerr << " Imm=" << *Imm; - cerr << " Inst: " << *Inst; + errs() << " Base=" << *Base; + errs() << " Imm=" << *Imm; + errs() << " Inst: " << *Inst; } Value *BasedUser::InsertCodeForBaseAtPosition(const SCEV *const &NewBase, @@ -461,9 +461,10 @@ void BasedUser::RewriteInstructionToUseNewBase(const SCEV *const &NewBase, // Replace the use of the operand Value with the new Phi we just created. Inst->replaceUsesOfWith(OperandValToReplace, NewVal); - DOUT << " Replacing with "; - DEBUG(WriteAsOperand(*DOUT, NewVal, /*PrintType=*/false)); - DOUT << ", which has value " << *NewBase << " plus IMM " << *Imm << "\n"; + DEBUG(errs() << " Replacing with "); + DEBUG(WriteAsOperand(errs(), NewVal, /*PrintType=*/false)); + DEBUG(errs() << ", which has value " << *NewBase << " plus IMM " + << *Imm << "\n"); return; } @@ -518,9 +519,10 @@ void BasedUser::RewriteInstructionToUseNewBase(const SCEV *const &NewBase, Code = InsertCodeForBaseAtPosition(NewBase, PN->getType(), Rewriter, InsertPt, L, LI); - DOUT << " Changing PHI use to "; - DEBUG(WriteAsOperand(*DOUT, Code, /*PrintType=*/false)); - DOUT << ", which has value " << *NewBase << " plus IMM " << *Imm << "\n"; + DEBUG(errs() << " Changing PHI use to "); + DEBUG(WriteAsOperand(errs(), Code, /*PrintType=*/false)); + DEBUG(errs() << ", which has value " << *NewBase << " plus IMM " + << *Imm << "\n"); } // Replace the use of the operand Value with the new Phi we just created. @@ -1373,7 +1375,7 @@ LoopStrengthReduce::PrepareToStrengthReduceFully( const SCEV *CommonExprs, const Loop *L, SCEVExpander &PreheaderRewriter) { - DOUT << " Fully reducing all users\n"; + DEBUG(errs() << " Fully reducing all users\n"); // Rewrite the UsersToProcess records, creating a separate PHI for each // unique Base value. @@ -1422,7 +1424,7 @@ LoopStrengthReduce::PrepareToStrengthReduceWithNewPhi( Instruction *IVIncInsertPt, const Loop *L, SCEVExpander &PreheaderRewriter) { - DOUT << " Inserting new PHI:\n"; + DEBUG(errs() << " Inserting new PHI:\n"); PHINode *Phi = InsertAffinePhi(SE->getUnknown(CommonBaseV), Stride, IVIncInsertPt, L, @@ -1435,9 +1437,9 @@ LoopStrengthReduce::PrepareToStrengthReduceWithNewPhi( for (unsigned i = 0, e = UsersToProcess.size(); i != e; ++i) UsersToProcess[i].Phi = Phi; - DOUT << " IV="; - DEBUG(WriteAsOperand(*DOUT, Phi, /*PrintType=*/false)); - DOUT << "\n"; + DEBUG(errs() << " IV="); + DEBUG(WriteAsOperand(errs(), Phi, /*PrintType=*/false)); + DEBUG(errs() << "\n"); } /// PrepareToStrengthReduceFromSmallerStride - Prepare for the given users to @@ -1450,8 +1452,8 @@ LoopStrengthReduce::PrepareToStrengthReduceFromSmallerStride( Value *CommonBaseV, const IVExpr &ReuseIV, Instruction *PreInsertPt) { - DOUT << " Rewriting in terms of existing IV of STRIDE " << *ReuseIV.Stride - << " and BASE " << *ReuseIV.Base << "\n"; + DEBUG(errs() << " Rewriting in terms of existing IV of STRIDE " + << *ReuseIV.Stride << " and BASE " << *ReuseIV.Base << "\n"); // All the users will share the reused IV. for (unsigned i = 0, e = UsersToProcess.size(); i != e; ++i) @@ -1558,7 +1560,7 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEV *const &Stride, UsersToProcess, TLI); if (DoSink) { - DOUT << " Sinking " << *Imm << " back down into uses\n"; + DEBUG(errs() << " Sinking " << *Imm << " back down into uses\n"); for (unsigned i = 0, e = UsersToProcess.size(); i != e; ++i) UsersToProcess[i].Imm = SE->getAddExpr(UsersToProcess[i].Imm, Imm); CommonExprs = NewCommon; @@ -1570,9 +1572,9 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEV *const &Stride, // Now that we know what we need to do, insert the PHI node itself. // - DOUT << "LSR: Examining IVs of TYPE " << *ReplacedTy << " of STRIDE " - << *Stride << ":\n" - << " Common base: " << *CommonExprs << "\n"; + DEBUG(errs() << "LSR: Examining IVs of TYPE " << *ReplacedTy << " of STRIDE " + << *Stride << ":\n" + << " Common base: " << *CommonExprs << "\n"); SCEVExpander Rewriter(*SE); SCEVExpander PreheaderRewriter(*SE); @@ -1634,10 +1636,10 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEV *const &Stride, if (!Base->isZero()) { BaseV = PreheaderRewriter.expandCodeFor(Base, 0, PreInsertPt); - DOUT << " INSERTING code for BASE = " << *Base << ":"; + DEBUG(errs() << " INSERTING code for BASE = " << *Base << ":"); if (BaseV->hasName()) - DOUT << " Result value name = %" << BaseV->getNameStr(); - DOUT << "\n"; + DEBUG(errs() << " Result value name = %" << BaseV->getName()); + DEBUG(errs() << "\n"); // If BaseV is a non-zero constant, make sure that it gets inserted into // the preheader, instead of being forward substituted into the uses. We @@ -1658,15 +1660,15 @@ void LoopStrengthReduce::StrengthReduceStridedIVUsers(const SCEV *const &Stride, // FIXME: Use emitted users to emit other users. BasedUser &User = UsersToProcess.back(); - DOUT << " Examining "; + DEBUG(errs() << " Examining "); if (User.isUseOfPostIncrementedValue) - DOUT << "postinc"; + DEBUG(errs() << "postinc"); else - DOUT << "preinc"; - DOUT << " use "; - DEBUG(WriteAsOperand(*DOUT, UsersToProcess.back().OperandValToReplace, + DEBUG(errs() << "preinc"); + DEBUG(errs() << " use "); + DEBUG(WriteAsOperand(errs(), UsersToProcess.back().OperandValToReplace, /*PrintType=*/false)); - DOUT << " in Inst: " << *(User.Inst); + DEBUG(errs() << " in Inst: " << *User.Inst); // If this instruction wants to use the post-incremented value, move it // after the post-inc and use its value instead of the PHI. diff --git a/lib/Transforms/Scalar/LoopUnswitch.cpp b/lib/Transforms/Scalar/LoopUnswitch.cpp index bbc99f6d44..06ee95cd32 100644 --- a/lib/Transforms/Scalar/LoopUnswitch.cpp +++ b/lib/Transforms/Scalar/LoopUnswitch.cpp @@ -751,7 +751,7 @@ static void RemoveFromWorklist(Instruction *I, static void ReplaceUsesOfWith(Instruction *I, Value *V, std::vector<Instruction*> &Worklist, Loop *L, LPPassManager *LPM) { - DOUT << "Replace with '" << *V << "': " << *I; + DEBUG(errs() << "Replace with '" << *V << "': " << *I); // Add uses to the worklist, which may be dead now. for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) @@ -813,7 +813,7 @@ void LoopUnswitch::RemoveBlockIfDead(BasicBlock *BB, return; } - DOUT << "Nuking dead block: " << *BB; + DEBUG(errs() << "Nuking dead block: " << *BB); // Remove the instructions in the basic block from the worklist. for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) { @@ -1002,7 +1002,7 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist, Loop *L) { // Simple DCE. if (isInstructionTriviallyDead(I)) { - DOUT << "Remove dead instruction '" << *I; + DEBUG(errs() << "Remove dead instruction '" << *I); // Add uses to the worklist, which may be dead now. for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) @@ -1091,7 +1091,7 @@ void LoopUnswitch::SimplifyCode(std::vector<Instruction*> &Worklist, Loop *L) { // remove dead blocks. break; // FIXME: Enable. - DOUT << "Folded branch: " << *BI; + DEBUG(errs() << "Folded branch: " << *BI); BasicBlock *DeadSucc = BI->getSuccessor(CB->getZExtValue()); BasicBlock *LiveSucc = BI->getSuccessor(!CB->getZExtValue()); DeadSucc->removePredecessor(BI->getParent(), true); diff --git a/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/lib/Transforms/Scalar/MemCpyOptimizer.cpp index e6ad3121fd..8d47e53762 100644 --- a/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -24,6 +24,7 @@ #include "llvm/Analysis/MemoryDependenceAnalysis.h" #include "llvm/Support/Debug.h" #include "llvm/Support/GetElementPtrTypeIterator.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/Target/TargetData.h" #include <list> using namespace llvm; @@ -454,10 +455,10 @@ bool MemCpyOpt::processStore(StoreInst *SI, BasicBlock::iterator& BBI) { ConstantInt::get(Type::getInt32Ty(SI->getContext()), Range.Alignment) }; Value *C = CallInst::Create(MemSetF, Ops, Ops+4, "", InsertPt); - DEBUG(cerr << "Replace stores:\n"; + DEBUG(errs() << "Replace stores:\n"; for (unsigned i = 0, e = Range.TheStores.size(); i != e; ++i) - cerr << *Range.TheStores[i]; - cerr << "With: " << *C); C=C; + errs() << *Range.TheStores[i]; + errs() << "With: " << *C); C=C; // Don't invalidate the iterator BBI = BI; diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp index 26183365a6..e069cea220 100644 --- a/lib/Transforms/Scalar/PredicateSimplifier.cpp +++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp @@ -1385,8 +1385,8 @@ namespace { } bool makeEqual(Value *V1, Value *V2) { - DOUT << "makeEqual(" << *V1 << ", " << *V2 << ")\n"; - DOUT << "context is "; + DEBUG(errs() << "makeEqual(" << *V1 << ", " << *V2 << ")\n"); + DEBUG(errs() << "context is "); DEBUG(if (TopInst) errs() << "I: " << *TopInst << "\n"; else @@ -1491,8 +1491,8 @@ namespace { ToNotify.push_back(I); } - DOUT << "Simply removing " << *I2 - << ", replacing with " << *V1 << "\n"; + DEBUG(errs() << "Simply removing " << *I2 + << ", replacing with " << *V1 << "\n"); I2->replaceAllUsesWith(V1); // leave it dead; it'll get erased later. ++NumInstruction; @@ -1523,8 +1523,8 @@ namespace { // If that killed the instruction, stop here. if (I2 && isInstructionTriviallyDead(I2)) { - DOUT << "Killed all uses of " << *I2 - << ", replacing with " << *V1 << "\n"; + DEBUG(errs() << "Killed all uses of " << *I2 + << ", replacing with " << *V1 << "\n"); continue; } @@ -1730,10 +1730,12 @@ namespace { /// add - adds a new property to the work queue void add(Value *V1, Value *V2, ICmpInst::Predicate Pred, Instruction *I = NULL) { - DOUT << "adding " << *V1 << " " << Pred << " " << *V2; - if (I) DOUT << " context: " << *I; - else DOUT << " default context (" << Top->getDFSNumIn() << ")"; - DOUT << "\n"; + DEBUG(errs() << "adding " << *V1 << " " << Pred << " " << *V2); + if (I) + DEBUG(errs() << " context: " << *I); + else + DEBUG(errs() << " default context (" << Top->getDFSNumIn() << ")"); + DEBUG(errs() << "\n"); assert(V1->getType() == V2->getType() && "Can't relate two values with different types."); @@ -2132,9 +2134,9 @@ namespace { /// solve - process the work queue void solve() { - //DOUT << "WorkList entry, size: " << WorkList.size() << "\n"; + //DEBUG(errs() << "WorkList entry, size: " << WorkList.size() << "\n"); while (!WorkList.empty()) { - //DOUT << "WorkList size: " << WorkList.size() << "\n"; + //DEBUG(errs() << "WorkList size: " << WorkList.size() << "\n"); Operation &O = WorkList.front(); TopInst = O.ContextInst; @@ -2349,7 +2351,7 @@ namespace { // Tries to simplify each Instruction and add new properties. void visitInstruction(Instruction *I, DomTreeDFS::Node *DT) { - DOUT << "Considering instruction " << *I << "\n"; + DEBUG(errs() << "Considering instruction " << *I << "\n"); DEBUG(VN->dump()); DEBUG(IG->dump()); DEBUG(VR->dump()); @@ -2372,7 +2374,7 @@ namespace { if (V != I) { modified = true; ++NumInstruction; - DOUT << "Removing " << *I << ", replacing with " << *V << "\n"; + DEBUG(errs() << "Removing " << *I << ", replacing with " << *V << "\n"); if (unsigned n = VN->valueNumber(I, DTDFS->getRootNode())) if (VN->value(n) == I) IG->remove(n); VN->remove(I); @@ -2389,18 +2391,18 @@ namespace { if (V != Oper) { modified = true; ++NumVarsReplaced; - DOUT << "Resolving " << *I; + DEBUG(errs() << "Resolving " << *I); I->setOperand(i, V); - DOUT << " into " << *I; + DEBUG(errs() << " into " << *I); } } #endif std::string name = I->getParent()->getName(); - DOUT << "push (%" << name << ")\n"; + DEBUG(errs() << "push (%" << name << ")\n"); Forwards visit(this, DT); visit.visit(*I); - DOUT << "pop (%" << name << ")\n"; + DEBUG(errs() << "pop (%" << name << ")\n"); } }; diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp index 5e4a8df2e0..f6e11bc646 100644 --- a/lib/Transforms/Scalar/Reassociate.cpp +++ b/lib/Transforms/Scalar/Reassociate.cpp @@ -34,6 +34,7 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ValueHandle.h" +#include "llvm/Support/raw_ostream.h" #include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/Statistic.h" #include <algorithm> @@ -181,8 +182,8 @@ unsigned Reassociate::getRank(Value *V) { (!BinaryOperator::isNot(I) && !BinaryOperator::isNeg(I))) ++Rank; - //DOUT << "Calculated Rank[" << V->getName() << "] = " - // << Rank << "\n"; + //DEBUG(errs() << "Calculated Rank[" << V->getName() << "] = " + // << Rank << "\n"); return CachedRank = Rank; } @@ -222,7 +223,7 @@ void Reassociate::LinearizeExpr(BinaryOperator *I) { isReassociableOp(RHS, I->getOpcode()) && "Not an expression that needs linearization?"); - DOUT << "Linear" << *LHS << '\n' << *RHS << '\n' << *I << '\n'; + DEBUG(errs() << "Linear" << *LHS << '\n' << *RHS << '\n' << *I << '\n'); // Move the RHS instruction to live immediately before I, avoiding breaking // dominator properties. @@ -235,7 +236,7 @@ void Reassociate::LinearizeExpr(BinaryOperator *I) { ++NumLinear; MadeChange = true; - DOUT << "Linearized: " << *I << '\n'; + DEBUG(errs() << "Linearized: " << *I << '\n'); // If D is part of this expression tree, tail recurse. if (isReassociableOp(I->getOperand(1), I->getOpcode())) @@ -334,10 +335,10 @@ void Reassociate::RewriteExprTree(BinaryOperator *I, if (I->getOperand(0) != Ops[i].Op || I->getOperand(1) != Ops[i+1].Op) { Value *OldLHS = I->getOperand(0); - DOUT << "RA: " << *I << '\n'; + DEBUG(errs() << "RA: " << *I << '\n'); I->setOperand(0, Ops[i].Op); I->setOperand(1, Ops[i+1].Op); - DOUT << "TO: " << *I << '\n'; + DEBUG(errs() << "TO: " << *I << '\n'); MadeChange = true; ++NumChanged; @@ -350,9 +351,9 @@ void Reassociate::RewriteExprTree(BinaryOperator *I, assert(i+2 < Ops.size() && "Ops index out of range!"); if (I->getOperand(1) != Ops[i].Op) { - DOUT << "RA: " << *I << '\n'; + DEBUG(errs() << "RA: " << *I << '\n'); I->setOperand(1, Ops[i].Op); - DOUT << "TO: " << *I << '\n'; + DEBUG(errs() << "TO: " << *I << '\n'); MadeChange = true; ++NumChanged; } @@ -450,7 +451,7 @@ static Instruction *BreakUpSubtract(LLVMContext &Context, Instruction *Sub, Sub->replaceAllUsesWith(New); Sub->eraseFromParent(); - DOUT << "Negated: " << *New << '\n'; + DEBUG(errs() << "Negated: " << *New << '\n'); return New; } @@ -728,7 +729,7 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I, // If any factor occurred more than one time, we can pull it out. if (MaxOcc > 1) { - DOUT << "\nFACTORING [" << MaxOcc << "]: " << *MaxOcc |