aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/IPO/FunctionResolution.cpp38
-rw-r--r--lib/Transforms/Scalar/CorrelatedExprs.cpp35
-rw-r--r--lib/Transforms/Scalar/PredicateSimplifier.cpp62
-rw-r--r--lib/Transforms/Scalar/Reassociate.cpp34
4 files changed, 79 insertions, 90 deletions
diff --git a/lib/Transforms/IPO/FunctionResolution.cpp b/lib/Transforms/IPO/FunctionResolution.cpp
index de3fe5ba87..01d7b5a349 100644
--- a/lib/Transforms/IPO/FunctionResolution.cpp
+++ b/lib/Transforms/IPO/FunctionResolution.cpp
@@ -62,13 +62,13 @@ static bool ResolveFunctions(Module &M, std::vector<GlobalValue*> &Globals,
if (OldFT->getNumParams() > ConcreteFT->getNumParams() &&
!ConcreteFT->isVarArg())
if (!Old->use_empty()) {
- std::cerr << "WARNING: Linking function '" << Old->getName()
- << "' is causing arguments to be dropped.\n";
- std::cerr << "WARNING: Prototype: ";
+ cerr << "WARNING: Linking function '" << Old->getName()
+ << "' is causing arguments to be dropped.\n";
+ cerr << "WARNING: Prototype: ";
WriteAsOperand(std::cerr, Old);
- std::cerr << " resolved to ";
+ cerr << " resolved to ";
WriteAsOperand(std::cerr, Concrete);
- std::cerr << "\n";
+ cerr << "\n";
}
// Check to make sure that if there are specified types, that they
@@ -82,14 +82,14 @@ static bool ResolveFunctions(Module &M, std::vector<GlobalValue*> &Globals,
if (OldFT->getParamType(i) != ConcreteFT->getParamType(i))
if (OldFT->getParamType(i)->getTypeID() !=
ConcreteFT->getParamType(i)->getTypeID()) {
- std::cerr << "WARNING: Function [" << Old->getName()
- << "]: Parameter types conflict for: '";
+ cerr << "WARNING: Function [" << Old->getName()
+ << "]: Parameter types conflict for: '";
WriteTypeSymbolic(std::cerr, OldFT, &M);
- std::cerr << "' (in "
- << Old->getParent()->getModuleIdentifier() << ") and '";
+ cerr << "' (in "
+ << Old->getParent()->getModuleIdentifier() << ") and '";
WriteTypeSymbolic(std::cerr, ConcreteFT, &M);
- std::cerr << "'(in "
- << Concrete->getParent()->getModuleIdentifier() << ")\n";
+ cerr << "'(in "
+ << Concrete->getParent()->getModuleIdentifier() << ")\n";
return Changed;
}
@@ -164,8 +164,8 @@ static bool ProcessGlobalsWithSameName(Module &M, TargetData &TD,
for (unsigned i = 0; i != Globals.size(); ) {
if (isa<Function>(Globals[i]) != isFunction) {
- std::cerr << "WARNING: Found function and global variable with the "
- << "same name: '" << Globals[i]->getName() << "'.\n";
+ cerr << "WARNING: Found function and global variable with the "
+ << "same name: '" << Globals[i]->getName() << "'.\n";
return false; // Don't know how to handle this, bail out!
}
@@ -192,9 +192,9 @@ static bool ProcessGlobalsWithSameName(Module &M, TargetData &TD,
GlobalVariable *GV = cast<GlobalVariable>(Globals[i]);
if (!GV->isExternal()) {
if (Concrete) {
- std::cerr << "WARNING: Two global variables with external linkage"
- << " exist with the same name: '" << GV->getName()
- << "'!\n";
+ cerr << "WARNING: Two global variables with external linkage"
+ << " exist with the same name: '" << GV->getName()
+ << "'!\n";
return false;
}
Concrete = GV;
@@ -251,11 +251,11 @@ static bool ProcessGlobalsWithSameName(Module &M, TargetData &TD,
}
if (0 && !DontPrintWarning) {
- std::cerr << "WARNING: Found global types that are not compatible:\n";
+ cerr << "WARNING: Found global types that are not compatible:\n";
for (unsigned i = 0; i < Globals.size(); ++i) {
- std::cerr << "\t";
+ cerr << "\t";
WriteTypeSymbolic(std::cerr, Globals[i]->getType(), &M);
- std::cerr << " %" << Globals[i]->getName() << "\n";
+ cerr << " %" << Globals[i]->getName() << "\n";
}
}
diff --git a/lib/Transforms/Scalar/CorrelatedExprs.cpp b/lib/Transforms/Scalar/CorrelatedExprs.cpp
index 9024f1caf9..a796ff742e 100644
--- a/lib/Transforms/Scalar/CorrelatedExprs.cpp
+++ b/lib/Transforms/Scalar/CorrelatedExprs.cpp
@@ -42,7 +42,6 @@
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/Statistic.h"
#include <algorithm>
-#include <iostream>
using namespace llvm;
namespace {
@@ -336,7 +335,7 @@ bool CEE::TransformRegion(BasicBlock *BB, std::set<BasicBlock*> &VisitedBlocks){
ComputeReplacements(RI);
// If debugging, print computed region information...
- DEBUG(RI.print(std::cerr));
+ DEBUG(RI.print(*cerr.stream()));
// Simplify the contents of this block...
bool Changed = SimplifyBasicBlock(*BB, RI);
@@ -517,11 +516,10 @@ void CEE::ForwardSuccessorTo(TerminatorInst *TI, unsigned SuccNo,
BasicBlock *OldSucc = TI->getSuccessor(SuccNo);
BasicBlock *BB = TI->getParent();
- DEBUG(std::cerr << "Forwarding branch in basic block %" << BB->getName()
- << " from block %" << OldSucc->getName() << " to block %"
- << Dest->getName() << "\n");
-
- DEBUG(std::cerr << "Before forwarding: " << *BB->getParent());
+ DOUT << "Forwarding branch in basic block %" << BB->getName()
+ << " from block %" << OldSucc->getName() << " to block %"
+ << Dest->getName() << "\n"
+ << "Before forwarding: " << *BB->getParent();
// Because we know that there cannot be critical edges in the flow graph, and
// that OldSucc has multiple outgoing edges, this means that Dest cannot have
@@ -628,7 +626,7 @@ void CEE::ForwardSuccessorTo(TerminatorInst *TI, unsigned SuccNo,
// FIXME: This is much worse than it really should be!
//EF->recalculate();
- DEBUG(std::cerr << "After forwarding: " << *BB->getParent());
+ DOUT << "After forwarding: " << *BB->getParent();
}
/// ReplaceUsesOfValueInRegion - This method replaces all uses of Orig with uses
@@ -921,9 +919,9 @@ void CEE::PropagateRelation(Instruction::BinaryOps Opcode, Value *Op0,
//
if (Op1R.contradicts(Opcode, VI)) {
Op1R.contradicts(Opcode, VI);
- std::cerr << "Contradiction found for opcode: "
- << Instruction::getOpcodeName(Opcode) << "\n";
- Op1R.print(std::cerr);
+ cerr << "Contradiction found for opcode: "
+ << Instruction::getOpcodeName(Opcode) << "\n";
+ Op1R.print(*cerr.stream());
return;
}
@@ -1033,8 +1031,7 @@ bool CEE::SimplifyBasicBlock(BasicBlock &BB, const RegionInfo &RI) {
// Try to simplify a setcc instruction based on inherited information
Relation::KnownResult Result = getSetCCResult(SCI, RI);
if (Result != Relation::Unknown) {
- DEBUG(std::cerr << "Replacing setcc with " << Result
- << " constant: " << *SCI);
+ DOUT << "Replacing setcc with " << Result << " constant: " << *SCI;
SCI->replaceAllUsesWith(ConstantBool::get((bool)Result));
// The instruction is now dead, remove it from the program.
@@ -1061,8 +1058,8 @@ bool CEE::SimplifyInstruction(Instruction *I, const RegionInfo &RI) {
if (Value *Repl = VI->getReplacement()) {
// If we know if a replacement with lower rank than Op0, make the
// replacement now.
- DEBUG(std::cerr << "In Inst: " << *I << " Replacing operand #" << i
- << " with " << *Repl << "\n");
+ DOUT << "In Inst: " << *I << " Replacing operand #" << i
+ << " with " << *Repl << "\n";
I->setOperand(i, Repl);
Changed = true;
++NumOperandsCann;
@@ -1090,7 +1087,7 @@ Relation::KnownResult CEE::getSetCCResult(SetCondInst *SCI,
if (isa<Constant>(Op1)) {
if (Constant *Result = ConstantFoldInstruction(SCI)) {
// Wow, this is easy, directly eliminate the SetCondInst.
- DEBUG(std::cerr << "Replacing setcc with constant fold: " << *SCI);
+ DOUT << "Replacing setcc with constant fold: " << *SCI;
return cast<ConstantBool>(Result)->getValue()
? Relation::KnownTrue : Relation::KnownFalse;
}
@@ -1313,6 +1310,6 @@ void Relation::print(std::ostream &OS) const {
}
// Don't inline these methods or else we won't be able to call them from GDB!
-void Relation::dump() const { print(std::cerr); }
-void ValueInfo::dump() const { print(std::cerr, 0); }
-void RegionInfo::dump() const { print(std::cerr); }
+void Relation::dump() const { print(*cerr.stream()); }
+void ValueInfo::dump() const { print(*cerr.stream(), 0); }
+void RegionInfo::dump() const { print(*cerr.stream()); }
diff --git a/lib/Transforms/Scalar/PredicateSimplifier.cpp b/lib/Transforms/Scalar/PredicateSimplifier.cpp
index 81a22309b1..8b8a9f9fa5 100644
--- a/lib/Transforms/Scalar/PredicateSimplifier.cpp
+++ b/lib/Transforms/Scalar/PredicateSimplifier.cpp
@@ -88,7 +88,6 @@
#include "llvm/Transforms/Utils/Local.h"
#include <algorithm>
#include <deque>
-#include <iostream>
#include <sstream>
#include <map>
using namespace llvm;
@@ -272,7 +271,7 @@ namespace {
}
Node *newNode(Value *V) {
- //DEBUG(std::cerr << "new node: " << *V << "\n");
+ //DOUT << "new node: " << *V << "\n";
materialize();
Node *&N = Nodes[V];
assert(N == 0 && "Node already exists for value.");
@@ -561,7 +560,7 @@ namespace {
}
void addToWorklist(Instruction *I) {
- //DEBUG(std::cerr << "addToWorklist: " << *I << "\n");
+ //DOUT << "addToWorklist: " << *I << "\n";
if (!isa<BinaryOperator>(I) && !isa<SelectInst>(I)) return;
@@ -574,7 +573,7 @@ namespace {
}
void addRecursive(Value *V) {
- //DEBUG(std::cerr << "addRecursive: " << *V << "\n");
+ //DOUT << "addRecursive: " << *V << "\n";
Instruction *I = dyn_cast<Instruction>(V);
if (I)
@@ -582,7 +581,7 @@ namespace {
else if (!isa<Argument>(V))
return;
- //DEBUG(std::cerr << "addRecursive uses...\n");
+ //DOUT << "addRecursive uses...\n";
for (Value::use_iterator UI = V->use_begin(), UE = V->use_end();
UI != UE; ++UI) {
// Use must be either be dominated by Top, or dominate Top.
@@ -594,14 +593,14 @@ namespace {
}
if (I) {
- //DEBUG(std::cerr << "addRecursive ops...\n");
+ //DOUT << "addRecursive ops...\n";
for (User::op_iterator OI = I->op_begin(), OE = I->op_end();
OI != OE; ++OI) {
if (Instruction *Inst = dyn_cast<Instruction>(*OI))
addToWorklist(Inst);
}
}
- //DEBUG(std::cerr << "exit addRecursive (" << *V << ").\n");
+ //DOUT << "exit addRecursive (" << *V << ").\n";
}
public:
@@ -660,8 +659,7 @@ namespace {
// you may no longer perform any queries on the InequalityGraph.
bool addEqual(Value *V1, Value *V2) {
- //DEBUG(std::cerr << "addEqual(" << *V1 << ", "
- // << *V2 << ")\n");
+ //DOUT << "addEqual(" << *V1 << ", " << *V2 << ")\n";
if (isEqual(V1, V2)) return true;
const Node *cN1 = cIG.getNode(V1), *cN2 = cIG.getNode(V2);
@@ -694,8 +692,8 @@ namespace {
if (Top != Node_I2 && Node_I2->DominatedBy(Top)) {
Value *V = V1;
if (cN1 && compare(V1, cN1->getValue())) V = cN1->getValue();
- //DEBUG(std::cerr << "Simply removing " << *I2
- // << ", replacing with " << *V << "\n");
+ //DOUT << "Simply removing " << *I2
+ // << ", replacing with " << *V << "\n";
I2->replaceAllUsesWith(V);
// leave it dead; it'll get erased later.
++NumSimple;
@@ -772,8 +770,7 @@ namespace {
}
bool addNotEqual(Value *V1, Value *V2) {
- //DEBUG(std::cerr << "addNotEqual(" << *V1 << ", "
- // << *V2 << ")\n");
+ //DOUT << "addNotEqual(" << *V1 << ", " << *V2 << ")\n");
if (isNotEqual(V1, V2)) return true;
// Never permit %x NE true/false.
@@ -837,9 +834,9 @@ namespace {
}
void solve() {
- DEBUG(std::cerr << "WorkList entry, size: " << WorkList.size() << "\n");
+ DOUT << "WorkList entry, size: " << WorkList.size() << "\n";
while (!WorkList.empty()) {
- DEBUG(std::cerr << "WorkList size: " << WorkList.size() << "\n");
+ DOUT << "WorkList size: " << WorkList.size() << "\n";
Instruction *I = WorkList.front();
WorkList.pop_front();
@@ -847,8 +844,8 @@ namespace {
Value *Canonical = cIG.canonicalize(I);
const Type *Ty = I->getType();
- //DEBUG(std::cerr << "solving: " << *I << "\n");
- //DEBUG(IG.debug(std::cerr));
+ //DOUT << "solving: " << *I << "\n";
+ //DEBUG(IG.debug(*cerr.stream()));
if (BinaryOperator *BO = dyn_cast<BinaryOperator>(I)) {
Value *Op0 = cIG.canonicalize(BO->getOperand(0)),
@@ -1135,17 +1132,17 @@ namespace {
// Visits each instruction in the basic block.
void visitBasicBlock(BasicBlock *BB, InequalityGraph &IG) {
- DEBUG(std::cerr << "Entering Basic Block: " << BB->getName() << "\n");
- for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
- visitInstruction(I++, IG);
+ DOUT << "Entering Basic Block: " << BB->getName() << "\n";
+ for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E;) {
+ visitInstruction(I++, IG);
}
}
// Tries to simplify each Instruction and add new properties to
// the PropertySet.
void visitInstruction(Instruction *I, InequalityGraph &IG) {
- DEBUG(std::cerr << "Considering instruction " << *I << "\n");
- DEBUG(IG.debug(std::cerr));
+ DOUT << "Considering instruction " << *I << "\n";
+ DEBUG(IG.debug(*cerr.stream()));
// Sometimes instructions are made dead due to earlier analysis.
if (isInstructionTriviallyDead(I)) {
@@ -1158,8 +1155,7 @@ namespace {
if (V != I) {
modified = true;
++NumInstruction;
- DEBUG(std::cerr << "Removing " << *I << ", replacing with "
- << *V << "\n");
+ DOUT << "Removing " << *I << ", replacing with " << *V << "\n";
IG.remove(I);
I->replaceAllUsesWith(V);
I->eraseFromParent();
@@ -1173,16 +1169,16 @@ namespace {
if (V != Oper) {
modified = true;
++NumVarsReplaced;
- DEBUG(std::cerr << "Resolving " << *I);
+ DOUT << "Resolving " << *I;
I->setOperand(i, V);
- DEBUG(std::cerr << " into " << *I);
+ DOUT << " into " << *I;
}
}
- //DEBUG(std::cerr << "push (%" << I->getParent()->getName() << ")\n");
+ //DOUT << "push (%" << I->getParent()->getName() << ")\n";
Forwards visit(this, IG);
visit.visit(*I);
- //DEBUG(std::cerr << "pop (%" << I->getParent()->getName() << ")\n");
+ //DOUT << "pop (%" << I->getParent()->getName() << ")\n";
}
};
@@ -1190,7 +1186,7 @@ namespace {
DT = &getAnalysis<DominatorTree>();
Forest = &getAnalysis<ETForest>();
- DEBUG(std::cerr << "Entering Function: " << F.getName() << "\n");
+ DOUT << "Entering Function: " << F.getName() << "\n";
modified = false;
WorkList.push_back(State(DT->getRoot(), new InequalityGraph()));
@@ -1236,15 +1232,15 @@ namespace {
VRPSolver Solver(*DestProperties, PS->Forest, Dest);
if (Dest == TrueDest) {
- DEBUG(std::cerr << "(" << BB->getName() << ") true set:\n");
+ DOUT << "(" << BB->getName() << ") true set:\n";
if (!Solver.addEqual(ConstantBool::getTrue(), Condition)) continue;
Solver.solve();
- DEBUG(DestProperties->debug(std::cerr));
+ DEBUG(DestProperties->debug(*cerr.stream()));
} else if (Dest == FalseDest) {
- DEBUG(std::cerr << "(" << BB->getName() << ") false set:\n");
+ DOUT << "(" << BB->getName() << ") false set:\n";
if (!Solver.addEqual(ConstantBool::getFalse(), Condition)) continue;
Solver.solve();
- DEBUG(DestProperties->debug(std::cerr));
+ DEBUG(DestProperties->debug(*cerr.stream()));
}
PS->proceedToSuccessor(DestProperties, Dest);
diff --git a/lib/Transforms/Scalar/Reassociate.cpp b/lib/Transforms/Scalar/Reassociate.cpp
index 09f274818b..196cd3854a 100644
--- a/lib/Transforms/Scalar/Reassociate.cpp
+++ b/lib/Transforms/Scalar/Reassociate.cpp
@@ -33,7 +33,6 @@
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/Statistic.h"
#include <algorithm>
-#include <iostream>
using namespace llvm;
namespace {
@@ -57,10 +56,10 @@ namespace {
///
static void PrintOps(Instruction *I, const std::vector<ValueEntry> &Ops) {
Module *M = I->getParent()->getParent()->getParent();
- std::cerr << Instruction::getOpcodeName(I->getOpcode()) << " "
+ cerr << Instruction::getOpcodeName(I->getOpcode()) << " "
<< *Ops[0].Op->getType();
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
- WriteAsOperand(std::cerr << " ", Ops[i].Op, false, M)
+ WriteAsOperand(*cerr.stream() << " ", Ops[i].Op, false, M)
<< "," << Ops[i].Rank;
}
@@ -169,8 +168,8 @@ unsigned Reassociate::getRank(Value *V) {
(!BinaryOperator::isNot(I) && !BinaryOperator::isNeg(I)))
++Rank;
- //DEBUG(std::cerr << "Calculated Rank[" << V->getName() << "] = "
- //<< Rank << "\n");
+ //DOUT << "Calculated Rank[" << V->getName() << "] = "
+ // << Rank << "\n";
return CachedRank = Rank;
}
@@ -212,7 +211,7 @@ void Reassociate::LinearizeExpr(BinaryOperator *I) {
isReassociableOp(RHS, I->getOpcode()) &&
"Not an expression that needs linearization?");
- DEBUG(std::cerr << "Linear" << *LHS << *RHS << *I);
+ DOUT << "Linear" << *LHS << *RHS << *I;
// Move the RHS instruction to live immediately before I, avoiding breaking
// dominator properties.
@@ -225,7 +224,7 @@ void Reassociate::LinearizeExpr(BinaryOperator *I) {
++NumLinear;
MadeChange = true;
- DEBUG(std::cerr << "Linearized: " << *I);
+ DOUT << "Linearized: " << *I;
// If D is part of this expression tree, tail recurse.
if (isReassociableOp(I->getOperand(1), I->getOpcode()))
@@ -320,10 +319,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);
- DEBUG(std::cerr << "RA: " << *I);
+ DOUT << "RA: " << *I;
I->setOperand(0, Ops[i].Op);
I->setOperand(1, Ops[i+1].Op);
- DEBUG(std::cerr << "TO: " << *I);
+ DOUT << "TO: " << *I;
MadeChange = true;
++NumChanged;
@@ -336,9 +335,9 @@ void Reassociate::RewriteExprTree(BinaryOperator *I,
assert(i+2 < Ops.size() && "Ops index out of range!");
if (I->getOperand(1) != Ops[i].Op) {
- DEBUG(std::cerr << "RA: " << *I);
+ DOUT << "RA: " << *I;
I->setOperand(1, Ops[i].Op);
- DEBUG(std::cerr << "TO: " << *I);
+ DOUT << "TO: " << *I;
MadeChange = true;
++NumChanged;
}
@@ -419,7 +418,7 @@ static Instruction *BreakUpSubtract(Instruction *Sub) {
Sub->replaceAllUsesWith(New);
Sub->eraseFromParent();
- DEBUG(std::cerr << "Negated: " << *New);
+ DOUT << "Negated: " << *New;
return New;
}
@@ -693,8 +692,7 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
// If any factor occurred more than one time, we can pull it out.
if (MaxOcc > 1) {
- DEBUG(std::cerr << "\nFACTORING [" << MaxOcc << "]: "
- << *MaxOccVal << "\n");
+ DOUT << "\nFACTORING [" << MaxOcc << "]: " << *MaxOccVal << "\n";
// Create a new instruction that uses the MaxOccVal twice. If we don't do
// this, we could otherwise run into situations where removing a factor
@@ -807,8 +805,7 @@ void Reassociate::ReassociateExpression(BinaryOperator *I) {
std::vector<ValueEntry> Ops;
LinearizeExprTree(I, Ops);
- DEBUG(std::cerr << "RAIn:\t"; PrintOps(I, Ops);
- std::cerr << "\n");
+ DOUT << "RAIn:\t"; DEBUG(PrintOps(I, Ops)); DOUT << "\n";
// Now that we have linearized the tree to a list and have gathered all of
// the operands and their ranks, sort the operands by their rank. Use a
@@ -823,7 +820,7 @@ void Reassociate::ReassociateExpression(BinaryOperator *I) {
if (Value *V = OptimizeExpression(I, Ops)) {
// This expression tree simplified to something that isn't a tree,
// eliminate it.
- DEBUG(std::cerr << "Reassoc to scalar: " << *V << "\n");
+ DOUT << "Reassoc to scalar: " << *V << "\n";
I->replaceAllUsesWith(V);
RemoveDeadBinaryOp(I);
return;
@@ -841,8 +838,7 @@ void Reassociate::ReassociateExpression(BinaryOperator *I) {
Ops.pop_back();
}
- DEBUG(std::cerr << "RAOut:\t"; PrintOps(I, Ops);
- std::cerr << "\n");
+ DOUT << "RAOut:\t"; DEBUG(PrintOps(I, Ops)); DOUT << "\n";
if (Ops.size() == 1) {
// This expression tree simplified to something that isn't a tree,