Eliminate some uses of DOUT, cerr, and getNameStart().

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77145 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar
2009-07-26 07:49:05 +00:00
parent f40761d522
commit 93b67e40de
12 changed files with 300 additions and 293 deletions

View File

@ -91,9 +91,10 @@
#include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/PrettyStackTrace.h"
namespace llvm { namespace llvm {
class Pass;
class Value;
class Module; class Module;
class Pass;
class StringRef;
class Value;
/// FunctionPassManager and PassManager, two top level managers, serve /// FunctionPassManager and PassManager, two top level managers, serve
/// as the public interface of pass manager infrastructure. /// as the public interface of pass manager infrastructure.
@ -285,7 +286,8 @@ public:
void removeNotPreservedAnalysis(Pass *P); void removeNotPreservedAnalysis(Pass *P);
/// Remove dead passes /// Remove dead passes
void removeDeadPasses(Pass *P, const char *Msg, enum PassDebuggingString); void removeDeadPasses(Pass *P, const StringRef &Msg,
enum PassDebuggingString);
/// Add pass P into the PassVector. Update /// Add pass P into the PassVector. Update
/// AvailableAnalysis appropriately if ProcessAnalysis is true. /// AvailableAnalysis appropriately if ProcessAnalysis is true.
@ -340,7 +342,7 @@ public:
void dumpLastUses(Pass *P, unsigned Offset) const; void dumpLastUses(Pass *P, unsigned Offset) const;
void dumpPassArguments() const; void dumpPassArguments() const;
void dumpPassInfo(Pass *P, enum PassDebuggingString S1, void dumpPassInfo(Pass *P, enum PassDebuggingString S1,
enum PassDebuggingString S2, const char *Msg); enum PassDebuggingString S2, const StringRef &Msg);
void dumpRequiredSet(const Pass *P) const; void dumpRequiredSet(const Pass *P) const;
void dumpPreservedSet(const Pass *P) const; void dumpPreservedSet(const Pass *P) const;
@ -379,7 +381,7 @@ protected:
std::map<AnalysisID, Pass *> *InheritedAnalysis[PMT_Last]; std::map<AnalysisID, Pass *> *InheritedAnalysis[PMT_Last];
private: private:
void dumpAnalysisUsage(const char *Msg, const Pass *P, void dumpAnalysisUsage(const StringRef &Msg, const Pass *P,
const AnalysisUsage::VectorType &Set) const; const AnalysisUsage::VectorType &Set) const;
// Set of available Analysis. This information is used while scheduling // Set of available Analysis. This information is used while scheduling

View File

@ -120,7 +120,8 @@ Function *ExecutionEngine::FindFunctionNamed(const char *FnName) {
void ExecutionEngine::addGlobalMapping(const GlobalValue *GV, void *Addr) { void ExecutionEngine::addGlobalMapping(const GlobalValue *GV, void *Addr) {
MutexGuard locked(lock); MutexGuard locked(lock);
DOUT << "JIT: Map \'" << GV->getNameStart() << "\' to [" << Addr << "]\n"; DEBUG(errs() << "JIT: Map \'" << GV->getName()
<< "\' to [" << Addr << "]\n";);
void *&CurVal = state.getGlobalAddressMap(locked)[GV]; void *&CurVal = state.getGlobalAddressMap(locked)[GV];
assert((CurVal == 0 || Addr == 0) && "GlobalMapping already established!"); assert((CurVal == 0 || Addr == 0) && "GlobalMapping already established!");
CurVal = Addr; CurVal = Addr;

View File

@ -1086,11 +1086,12 @@ bool ARMAsmPrinter::doInitialization(Module &M) {
/// PrintUnmangledNameSafely - Print out the printable characters in the name. /// PrintUnmangledNameSafely - Print out the printable characters in the name.
/// Don't print things like \\n or \\0. /// Don't print things like \\n or \\0.
static void PrintUnmangledNameSafely(const Value *V, formatted_raw_ostream &OS) { static void PrintUnmangledNameSafely(const Value *V,
for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen(); formatted_raw_ostream &OS) {
Name != E; ++Name) for (StringRef::iterator it = V->getName().begin(),
if (isprint(*Name)) ie = V->getName().end(); it != ie; ++it)
OS << *Name; if (isprint(*it))
OS << *it;
} }
void ARMAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) { void ARMAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {

View File

@ -490,11 +490,12 @@ bool LinuxAsmPrinter::doInitialization(Module &M) {
/// PrintUnmangledNameSafely - Print out the printable characters in the name. /// PrintUnmangledNameSafely - Print out the printable characters in the name.
/// Don't print things like \\n or \\0. /// Don't print things like \\n or \\0.
static void PrintUnmangledNameSafely(const Value *V, formatted_raw_ostream &OS) { static void PrintUnmangledNameSafely(const Value *V,
for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen(); formatted_raw_ostream &OS) {
Name != E; ++Name) for (StringRef::iterator it = V->getName().begin(),
if (isprint(*Name)) ie = V->getName().end(); it != ie; ++it)
OS << *Name; if (isprint(*it))
OS << *it;
} }
/*! /*!

View File

@ -652,11 +652,12 @@ bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
/// PrintUnmangledNameSafely - Print out the printable characters in the name. /// PrintUnmangledNameSafely - Print out the printable characters in the name.
/// Don't print things like \\n or \\0. /// Don't print things like \\n or \\0.
static void PrintUnmangledNameSafely(const Value *V, formatted_raw_ostream &OS) { static void PrintUnmangledNameSafely(const Value *V,
for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen(); formatted_raw_ostream &OS) {
Name != E; ++Name) for (StringRef::iterator it = V->getName().begin(),
if (isprint(*Name)) ie = V->getName().end(); it != ie; ++it)
OS << *Name; if (isprint(*it))
OS << *it;
} }
void PPCLinuxAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) { void PPCLinuxAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {

View File

@ -303,11 +303,12 @@ void SystemZAsmPrinter::printRRIAddrOperand(const MachineInstr *MI, int OpNum,
/// PrintUnmangledNameSafely - Print out the printable characters in the name. /// PrintUnmangledNameSafely - Print out the printable characters in the name.
/// Don't print things like \\n or \\0. /// Don't print things like \\n or \\0.
static void PrintUnmangledNameSafely(const Value *V, formatted_raw_ostream &OS) { static void PrintUnmangledNameSafely(const Value *V,
for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen(); formatted_raw_ostream &OS) {
Name != E; ++Name) for (StringRef::iterator it = V->getName().begin(),
if (isprint(*Name)) ie = V->getName().end(); it != ie; ++it)
OS << *Name; if (isprint(*it))
OS << *it;
} }
void SystemZAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) { void SystemZAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {

View File

@ -60,12 +60,12 @@ void X86ATTAsmPrinter::PrintPICBaseSymbol() const {
/// PrintUnmangledNameSafely - Print out the printable characters in the name. /// PrintUnmangledNameSafely - Print out the printable characters in the name.
/// Don't print things like \\n or \\0. /// Don't print things like \\n or \\0.
static void PrintUnmangledNameSafely(const Value *V, static void PrintUnmangledNameSafely(const Value *V,
formatted_raw_ostream &OS) { formatted_raw_ostream &OS) {
for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen(); for (StringRef::iterator it = V->getName().begin(),
Name != E; ++Name) ie = V->getName().end(); it != ie; ++it)
if (isprint(*Name)) if (isprint(*it))
OS << *Name; OS << *it;
} }
static X86MachineFunctionInfo calculateFunctionInfo(const Function *F, static X86MachineFunctionInfo calculateFunctionInfo(const Function *F,

View File

@ -29,6 +29,7 @@
#include "llvm/Support/Compiler.h" #include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/ValueHandle.h" #include "llvm/Support/ValueHandle.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm; using namespace llvm;
STATISTIC(NumThreads, "Number of jumps threaded"); STATISTIC(NumThreads, "Number of jumps threaded");
@ -98,7 +99,7 @@ FunctionPass *llvm::createJumpThreadingPass() { return new JumpThreading(); }
/// runOnFunction - Top level algorithm. /// runOnFunction - Top level algorithm.
/// ///
bool JumpThreading::runOnFunction(Function &F) { bool JumpThreading::runOnFunction(Function &F) {
DOUT << "Jump threading on function '" << F.getNameStart() << "'\n"; DEBUG(errs() << "Jump threading on function '" << F.getName() << "'\n");
TD = getAnalysisIfAvailable<TargetData>(); TD = getAnalysisIfAvailable<TargetData>();
FindLoopHeaders(F); FindLoopHeaders(F);
@ -118,8 +119,8 @@ bool JumpThreading::runOnFunction(Function &F) {
// edges which simplifies the CFG. // edges which simplifies the CFG.
if (pred_begin(BB) == pred_end(BB) && if (pred_begin(BB) == pred_end(BB) &&
BB != &BB->getParent()->getEntryBlock()) { BB != &BB->getParent()->getEntryBlock()) {
DOUT << " JT: Deleting dead block '" << BB->getNameStart() DEBUG(errs() << " JT: Deleting dead block '" << BB->getName()
<< "' with terminator: " << *BB->getTerminator(); << "' with terminator: " << *BB->getTerminator());
LoopHeaders.erase(BB); LoopHeaders.erase(BB);
DeleteDeadBlock(BB); DeleteDeadBlock(BB);
Changed = true; Changed = true;
@ -172,8 +173,8 @@ BasicBlock *JumpThreading::FactorCommonPHIPreds(PHINode *PN, Value *Val) {
if (CommonPreds.size() == 1) if (CommonPreds.size() == 1)
return CommonPreds[0]; return CommonPreds[0];
DOUT << " Factoring out " << CommonPreds.size() DEBUG(errs() << " Factoring out " << CommonPreds.size()
<< " common predecessors.\n"; << " common predecessors.\n");
return SplitBlockPredecessors(PN->getParent(), return SplitBlockPredecessors(PN->getParent(),
&CommonPreds[0], CommonPreds.size(), &CommonPreds[0], CommonPreds.size(),
".thr_comm", this); ".thr_comm", this);
@ -261,8 +262,8 @@ bool JumpThreading::ProcessBlock(BasicBlock *BB) {
// terminator to an unconditional branch. This can occur due to threading in // terminator to an unconditional branch. This can occur due to threading in
// other blocks. // other blocks.
if (isa<ConstantInt>(Condition)) { if (isa<ConstantInt>(Condition)) {
DOUT << " In block '" << BB->getNameStart() DEBUG(errs() << " In block '" << BB->getName()
<< "' folding terminator: " << *BB->getTerminator(); << "' folding terminator: " << *BB->getTerminator());
++NumFolds; ++NumFolds;
ConstantFoldTerminator(BB); ConstantFoldTerminator(BB);
return true; return true;
@ -291,8 +292,8 @@ bool JumpThreading::ProcessBlock(BasicBlock *BB) {
BBTerm->getSuccessor(i)->removePredecessor(BB); BBTerm->getSuccessor(i)->removePredecessor(BB);
} }
DOUT << " In block '" << BB->getNameStart() DEBUG(errs() << " In block '" << BB->getName()
<< "' folding undef terminator: " << *BBTerm; << "' folding undef terminator: " << *BBTerm);
BranchInst::Create(BBTerm->getSuccessor(MinSucc), BBTerm); BranchInst::Create(BBTerm->getSuccessor(MinSucc), BBTerm);
BBTerm->eraseFromParent(); BBTerm->eraseFromParent();
return true; return true;
@ -418,8 +419,8 @@ bool JumpThreading::ProcessBranchOnDuplicateCond(BasicBlock *PredBB,
else if (PredBI->getSuccessor(0) != BB) else if (PredBI->getSuccessor(0) != BB)
BranchDir = false; BranchDir = false;
else { else {
DOUT << " In block '" << PredBB->getNameStart() DEBUG(errs() << " In block '" << PredBB->getName()
<< "' folding terminator: " << *PredBB->getTerminator(); << "' folding terminator: " << *PredBB->getTerminator());
++NumFolds; ++NumFolds;
ConstantFoldTerminator(PredBB); ConstantFoldTerminator(PredBB);
return true; return true;
@ -430,9 +431,9 @@ bool JumpThreading::ProcessBranchOnDuplicateCond(BasicBlock *PredBB,
// If the dest block has one predecessor, just fix the branch condition to a // If the dest block has one predecessor, just fix the branch condition to a
// constant and fold it. // constant and fold it.
if (BB->getSinglePredecessor()) { if (BB->getSinglePredecessor()) {
DOUT << " In block '" << BB->getNameStart() DEBUG(errs() << " In block '" << BB->getName()
<< "' folding condition to '" << BranchDir << "': " << "' folding condition to '" << BranchDir << "': "
<< *BB->getTerminator(); << *BB->getTerminator());
++NumFolds; ++NumFolds;
DestBI->setCondition(ConstantInt::get(Type::Int1Ty, BranchDir)); DestBI->setCondition(ConstantInt::get(Type::Int1Ty, BranchDir));
ConstantFoldTerminator(BB); ConstantFoldTerminator(BB);
@ -443,8 +444,8 @@ bool JumpThreading::ProcessBranchOnDuplicateCond(BasicBlock *PredBB,
// involves code duplication. Check to see if it is worth it. // involves code duplication. Check to see if it is worth it.
unsigned JumpThreadCost = getJumpThreadDuplicationCost(BB); unsigned JumpThreadCost = getJumpThreadDuplicationCost(BB);
if (JumpThreadCost > Threshold) { if (JumpThreadCost > Threshold) {
DOUT << " Not threading BB '" << BB->getNameStart() DEBUG(errs() << " Not threading BB '" << BB->getName()
<< "' - Cost is too high: " << JumpThreadCost << "\n"; << "' - Cost is too high: " << JumpThreadCost << "\n");
return false; return false;
} }
@ -507,8 +508,8 @@ bool JumpThreading::ProcessSwitchOnDuplicateCond(BasicBlock *PredBB,
// Otherwise, we're safe to make the change. Make sure that the edge from // Otherwise, we're safe to make the change. Make sure that the edge from
// DestSI to DestSucc is not critical and has no PHI nodes. // DestSI to DestSucc is not critical and has no PHI nodes.
DOUT << "FORWARDING EDGE " << *DestVal << " FROM: " << *PredSI; DEBUG(errs() << "FORWARDING EDGE " << *DestVal << " FROM: " << *PredSI);
DOUT << "THROUGH: " << *DestSI; DEBUG(errs() << "THROUGH: " << *DestSI);
// If the destination has PHI nodes, just split the edge for updating // If the destination has PHI nodes, just split the edge for updating
// simplicity. // simplicity.
@ -706,8 +707,8 @@ bool JumpThreading::ProcessJumpOnPHI(PHINode *PN) {
BasicBlock *BB = PN->getParent(); BasicBlock *BB = PN->getParent();
unsigned JumpThreadCost = getJumpThreadDuplicationCost(BB); unsigned JumpThreadCost = getJumpThreadDuplicationCost(BB);
if (JumpThreadCost > Threshold) { if (JumpThreadCost > Threshold) {
DOUT << " Not threading BB '" << BB->getNameStart() DEBUG(errs() << " Not threading BB '" << BB->getName()
<< "' - Cost is too high: " << JumpThreadCost << "\n"; << "' - Cost is too high: " << JumpThreadCost << "\n");
return false; return false;
} }
@ -771,8 +772,8 @@ bool JumpThreading::ProcessBranchOnLogical(Value *V, BasicBlock *BB,
// See if the cost of duplicating this block is low enough. // See if the cost of duplicating this block is low enough.
unsigned JumpThreadCost = getJumpThreadDuplicationCost(BB); unsigned JumpThreadCost = getJumpThreadDuplicationCost(BB);
if (JumpThreadCost > Threshold) { if (JumpThreadCost > Threshold) {
DOUT << " Not threading BB '" << BB->getNameStart() DEBUG(errs() << " Not threading BB '" << BB->getName()
<< "' - Cost is too high: " << JumpThreadCost << "\n"; << "' - Cost is too high: " << JumpThreadCost << "\n");
return false; return false;
} }
@ -857,8 +858,8 @@ bool JumpThreading::ProcessBranchOnCompare(CmpInst *Cmp, BasicBlock *BB) {
// See if the cost of duplicating this block is low enough. // See if the cost of duplicating this block is low enough.
unsigned JumpThreadCost = getJumpThreadDuplicationCost(BB); unsigned JumpThreadCost = getJumpThreadDuplicationCost(BB);
if (JumpThreadCost > Threshold) { if (JumpThreadCost > Threshold) {
DOUT << " Not threading BB '" << BB->getNameStart() DEBUG(errs() << " Not threading BB '" << BB->getNameStart()
<< "' - Cost is too high: " << JumpThreadCost << "\n"; << "' - Cost is too high: " << JumpThreadCost << "\n");
return false; return false;
} }
@ -882,26 +883,26 @@ bool JumpThreading::ThreadEdge(BasicBlock *BB, BasicBlock *PredBB,
// If threading to the same block as we come from, we would infinite loop. // If threading to the same block as we come from, we would infinite loop.
if (SuccBB == BB) { if (SuccBB == BB) {
DOUT << " Not threading across BB '" << BB->getNameStart() DEBUG(errs() << " Not threading across BB '" << BB->getName()
<< "' - would thread to self!\n"; << "' - would thread to self!\n");
return false; return false;
} }
// If threading this would thread across a loop header, don't thread the edge. // If threading this would thread across a loop header, don't thread the edge.
// See the comments above FindLoopHeaders for justifications and caveats. // See the comments above FindLoopHeaders for justifications and caveats.
if (LoopHeaders.count(BB)) { if (LoopHeaders.count(BB)) {
DOUT << " Not threading from '" << PredBB->getNameStart() DEBUG(errs() << " Not threading from '" << PredBB->getName()
<< "' across loop header BB '" << BB->getNameStart() << "' across loop header BB '" << BB->getName()
<< "' to dest BB '" << SuccBB->getNameStart() << "' to dest BB '" << SuccBB->getName()
<< "' - it might create an irreducible loop!\n"; << "' - it might create an irreducible loop!\n");
return false; return false;
} }
// And finally, do it! // And finally, do it!
DOUT << " Threading edge from '" << PredBB->getNameStart() << "' to '" DEBUG(errs() << " Threading edge from '" << PredBB->getName() << "' to '"
<< SuccBB->getNameStart() << "' with cost: " << JumpThreadCost << SuccBB->getNameStart() << "' with cost: " << JumpThreadCost
<< ", across block:\n " << ", across block:\n "
<< *BB << "\n"; << *BB << "\n");
// Jump Threading can not update SSA properties correctly if the values // Jump Threading can not update SSA properties correctly if the values
// defined in the duplicated block are used outside of the block itself. For // defined in the duplicated block are used outside of the block itself. For

View File

@ -186,7 +186,7 @@ public:
/// MarkBlockExecutable - This method can be used by clients to mark all of /// MarkBlockExecutable - This method can be used by clients to mark all of
/// the blocks that are known to be intrinsically live in the processed unit. /// the blocks that are known to be intrinsically live in the processed unit.
void MarkBlockExecutable(BasicBlock *BB) { void MarkBlockExecutable(BasicBlock *BB) {
DOUT << "Marking Block Executable: " << BB->getNameStart() << "\n"; DEBUG(errs() << "Marking Block Executable: " << BB->getName() << "\n");
BBExecutable.insert(BB); // Basic block is executable! BBExecutable.insert(BB); // Basic block is executable!
BBWorkList.push_back(BB); // Add the block to the work list! BBWorkList.push_back(BB); // Add the block to the work list!
} }
@ -262,14 +262,14 @@ private:
// //
inline void markConstant(LatticeVal &IV, Value *V, Constant *C) { inline void markConstant(LatticeVal &IV, Value *V, Constant *C) {
if (IV.markConstant(C)) { if (IV.markConstant(C)) {
DOUT << "markConstant: " << *C << ": " << *V; DEBUG(errs() << "markConstant: " << *C << ": " << *V);
InstWorkList.push_back(V); InstWorkList.push_back(V);
} }
} }
inline void markForcedConstant(LatticeVal &IV, Value *V, Constant *C) { inline void markForcedConstant(LatticeVal &IV, Value *V, Constant *C) {
IV.markForcedConstant(C); IV.markForcedConstant(C);
DOUT << "markForcedConstant: " << *C << ": " << *V; DEBUG(errs() << "markForcedConstant: " << *C << ": " << *V);
InstWorkList.push_back(V); InstWorkList.push_back(V);
} }
@ -339,8 +339,8 @@ private:
return; // This edge is already known to be executable! return; // This edge is already known to be executable!
if (BBExecutable.count(Dest)) { if (BBExecutable.count(Dest)) {
DOUT << "Marking Edge Executable: " << Source->getNameStart() DEBUG(errs() << "Marking Edge Executable: " << Source->getName()
<< " -> " << Dest->getNameStart() << "\n"; << " -> " << Dest->getName() << "\n");
// The destination is already executable, but we just made an edge // The destination is already executable, but we just made an edge
// feasible that wasn't before. Revisit the PHI nodes in the block // feasible that wasn't before. Revisit the PHI nodes in the block
@ -1278,7 +1278,7 @@ void SCCPSolver::Solve() {
Value *I = OverdefinedInstWorkList.back(); Value *I = OverdefinedInstWorkList.back();
OverdefinedInstWorkList.pop_back(); OverdefinedInstWorkList.pop_back();
DOUT << "\nPopped off OI-WL: " << *I; DEBUG(errs() << "\nPopped off OI-WL: " << *I);
// "I" got into the work list because it either made the transition from // "I" got into the work list because it either made the transition from
// bottom to constant // bottom to constant
@ -1296,7 +1296,7 @@ void SCCPSolver::Solve() {
Value *I = InstWorkList.back(); Value *I = InstWorkList.back();
InstWorkList.pop_back(); InstWorkList.pop_back();
DOUT << "\nPopped off I-WL: " << *I; DEBUG(errs() << "\nPopped off I-WL: " << *I);
// "I" got into the work list because it either made the transition from // "I" got into the work list because it either made the transition from
// bottom to constant // bottom to constant
@ -1316,7 +1316,7 @@ void SCCPSolver::Solve() {
BasicBlock *BB = BBWorkList.back(); BasicBlock *BB = BBWorkList.back();
BBWorkList.pop_back(); BBWorkList.pop_back();
DOUT << "\nPopped off BBWL: " << *BB; DEBUG(errs() << "\nPopped off BBWL: " << *BB);
// Notify all instructions in this basic block that they are newly // Notify all instructions in this basic block that they are newly
// executable. // executable.
@ -1536,7 +1536,7 @@ FunctionPass *llvm::createSCCPPass() {
// and return true if the function was modified. // and return true if the function was modified.
// //
bool SCCP::runOnFunction(Function &F) { bool SCCP::runOnFunction(Function &F) {
DOUT << "SCCP on function '" << F.getNameStart() << "'\n"; DEBUG(errs() << "SCCP on function '" << F.getName() << "'\n");
SCCPSolver Solver; SCCPSolver Solver;
Solver.setContext(&F.getContext()); Solver.setContext(&F.getContext());
@ -1551,7 +1551,7 @@ bool SCCP::runOnFunction(Function &F) {
bool ResolvedUndefs = true; bool ResolvedUndefs = true;
while (ResolvedUndefs) { while (ResolvedUndefs) {
Solver.Solve(); Solver.Solve();
DOUT << "RESOLVING UNDEFs\n"; DEBUG(errs() << "RESOLVING UNDEFs\n");
ResolvedUndefs = Solver.ResolvedUndefsIn(F); ResolvedUndefs = Solver.ResolvedUndefsIn(F);
} }
@ -1566,7 +1566,7 @@ bool SCCP::runOnFunction(Function &F) {
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
if (!Solver.isBlockExecutable(BB)) { if (!Solver.isBlockExecutable(BB)) {
DOUT << " BasicBlock Dead:" << *BB; DEBUG(errs() << " BasicBlock Dead:" << *BB);
++NumDeadBlocks; ++NumDeadBlocks;
// Delete the instructions backwards, as it has a reduced likelihood of // Delete the instructions backwards, as it has a reduced likelihood of
@ -1599,7 +1599,7 @@ bool SCCP::runOnFunction(Function &F) {
Constant *Const = IV.isConstant() Constant *Const = IV.isConstant()
? IV.getConstant() : F.getContext().getUndef(Inst->getType()); ? IV.getConstant() : F.getContext().getUndef(Inst->getType());
DOUT << " Constant: " << *Const << " = " << *Inst; DEBUG(errs() << " Constant: " << *Const << " = " << *Inst);
// Replaces all of the uses of a variable with uses of the constant. // Replaces all of the uses of a variable with uses of the constant.
Inst->replaceAllUsesWith(Const); Inst->replaceAllUsesWith(Const);
@ -1695,7 +1695,7 @@ bool IPSCCP::runOnModule(Module &M) {
while (ResolvedUndefs) { while (ResolvedUndefs) {
Solver.Solve(); Solver.Solve();
DOUT << "RESOLVING UNDEFS\n"; DEBUG(errs() << "RESOLVING UNDEFS\n");
ResolvedUndefs = false; ResolvedUndefs = false;
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
ResolvedUndefs |= Solver.ResolvedUndefsIn(*F); ResolvedUndefs |= Solver.ResolvedUndefsIn(*F);
@ -1718,7 +1718,7 @@ bool IPSCCP::runOnModule(Module &M) {
if (IV.isConstant() || IV.isUndefined()) { if (IV.isConstant() || IV.isUndefined()) {
Constant *CST = IV.isConstant() ? Constant *CST = IV.isConstant() ?
IV.getConstant() : Context->getUndef(AI->getType()); IV.getConstant() : Context->getUndef(AI->getType());
DOUT << "*** Arg " << *AI << " = " << *CST <<"\n"; DEBUG(errs() << "*** Arg " << *AI << " = " << *CST <<"\n");
// Replaces all of the uses of a variable with uses of the // Replaces all of the uses of a variable with uses of the
// constant. // constant.
@ -1729,7 +1729,7 @@ bool IPSCCP::runOnModule(Module &M) {
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
if (!Solver.isBlockExecutable(BB)) { if (!Solver.isBlockExecutable(BB)) {
DOUT << " BasicBlock Dead:" << *BB; DEBUG(errs() << " BasicBlock Dead:" << *BB);
++IPNumDeadBlocks; ++IPNumDeadBlocks;
// Delete the instructions backwards, as it has a reduced likelihood of // Delete the instructions backwards, as it has a reduced likelihood of
@ -1774,7 +1774,7 @@ bool IPSCCP::runOnModule(Module &M) {
Constant *Const = IV.isConstant() Constant *Const = IV.isConstant()
? IV.getConstant() : Context->getUndef(Inst->getType()); ? IV.getConstant() : Context->getUndef(Inst->getType());
DOUT << " Constant: " << *Const << " = " << *Inst; DEBUG(errs() << " Constant: " << *Const << " = " << *Inst);
// Replaces all of the uses of a variable with uses of the // Replaces all of the uses of a variable with uses of the
// constant. // constant.
@ -1858,7 +1858,7 @@ bool IPSCCP::runOnModule(Module &M) {
GlobalVariable *GV = I->first; GlobalVariable *GV = I->first;
assert(!I->second.isOverdefined() && assert(!I->second.isOverdefined() &&
"Overdefined values should have been taken out of the map!"); "Overdefined values should have been taken out of the map!");
DOUT << "Found that GV '" << GV->getNameStart() << "' is constant!\n"; DEBUG(errs() << "Found that GV '" << GV->getName() << "' is constant!\n");
while (!GV->use_empty()) { while (!GV->use_empty()) {
StoreInst *SI = cast<StoreInst>(GV->use_back()); StoreInst *SI = cast<StoreInst>(GV->use_back());
SI->eraseFromParent(); SI->eraseFromParent();

View File

@ -1127,7 +1127,7 @@ struct VISIBILITY_HIDDEN UnaryDoubleFPOpt : public LibCallOptimization {
// floor((double)floatval) -> (double)floorf(floatval) // floor((double)floatval) -> (double)floorf(floatval)
Value *V = Cast->getOperand(0); Value *V = Cast->getOperand(0);
V = EmitUnaryFloatFnCall(V, Callee->getNameStart(), B); V = EmitUnaryFloatFnCall(V, Callee->getName().data(), B);
return B.CreateFPExt(V, Type::DoubleTy); return B.CreateFPExt(V, Type::DoubleTy);
} }
}; };
@ -1736,40 +1736,39 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
if (!F.isDeclaration()) if (!F.isDeclaration())
continue; continue;
unsigned NameLen = F.getNameLen(); if (!F.hasName())
if (!NameLen)
continue; continue;
const FunctionType *FTy = F.getFunctionType(); const FunctionType *FTy = F.getFunctionType();
const char *NameStr = F.getNameStart(); StringRef Name = F.getName();
switch (NameStr[0]) { switch (Name[0]) {
case 's': case 's':
if (NameLen == 6 && !strcmp(NameStr, "strlen")) { if (Name == "strlen") {
if (FTy->getNumParams() != 1 || if (FTy->getNumParams() != 1 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
setOnlyReadsMemory(F); setOnlyReadsMemory(F);
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if ((NameLen == 6 && !strcmp(NameStr, "strcpy")) || } else if (Name == "strcpy" ||
(NameLen == 6 && !strcmp(NameStr, "stpcpy")) || Name == "stpcpy" ||
(NameLen == 6 && !strcmp(NameStr, "strcat")) || Name == "strcat" ||
(NameLen == 6 && !strcmp(NameStr, "strtol")) || Name == "strtol" ||
(NameLen == 6 && !strcmp(NameStr, "strtod")) || Name == "strtod" ||
(NameLen == 6 && !strcmp(NameStr, "strtof")) || Name == "strtof" ||
(NameLen == 7 && !strcmp(NameStr, "strtoul")) || Name == "strtoul" ||
(NameLen == 7 && !strcmp(NameStr, "strtoll")) || Name == "strtoll" ||
(NameLen == 7 && !strcmp(NameStr, "strtold")) || Name == "strtold" ||
(NameLen == 7 && !strcmp(NameStr, "strncat")) || Name == "strncat" ||
(NameLen == 7 && !strcmp(NameStr, "strncpy")) || Name == "strncpy" ||
(NameLen == 8 && !strcmp(NameStr, "strtoull"))) { Name == "strtoull") {
if (FTy->getNumParams() < 2 || if (FTy->getNumParams() < 2 ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 7 && !strcmp(NameStr, "strxfrm")) { } else if (Name == "strxfrm") {
if (FTy->getNumParams() != 3 || if (FTy->getNumParams() != 3 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
@ -1777,13 +1776,13 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if ((NameLen == 6 && !strcmp(NameStr, "strcmp")) || } else if (Name == "strcmp" ||
(NameLen == 6 && !strcmp(NameStr, "strspn")) || Name == "strspn" ||
(NameLen == 7 && !strcmp(NameStr, "strncmp")) || Name == "strncmp" ||
(NameLen == 7 && !strcmp(NameStr, "strcspn")) || Name ==" strcspn" ||
(NameLen == 7 && !strcmp(NameStr, "strcoll")) || Name == "strcoll" ||
(NameLen == 10 && !strcmp(NameStr, "strcasecmp")) || Name == "strcasecmp" ||
(NameLen == 11 && !strcmp(NameStr, "strncasecmp"))) { Name == "strncasecmp") {
if (FTy->getNumParams() < 2 || if (FTy->getNumParams() < 2 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
@ -1792,31 +1791,31 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if ((NameLen == 6 && !strcmp(NameStr, "strstr")) || } else if (Name == "strstr" ||
(NameLen == 7 && !strcmp(NameStr, "strpbrk"))) { Name == "strpbrk") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
continue; continue;
setOnlyReadsMemory(F); setOnlyReadsMemory(F);
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if ((NameLen == 6 && !strcmp(NameStr, "strtok")) || } else if (Name == "strtok" ||
(NameLen == 8 && !strcmp(NameStr, "strtok_r"))) { Name == "strtok_r") {
if (FTy->getNumParams() < 2 || if (FTy->getNumParams() < 2 ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if ((NameLen == 5 && !strcmp(NameStr, "scanf")) || } else if (Name == "scanf" ||
(NameLen == 6 && !strcmp(NameStr, "setbuf")) || Name == "setbuf" ||
(NameLen == 7 && !strcmp(NameStr, "setvbuf"))) { Name == "setvbuf") {
if (FTy->getNumParams() < 1 || if (FTy->getNumParams() < 1 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if ((NameLen == 6 && !strcmp(NameStr, "strdup")) || } else if (Name == "strdup" ||
(NameLen == 7 && !strcmp(NameStr, "strndup"))) { Name == "strndup") {
if (FTy->getNumParams() < 1 || if (FTy->getNumParams() < 1 ||
!isa<PointerType>(FTy->getReturnType()) || !isa<PointerType>(FTy->getReturnType()) ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
@ -1824,10 +1823,10 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotAlias(F, 0); setDoesNotAlias(F, 0);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if ((NameLen == 4 && !strcmp(NameStr, "stat")) || } else if (Name == "stat" ||
(NameLen == 6 && !strcmp(NameStr, "sscanf")) || Name == "sscanf" ||
(NameLen == 7 && !strcmp(NameStr, "sprintf")) || Name == "sprintf" ||
(NameLen == 7 && !strcmp(NameStr, "statvfs"))) { Name == "statvfs") {
if (FTy->getNumParams() < 2 || if (FTy->getNumParams() < 2 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
@ -1835,7 +1834,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 8 && !strcmp(NameStr, "snprintf")) { } else if (Name == "snprintf") {
if (FTy->getNumParams() != 3 || if (FTy->getNumParams() != 3 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(2))) !isa<PointerType>(FTy->getParamType(2)))
@ -1843,7 +1842,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setDoesNotCapture(F, 3); setDoesNotCapture(F, 3);
} else if (NameLen == 9 && !strcmp(NameStr, "setitimer")) { } else if (Name == "setitimer") {
if (FTy->getNumParams() != 3 || if (FTy->getNumParams() != 3 ||
!isa<PointerType>(FTy->getParamType(1)) || !isa<PointerType>(FTy->getParamType(1)) ||
!isa<PointerType>(FTy->getParamType(2))) !isa<PointerType>(FTy->getParamType(2)))
@ -1851,7 +1850,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
setDoesNotCapture(F, 3); setDoesNotCapture(F, 3);
} else if (NameLen == 6 && !strcmp(NameStr, "system")) { } else if (Name == "system") {
if (FTy->getNumParams() != 1 || if (FTy->getNumParams() != 1 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
@ -1860,7 +1859,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 'm': case 'm':
if (NameLen == 6 && !strcmp(NameStr, "memcmp")) { if (Name == "memcmp") {
if (FTy->getNumParams() != 3 || if (FTy->getNumParams() != 3 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
@ -1869,29 +1868,29 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if ((NameLen == 6 && !strcmp(NameStr, "memchr")) || } else if (Name == "memchr" ||
(NameLen == 7 && !strcmp(NameStr, "memrchr"))) { Name == "memrchr") {
if (FTy->getNumParams() != 3) if (FTy->getNumParams() != 3)
continue; continue;
setOnlyReadsMemory(F); setOnlyReadsMemory(F);
setDoesNotThrow(F); setDoesNotThrow(F);
} else if ((NameLen == 4 && !strcmp(NameStr, "modf")) || } else if (Name == "modf" ||
(NameLen == 5 && !strcmp(NameStr, "modff")) || Name == "modff" ||
(NameLen == 5 && !strcmp(NameStr, "modfl")) || Name == "modfl" ||
(NameLen == 6 && !strcmp(NameStr, "memcpy")) || Name == "memcpy" ||
(NameLen == 7 && !strcmp(NameStr, "memccpy")) || Name == "memccpy" ||
(NameLen == 7 && !strcmp(NameStr, "memmove"))) { Name == "memmove") {
if (FTy->getNumParams() < 2 || if (FTy->getNumParams() < 2 ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 8 && !strcmp(NameStr, "memalign")) { } else if (Name == "memalign") {
if (!isa<PointerType>(FTy->getReturnType())) if (!isa<PointerType>(FTy->getReturnType()))
continue; continue;
setDoesNotAlias(F, 0); setDoesNotAlias(F, 0);
} else if ((NameLen == 5 && !strcmp(NameStr, "mkdir")) || } else if (Name == "mkdir" ||
(NameLen == 6 && !strcmp(NameStr, "mktime"))) { Name == "mktime") {
if (FTy->getNumParams() == 0 || if (FTy->getNumParams() == 0 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
@ -1900,7 +1899,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 'r': case 'r':
if (NameLen == 7 && !strcmp(NameStr, "realloc")) { if (Name == "realloc") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getReturnType())) !isa<PointerType>(FTy->getReturnType()))
@ -1908,23 +1907,23 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotAlias(F, 0); setDoesNotAlias(F, 0);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if (NameLen == 4 && !strcmp(NameStr, "read")) { } else if (Name == "read") {
if (FTy->getNumParams() != 3 || if (FTy->getNumParams() != 3 ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
continue; continue;
// May throw; "read" is a valid pthread cancellation point. // May throw; "read" is a valid pthread cancellation point.
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if ((NameLen == 5 && !strcmp(NameStr, "rmdir")) || } else if (Name == "rmdir" ||
(NameLen == 6 && !strcmp(NameStr, "rewind")) || Name == "rewind" ||
(NameLen == 6 && !strcmp(NameStr, "remove")) || Name == "remove" ||
(NameLen == 8 && !strcmp(NameStr, "realpath"))) { Name == "realpath") {
if (FTy->getNumParams() < 1 || if (FTy->getNumParams() < 1 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if ((NameLen == 6 && !strcmp(NameStr, "rename")) || } else if (Name == "rename" ||
(NameLen == 8 && !strcmp(NameStr, "readlink"))) { Name == "readlink") {
if (FTy->getNumParams() < 2 || if (FTy->getNumParams() < 2 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
@ -1935,7 +1934,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 'w': case 'w':
if (NameLen == 5 && !strcmp(NameStr, "write")) { if (Name == "write") {
if (FTy->getNumParams() != 3 || if (FTy->getNumParams() != 3 ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
continue; continue;
@ -1944,7 +1943,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 'b': case 'b':
if (NameLen == 5 && !strcmp(NameStr, "bcopy")) { if (Name == "bcopy") {
if (FTy->getNumParams() != 3 || if (FTy->getNumParams() != 3 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
@ -1952,7 +1951,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 4 && !strcmp(NameStr, "bcmp")) { } else if (Name == "bcmp") {
if (FTy->getNumParams() != 3 || if (FTy->getNumParams() != 3 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
@ -1961,7 +1960,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setOnlyReadsMemory(F); setOnlyReadsMemory(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 5 && !strcmp(NameStr, "bzero")) { } else if (Name == "bzero") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
@ -1970,17 +1969,17 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 'c': case 'c':
if (NameLen == 6 && !strcmp(NameStr, "calloc")) { if (Name == "calloc") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getReturnType())) !isa<PointerType>(FTy->getReturnType()))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotAlias(F, 0); setDoesNotAlias(F, 0);
} else if ((NameLen == 5 && !strcmp(NameStr, "chmod")) || } else if (Name == "chmod" ||
(NameLen == 5 && !strcmp(NameStr, "chown")) || Name == "chown" ||
(NameLen == 7 && !strcmp(NameStr, "ctermid")) || Name == "ctermid" ||
(NameLen == 8 && !strcmp(NameStr, "clearerr")) || Name == "clearerr" ||
(NameLen == 8 && !strcmp(NameStr, "closedir"))) { Name == "closedir") {
if (FTy->getNumParams() == 0 || if (FTy->getNumParams() == 0 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
@ -1989,17 +1988,17 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 'a': case 'a':
if ((NameLen == 4 && !strcmp(NameStr, "atoi")) || if (Name == "atoi" ||
(NameLen == 4 && !strcmp(NameStr, "atol")) || Name == "atol" ||
(NameLen == 4 && !strcmp(NameStr, "atof")) || Name == "atof" ||
(NameLen == 5 && !strcmp(NameStr, "atoll"))) { Name == "atoll") {
if (FTy->getNumParams() != 1 || if (FTy->getNumParams() != 1 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setOnlyReadsMemory(F); setOnlyReadsMemory(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if (NameLen == 6 && !strcmp(NameStr, "access")) { } else if (Name == "access") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
@ -2008,7 +2007,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 'f': case 'f':
if (NameLen == 5 && !strcmp(NameStr, "fopen")) { if (Name == "fopen") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getReturnType()) || !isa<PointerType>(FTy->getReturnType()) ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
@ -2018,7 +2017,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotAlias(F, 0); setDoesNotAlias(F, 0);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 6 && !strcmp(NameStr, "fdopen")) { } else if (Name == "fdopen") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getReturnType()) || !isa<PointerType>(FTy->getReturnType()) ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
@ -2026,52 +2025,52 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotAlias(F, 0); setDoesNotAlias(F, 0);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if ((NameLen == 4 && !strcmp(NameStr, "feof")) || } else if (Name == "feof" ||
(NameLen == 4 && !strcmp(NameStr, "free")) || Name == "free" ||
(NameLen == 5 && !strcmp(NameStr, "fseek")) || Name == "fseek" ||
(NameLen == 5 && !strcmp(NameStr, "ftell")) || Name == "ftell" ||
(NameLen == 5 && !strcmp(NameStr, "fgetc")) || Name == "fgetc" ||
(NameLen == 6 && !strcmp(NameStr, "fseeko")) || Name == "fseeko" ||
(NameLen == 6 && !strcmp(NameStr, "ftello")) || Name == "ftello" ||
(NameLen == 6 && !strcmp(NameStr, "fileno")) || Name == "fileno" ||
(NameLen == 6 && !strcmp(NameStr, "fflush")) || Name == "fflush" ||
(NameLen == 6 && !strcmp(NameStr, "fclose")) || Name == "fclose" ||
(NameLen == 7 && !strcmp(NameStr, "fsetpos")) || Name == "fsetpos" ||
(NameLen == 9 && !strcmp(NameStr, "flockfile")) || Name == "flockfile" ||
(NameLen == 11 && !strcmp(NameStr, "funlockfile")) || Name == "funlockfile" ||
(NameLen == 12 && !strcmp(NameStr, "ftrylockfile"))) { Name == "ftrylockfile") {
if (FTy->getNumParams() == 0 || if (FTy->getNumParams() == 0 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if (NameLen == 6 && !strcmp(NameStr, "ferror")) { } else if (Name == "ferror") {
if (FTy->getNumParams() != 1 || if (FTy->getNumParams() != 1 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setOnlyReadsMemory(F); setOnlyReadsMemory(F);
} else if ((NameLen == 5 && !strcmp(NameStr, "fputc")) || } else if (Name == "fputc" ||
(NameLen == 5 && !strcmp(NameStr, "fstat")) || Name == "fstat" ||
(NameLen == 5 && !strcmp(NameStr, "frexp")) || Name == "frexp" ||
(NameLen == 6 && !strcmp(NameStr, "frexpf")) || Name == "frexpf" ||
(NameLen == 6 && !strcmp(NameStr, "frexpl")) || Name == "frexpl" ||
(NameLen == 8 && !strcmp(NameStr, "fstatvfs"))) { Name == "fstatvfs") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 5 && !strcmp(NameStr, "fgets")) { } else if (Name == "fgets") {
if (FTy->getNumParams() != 3 || if (FTy->getNumParams() != 3 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(2))) !isa<PointerType>(FTy->getParamType(2)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 3); setDoesNotCapture(F, 3);
} else if ((NameLen == 5 && !strcmp(NameStr, "fread")) || } else if (Name == "fread" ||
(NameLen == 6 && !strcmp(NameStr, "fwrite"))) { Name == "fwrite") {
if (FTy->getNumParams() != 4 || if (FTy->getNumParams() != 4 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(3))) !isa<PointerType>(FTy->getParamType(3)))
@ -2079,10 +2078,10 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setDoesNotCapture(F, 4); setDoesNotCapture(F, 4);
} else if ((NameLen == 5 && !strcmp(NameStr, "fputs")) || } else if (Name == "fputs" ||
(NameLen == 6 && !strcmp(NameStr, "fscanf")) || Name == "fscanf" ||
(NameLen == 7 && !strcmp(NameStr, "fprintf")) || Name == "fprintf" ||
(NameLen == 7 && !strcmp(NameStr, "fgetpos"))) { Name == "fgetpos") {
if (FTy->getNumParams() < 2 || if (FTy->getNumParams() < 2 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
@ -2093,31 +2092,31 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 'g': case 'g':
if ((NameLen == 4 && !strcmp(NameStr, "getc")) || if (Name == "getc" ||
(NameLen == 10 && !strcmp(NameStr, "getlogin_r")) || Name == "getlogin_r" ||
(NameLen == 13 && !strcmp(NameStr, "getc_unlocked"))) { Name == "getc_unlocked") {
if (FTy->getNumParams() == 0 || if (FTy->getNumParams() == 0 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if (NameLen == 6 && !strcmp(NameStr, "getenv")) { } else if (Name == "getenv") {
if (FTy->getNumParams() != 1 || if (FTy->getNumParams() != 1 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setOnlyReadsMemory(F); setOnlyReadsMemory(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if ((NameLen == 4 && !strcmp(NameStr, "gets")) || } else if (Name == "gets" ||
(NameLen == 7 && !strcmp(NameStr, "getchar"))) { Name == "getchar") {
setDoesNotThrow(F); setDoesNotThrow(F);
} else if (NameLen == 9 && !strcmp(NameStr, "getitimer")) { } else if (Name == "getitimer") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 8 && !strcmp(NameStr, "getpwnam")) { } else if (Name == "getpwnam") {
if (FTy->getNumParams() != 1 || if (FTy->getNumParams() != 1 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
@ -2126,22 +2125,22 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 'u': case 'u':
if (NameLen == 6 && !strcmp(NameStr, "ungetc")) { if (Name == "ungetc") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if ((NameLen == 5 && !strcmp(NameStr, "uname")) || } else if (Name == "uname" ||
(NameLen == 6 && !strcmp(NameStr, "unlink")) || Name == "unlink" ||
(NameLen == 8 && !strcmp(NameStr, "unsetenv"))) { Name == "unsetenv") {
if (FTy->getNumParams() != 1 || if (FTy->getNumParams() != 1 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if ((NameLen == 5 && !strcmp(NameStr, "utime")) || } else if (Name == "utime" ||
(NameLen == 6 && !strcmp(NameStr, "utimes"))) { Name == "utimes") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
@ -2152,30 +2151,30 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 'p': case 'p':
if (NameLen == 4 && !strcmp(NameStr, "putc")) { if (Name == "putc") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if ((NameLen == 4 && !strcmp(NameStr, "puts")) || } else if (Name == "puts" ||
(NameLen == 6 && !strcmp(NameStr, "printf")) || Name == "printf" ||
(NameLen == 6 && !strcmp(NameStr, "perror"))) { Name == "perror") {
if (FTy->getNumParams() != 1 || if (FTy->getNumParams() != 1 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if ((NameLen == 5 && !strcmp(NameStr, "pread")) || } else if (Name == "pread" ||
(NameLen == 6 && !strcmp(NameStr, "pwrite"))) { Name == "pwrite") {
if (FTy->getNumParams() != 4 || if (FTy->getNumParams() != 4 ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
continue; continue;
// May throw; these are valid pthread cancellation points. // May throw; these are valid pthread cancellation points.
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 7 && !strcmp(NameStr, "putchar")) { } else if (Name == "putchar") {
setDoesNotThrow(F); setDoesNotThrow(F);
} else if (NameLen == 5 && !strcmp(NameStr, "popen")) { } else if (Name == "popen") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getReturnType()) || !isa<PointerType>(FTy->getReturnType()) ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
@ -2185,7 +2184,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotAlias(F, 0); setDoesNotAlias(F, 0);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 6 && !strcmp(NameStr, "pclose")) { } else if (Name == "pclose") {
if (FTy->getNumParams() != 1 || if (FTy->getNumParams() != 1 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
@ -2194,14 +2193,14 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 'v': case 'v':
if (NameLen == 6 && !strcmp(NameStr, "vscanf")) { if (Name == "vscanf") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if ((NameLen == 7 && !strcmp(NameStr, "vsscanf")) || } else if (Name == "vsscanf" ||
(NameLen == 7 && !strcmp(NameStr, "vfscanf"))) { Name == "vfscanf") {
if (FTy->getNumParams() != 3 || if (FTy->getNumParams() != 3 ||
!isa<PointerType>(FTy->getParamType(1)) || !isa<PointerType>(FTy->getParamType(1)) ||
!isa<PointerType>(FTy->getParamType(2))) !isa<PointerType>(FTy->getParamType(2)))
@ -2209,19 +2208,19 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 6 && !strcmp(NameStr, "valloc")) { } else if (Name == "valloc") {
if (!isa<PointerType>(FTy->getReturnType())) if (!isa<PointerType>(FTy->getReturnType()))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotAlias(F, 0); setDoesNotAlias(F, 0);
} else if (NameLen == 7 && !strcmp(NameStr, "vprintf")) { } else if (Name == "vprintf") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if ((NameLen == 8 && !strcmp(NameStr, "vfprintf")) || } else if (Name == "vfprintf" ||
(NameLen == 8 && !strcmp(NameStr, "vsprintf"))) { Name == "vsprintf") {
if (FTy->getNumParams() != 3 || if (FTy->getNumParams() != 3 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
@ -2229,7 +2228,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 9 && !strcmp(NameStr, "vsnprintf")) { } else if (Name == "vsnprintf") {
if (FTy->getNumParams() != 4 || if (FTy->getNumParams() != 4 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(2))) !isa<PointerType>(FTy->getParamType(2)))
@ -2240,13 +2239,13 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 'o': case 'o':
if (NameLen == 4 && !strcmp(NameStr, "open")) { if (Name == "open") {
if (FTy->getNumParams() < 2 || if (FTy->getNumParams() < 2 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
// May throw; "open" is a valid pthread cancellation point. // May throw; "open" is a valid pthread cancellation point.
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if (NameLen == 7 && !strcmp(NameStr, "opendir")) { } else if (Name == "opendir") {
if (FTy->getNumParams() != 1 || if (FTy->getNumParams() != 1 ||
!isa<PointerType>(FTy->getReturnType()) || !isa<PointerType>(FTy->getReturnType()) ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
@ -2257,12 +2256,12 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 't': case 't':
if (NameLen == 7 && !strcmp(NameStr, "tmpfile")) { if (Name == "tmpfile") {
if (!isa<PointerType>(FTy->getReturnType())) if (!isa<PointerType>(FTy->getReturnType()))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotAlias(F, 0); setDoesNotAlias(F, 0);
} else if (NameLen == 5 && !strcmp(NameStr, "times")) { } else if (Name == "times") {
if (FTy->getNumParams() != 1 || if (FTy->getNumParams() != 1 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
@ -2271,21 +2270,21 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 'h': case 'h':
if ((NameLen == 5 && !strcmp(NameStr, "htonl")) || if (Name == "htonl" ||
(NameLen == 5 && !strcmp(NameStr, "htons"))) { Name == "htons") {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotAccessMemory(F); setDoesNotAccessMemory(F);
} }
break; break;
case 'n': case 'n':
if ((NameLen == 5 && !strcmp(NameStr, "ntohl")) || if (Name == "ntohl" ||
(NameLen == 5 && !strcmp(NameStr, "ntohs"))) { Name == "ntohs") {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotAccessMemory(F); setDoesNotAccessMemory(F);
} }
break; break;
case 'l': case 'l':
if (NameLen == 5 && !strcmp(NameStr, "lstat")) { if (Name == "lstat") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
@ -2293,7 +2292,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 6 && !strcmp(NameStr, "lchown")) { } else if (Name == "lchown") {
if (FTy->getNumParams() != 3 || if (FTy->getNumParams() != 3 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
@ -2302,7 +2301,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 'q': case 'q':
if (NameLen == 5 && !strcmp(NameStr, "qsort")) { if (Name == "qsort") {
if (FTy->getNumParams() != 4 || if (FTy->getNumParams() != 4 ||
!isa<PointerType>(FTy->getParamType(3))) !isa<PointerType>(FTy->getParamType(3)))
continue; continue;
@ -2311,8 +2310,8 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case '_': case '_':
if ((NameLen == 8 && !strcmp(NameStr, "__strdup")) || if (Name == "__strdup" ||
(NameLen == 9 && !strcmp(NameStr, "__strndup"))) { Name == "__strndup") {
if (FTy->getNumParams() < 1 || if (FTy->getNumParams() < 1 ||
!isa<PointerType>(FTy->getReturnType()) || !isa<PointerType>(FTy->getReturnType()) ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
@ -2320,19 +2319,19 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotAlias(F, 0); setDoesNotAlias(F, 0);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if (NameLen == 10 && !strcmp(NameStr, "__strtok_r")) { } else if (Name == "__strtok_r") {
if (FTy->getNumParams() != 3 || if (FTy->getNumParams() != 3 ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 8 && !strcmp(NameStr, "_IO_getc")) { } else if (Name == "_IO_getc") {
if (FTy->getNumParams() != 1 || if (FTy->getNumParams() != 1 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if (NameLen == 8 && !strcmp(NameStr, "_IO_putc")) { } else if (Name == "_IO_putc") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
continue; continue;
@ -2341,16 +2340,16 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
} }
break; break;
case 1: case 1:
if (NameLen == 15 && !strcmp(NameStr, "\1__isoc99_scanf")) { if (Name == "\1__isoc99_scanf") {
if (FTy->getNumParams() < 1 || if (FTy->getNumParams() < 1 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if ((NameLen == 7 && !strcmp(NameStr, "\1stat64")) || } else if (Name == "\1stat64" ||
(NameLen == 8 && !strcmp(NameStr, "\1lstat64")) || Name == "\1lstat64" ||
(NameLen == 10 && !strcmp(NameStr, "\1statvfs64")) || Name == "\1statvfs64" ||
(NameLen == 16 && !strcmp(NameStr, "\1__isoc99_sscanf"))) { Name == "\1__isoc99_sscanf") {
if (FTy->getNumParams() < 1 || if (FTy->getNumParams() < 1 ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
@ -2358,7 +2357,7 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 8 && !strcmp(NameStr, "\1fopen64")) { } else if (Name == "\1fopen64") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getReturnType()) || !isa<PointerType>(FTy->getReturnType()) ||
!isa<PointerType>(FTy->getParamType(0)) || !isa<PointerType>(FTy->getParamType(0)) ||
@ -2368,26 +2367,26 @@ bool SimplifyLibCalls::doInitialization(Module &M) {
setDoesNotAlias(F, 0); setDoesNotAlias(F, 0);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if ((NameLen == 9 && !strcmp(NameStr, "\1fseeko64")) || } else if (Name == "\1fseeko64" ||
(NameLen == 9 && !strcmp(NameStr, "\1ftello64"))) { Name == "\1ftello64") {
if (FTy->getNumParams() == 0 || if (FTy->getNumParams() == 0 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 1); setDoesNotCapture(F, 1);
} else if (NameLen == 10 && !strcmp(NameStr, "\1tmpfile64")) { } else if (Name == "\1tmpfile64") {
if (!isa<PointerType>(FTy->getReturnType())) if (!isa<PointerType>(FTy->getReturnType()))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotAlias(F, 0); setDoesNotAlias(F, 0);
} else if ((NameLen == 8 && !strcmp(NameStr, "\1fstat64")) || } else if (Name == "\1fstat64" ||
(NameLen == 11 && !strcmp(NameStr, "\1fstatvfs64"))) { Name == "\1fstatvfs64") {
if (FTy->getNumParams() != 2 || if (FTy->getNumParams() != 2 ||
!isa<PointerType>(FTy->getParamType(1))) !isa<PointerType>(FTy->getParamType(1)))
continue; continue;
setDoesNotThrow(F); setDoesNotThrow(F);
setDoesNotCapture(F, 2); setDoesNotCapture(F, 2);
} else if (NameLen == 7 && !strcmp(NameStr, "\1open64")) { } else if (Name == "\1open64") {
if (FTy->getNumParams() < 2 || if (FTy->getNumParams() < 2 ||
!isa<PointerType>(FTy->getParamType(0))) !isa<PointerType>(FTy->getParamType(0)))
continue; continue;

View File

@ -306,7 +306,7 @@ LLVMTypeRef LLVMTypeOf(LLVMValueRef Val) {
} }
const char *LLVMGetValueName(LLVMValueRef Val) { const char *LLVMGetValueName(LLVMValueRef Val) {
return unwrap(Val)->getNameStart(); return unwrap(Val)->getName().data();
} }
void LLVMSetValueName(LLVMValueRef Val, const char *Name) { void LLVMSetValueName(LLVMValueRef Val, const char *Name) {

View File

@ -135,7 +135,7 @@ public:
// Print passes managed by this manager // Print passes managed by this manager
void dumpPassStructure(unsigned Offset) { void dumpPassStructure(unsigned Offset) {
llvm::cerr << std::string(Offset*2, ' ') << "BasicBlockPass Manager\n"; llvm::errs() << std::string(Offset*2, ' ') << "BasicBlockPass Manager\n";
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
BasicBlockPass *BP = getContainedPass(Index); BasicBlockPass *BP = getContainedPass(Index);
BP->dumpPassStructure(Offset + 1); BP->dumpPassStructure(Offset + 1);
@ -275,7 +275,7 @@ public:
// Print passes managed by this manager // Print passes managed by this manager
void dumpPassStructure(unsigned Offset) { void dumpPassStructure(unsigned Offset) {
llvm::cerr << std::string(Offset*2, ' ') << "ModulePass Manager\n"; llvm::errs() << std::string(Offset*2, ' ') << "ModulePass Manager\n";
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
ModulePass *MP = getContainedPass(Index); ModulePass *MP = getContainedPass(Index);
MP->dumpPassStructure(Offset + 1); MP->dumpPassStructure(Offset + 1);
@ -604,11 +604,11 @@ void PMTopLevelManager::dumpArguments() const {
if (PassDebugging < Arguments) if (PassDebugging < Arguments)
return; return;
cerr << "Pass Arguments: "; errs() << "Pass Arguments: ";
for (SmallVector<PMDataManager *, 8>::const_iterator I = PassManagers.begin(), for (SmallVector<PMDataManager *, 8>::const_iterator I = PassManagers.begin(),
E = PassManagers.end(); I != E; ++I) E = PassManagers.end(); I != E; ++I)
(*I)->dumpPassArguments(); (*I)->dumpPassArguments();
cerr << "\n"; errs() << "\n";
} }
void PMTopLevelManager::initializeAllAnalysisInfo() { void PMTopLevelManager::initializeAllAnalysisInfo() {
@ -718,11 +718,11 @@ void PMDataManager::verifyDomInfo(Pass &P, Function &F) {
DominatorTree OtherDT; DominatorTree OtherDT;
OtherDT.getBase().recalculate(F); OtherDT.getBase().recalculate(F);
if (DT->compare(OtherDT)) { if (DT->compare(OtherDT)) {
cerr << "Dominator Information for " << F.getNameStart() << "\n"; errs() << "Dominator Information for " << F.getName() << "\n";
cerr << "Pass '" << P.getPassName() << "'\n"; errs() << "Pass '" << P.getPassName() << "'\n";
cerr << "----- Valid -----\n"; errs() << "----- Valid -----\n";
OtherDT.dump(); OtherDT.dump();
cerr << "----- Invalid -----\n"; errs() << "----- Invalid -----\n";
DT->dump(); DT->dump();
llvm_unreachable("Invalid dominator info"); llvm_unreachable("Invalid dominator info");
} }
@ -735,11 +735,11 @@ void PMDataManager::verifyDomInfo(Pass &P, Function &F) {
std::vector<BasicBlock*> DTRoots = DT->getRoots(); std::vector<BasicBlock*> DTRoots = DT->getRoots();
OtherDF.calculate(*DT, DT->getNode(DTRoots[0])); OtherDF.calculate(*DT, DT->getNode(DTRoots[0]));
if (DF->compare(OtherDF)) { if (DF->compare(OtherDF)) {
cerr << "Dominator Information for " << F.getNameStart() << "\n"; errs() << "Dominator Information for " << F.getName() << "\n";
cerr << "Pass '" << P.getPassName() << "'\n"; errs() << "Pass '" << P.getPassName() << "'\n";
cerr << "----- Valid -----\n"; errs() << "----- Valid -----\n";
OtherDF.dump(); OtherDF.dump();
cerr << "----- Invalid -----\n"; errs() << "----- Invalid -----\n";
DF->dump(); DF->dump();
llvm_unreachable("Invalid dominator info"); llvm_unreachable("Invalid dominator info");
} }
@ -761,8 +761,8 @@ void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
// Remove this analysis // Remove this analysis
if (PassDebugging >= Details) { if (PassDebugging >= Details) {
Pass *S = Info->second; Pass *S = Info->second;
cerr << " -- '" << P->getPassName() << "' is not preserving '"; errs() << " -- '" << P->getPassName() << "' is not preserving '";
cerr << S->getPassName() << "'\n"; errs() << S->getPassName() << "'\n";
} }
AvailableAnalysis.erase(Info); AvailableAnalysis.erase(Info);
} }
@ -789,7 +789,7 @@ void PMDataManager::removeNotPreservedAnalysis(Pass *P) {
} }
/// Remove analysis passes that are not used any longer /// Remove analysis passes that are not used any longer
void PMDataManager::removeDeadPasses(Pass *P, const char *Msg, void PMDataManager::removeDeadPasses(Pass *P, const StringRef &Msg,
enum PassDebuggingString DBG_STR) { enum PassDebuggingString DBG_STR) {
SmallVector<Pass *, 12> DeadPasses; SmallVector<Pass *, 12> DeadPasses;
@ -801,9 +801,9 @@ void PMDataManager::removeDeadPasses(Pass *P, const char *Msg,
TPM->collectLastUses(DeadPasses, P); TPM->collectLastUses(DeadPasses, P);
if (PassDebugging >= Details && !DeadPasses.empty()) { if (PassDebugging >= Details && !DeadPasses.empty()) {
cerr << " -*- '" << P->getPassName(); errs() << " -*- '" << P->getPassName();
cerr << "' is the last user of following pass instances."; errs() << "' is the last user of following pass instances.";
cerr << " Free these instances\n"; errs() << " Free these instances\n";
} }
for (SmallVector<Pass *, 12>::iterator I = DeadPasses.begin(), for (SmallVector<Pass *, 12>::iterator I = DeadPasses.begin(),
@ -995,7 +995,7 @@ void PMDataManager::dumpLastUses(Pass *P, unsigned Offset) const{
for (SmallVector<Pass *, 12>::iterator I = LUses.begin(), for (SmallVector<Pass *, 12>::iterator I = LUses.begin(),
E = LUses.end(); I != E; ++I) { E = LUses.end(); I != E; ++I) {
llvm::cerr << "--" << std::string(Offset*2, ' '); llvm::errs() << "--" << std::string(Offset*2, ' ');
(*I)->dumpPassStructure(0); (*I)->dumpPassStructure(0);
} }
} }
@ -1008,44 +1008,44 @@ void PMDataManager::dumpPassArguments() const {
else else
if (const PassInfo *PI = (*I)->getPassInfo()) if (const PassInfo *PI = (*I)->getPassInfo())
if (!PI->isAnalysisGroup()) if (!PI->isAnalysisGroup())
cerr << " -" << PI->getPassArgument(); errs() << " -" << PI->getPassArgument();
} }
} }
void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1, void PMDataManager::dumpPassInfo(Pass *P, enum PassDebuggingString S1,
enum PassDebuggingString S2, enum PassDebuggingString S2,
const char *Msg) { const StringRef &Msg) {
if (PassDebugging < Executions) if (PassDebugging < Executions)
return; return;
cerr << (void*)this << std::string(getDepth()*2+1, ' '); errs() << (void*)this << std::string(getDepth()*2+1, ' ');
switch (S1) { switch (S1) {
case EXECUTION_MSG: case EXECUTION_MSG:
cerr << "Executing Pass '" << P->getPassName(); errs() << "Executing Pass '" << P->getPassName();
break; break;
case MODIFICATION_MSG: case MODIFICATION_MSG:
cerr << "Made Modification '" << P->getPassName(); errs() << "Made Modification '" << P->getPassName();
break; break;
case FREEING_MSG: case FREEING_MSG:
cerr << " Freeing Pass '" << P->getPassName(); errs() << " Freeing Pass '" << P->getPassName();
break; break;
default: default:
break; break;
} }
switch (S2) { switch (S2) {
case ON_BASICBLOCK_MSG: case ON_BASICBLOCK_MSG:
cerr << "' on BasicBlock '" << Msg << "'...\n"; errs() << "' on BasicBlock '" << Msg << "'...\n";
break; break;
case ON_FUNCTION_MSG: case ON_FUNCTION_MSG:
cerr << "' on Function '" << Msg << "'...\n"; errs() << "' on Function '" << Msg << "'...\n";
break; break;
case ON_MODULE_MSG: case ON_MODULE_MSG:
cerr << "' on Module '" << Msg << "'...\n"; errs() << "' on Module '" << Msg << "'...\n";
break; break;
case ON_LOOP_MSG: case ON_LOOP_MSG:
cerr << "' on Loop " << Msg << "'...\n"; errs() << "' on Loop " << Msg << "'...\n";
break; break;
case ON_CG_MSG: case ON_CG_MSG:
cerr << "' on Call Graph " << Msg << "'...\n"; errs() << "' on Call Graph " << Msg << "'...\n";
break; break;
default: default:
break; break;
@ -1070,17 +1070,17 @@ void PMDataManager::dumpPreservedSet(const Pass *P) const {
dumpAnalysisUsage("Preserved", P, analysisUsage.getPreservedSet()); dumpAnalysisUsage("Preserved", P, analysisUsage.getPreservedSet());
} }
void PMDataManager::dumpAnalysisUsage(const char *Msg, const Pass *P, void PMDataManager::dumpAnalysisUsage(const StringRef &Msg, const Pass *P,
const AnalysisUsage::VectorType &Set) const { const AnalysisUsage::VectorType &Set) const {
assert(PassDebugging >= Details); assert(PassDebugging >= Details);
if (Set.empty()) if (Set.empty())
return; return;
cerr << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:"; errs() << (void*)P << std::string(getDepth()*2+3, ' ') << Msg << " Analyses:";
for (unsigned i = 0; i != Set.size(); ++i) { for (unsigned i = 0; i != Set.size(); ++i) {
if (i) cerr << ","; if (i) errs() << ",";
cerr << " " << Set[i]->getPassName(); errs() << " " << Set[i]->getPassName();
} }
cerr << "\n"; errs() << "\n";
} }
/// Add RequiredPass into list of lower level passes required by pass P. /// Add RequiredPass into list of lower level passes required by pass P.
@ -1103,8 +1103,8 @@ void PMDataManager::addLowerLevelRequiredPass(Pass *P, Pass *RequiredPass) {
// checks whether any lower level manager will be able to provide this // checks whether any lower level manager will be able to provide this
// analysis info on demand or not. // analysis info on demand or not.
#ifndef NDEBUG #ifndef NDEBUG
cerr << "Unable to schedule '" << RequiredPass->getPassName(); errs() << "Unable to schedule '" << RequiredPass->getPassName();
cerr << "' required by '" << P->getPassName() << "'\n"; errs() << "' required by '" << P->getPassName() << "'\n";
#endif #endif
llvm_unreachable("Unable to schedule pass"); llvm_unreachable("Unable to schedule pass");
} }
@ -1144,7 +1144,7 @@ bool BBPassManager::runOnFunction(Function &F) {
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
BasicBlockPass *BP = getContainedPass(Index); BasicBlockPass *BP = getContainedPass(Index);
dumpPassInfo(BP, EXECUTION_MSG, ON_BASICBLOCK_MSG, I->getNameStart()); dumpPassInfo(BP, EXECUTION_MSG, ON_BASICBLOCK_MSG, I->getName());
dumpRequiredSet(BP); dumpRequiredSet(BP);
initializeAnalysisImpl(BP); initializeAnalysisImpl(BP);
@ -1160,13 +1160,13 @@ bool BBPassManager::runOnFunction(Function &F) {
if (Changed) if (Changed)
dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG, dumpPassInfo(BP, MODIFICATION_MSG, ON_BASICBLOCK_MSG,
I->getNameStart()); I->getName());
dumpPreservedSet(BP); dumpPreservedSet(BP);
verifyPreservedAnalysis(BP); verifyPreservedAnalysis(BP);
removeNotPreservedAnalysis(BP); removeNotPreservedAnalysis(BP);
recordAvailableAnalysis(BP); recordAvailableAnalysis(BP);
removeDeadPasses(BP, I->getNameStart(), ON_BASICBLOCK_MSG); removeDeadPasses(BP, I->getName(), ON_BASICBLOCK_MSG);
} }
return Changed |= doFinalization(F); return Changed |= doFinalization(F);
@ -1336,7 +1336,7 @@ bool FunctionPassManagerImpl::run(Function &F) {
char FPPassManager::ID = 0; char FPPassManager::ID = 0;
/// Print passes managed by this manager /// Print passes managed by this manager
void FPPassManager::dumpPassStructure(unsigned Offset) { void FPPassManager::dumpPassStructure(unsigned Offset) {
llvm::cerr << std::string(Offset*2, ' ') << "FunctionPass Manager\n"; llvm::errs() << std::string(Offset*2, ' ') << "FunctionPass Manager\n";
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
FunctionPass *FP = getContainedPass(Index); FunctionPass *FP = getContainedPass(Index);
FP->dumpPassStructure(Offset + 1); FP->dumpPassStructure(Offset + 1);
@ -1360,7 +1360,7 @@ bool FPPassManager::runOnFunction(Function &F) {
for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) {
FunctionPass *FP = getContainedPass(Index); FunctionPass *FP = getContainedPass(Index);
dumpPassInfo(FP, EXECUTION_MSG, ON_FUNCTION_MSG, F.getNameStart()); dumpPassInfo(FP, EXECUTION_MSG, ON_FUNCTION_MSG, F.getName());
dumpRequiredSet(FP); dumpRequiredSet(FP);
initializeAnalysisImpl(FP); initializeAnalysisImpl(FP);
@ -1374,13 +1374,13 @@ bool FPPassManager::runOnFunction(Function &F) {
} }
if (Changed) if (Changed)
dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getNameStart()); dumpPassInfo(FP, MODIFICATION_MSG, ON_FUNCTION_MSG, F.getName());
dumpPreservedSet(FP); dumpPreservedSet(FP);
verifyPreservedAnalysis(FP); verifyPreservedAnalysis(FP);
removeNotPreservedAnalysis(FP); removeNotPreservedAnalysis(FP);
recordAvailableAnalysis(FP); recordAvailableAnalysis(FP);
removeDeadPasses(FP, F.getNameStart(), ON_FUNCTION_MSG); removeDeadPasses(FP, F.getName(), ON_FUNCTION_MSG);
// If dominator information is available then verify the info if requested. // If dominator information is available then verify the info if requested.
verifyDomInfo(*FP, F); verifyDomInfo(*FP, F);