diff options
author | Bill Wendling <isanbard@gmail.com> | 2009-03-13 04:37:11 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2009-03-13 04:37:11 +0000 |
commit | c7a09ab3110b9462ad9646cb60c22c8527491ad9 (patch) | |
tree | db612124a57fb8f23dfadbf625ea75d22512bc18 /lib/Analysis | |
parent | 77502c93442c5953c05e39fcd4c17d9e2aca766f (diff) | |
download | external_llvm-c7a09ab3110b9462ad9646cb60c22c8527491ad9.tar.gz external_llvm-c7a09ab3110b9462ad9646cb60c22c8527491ad9.tar.bz2 external_llvm-c7a09ab3110b9462ad9646cb60c22c8527491ad9.zip |
Temporarily XFAIL this test.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66866 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r-- | lib/Analysis/DbgInfoPrinter.cpp | 48 | ||||
-rw-r--r-- | lib/Analysis/DebugInfo.cpp | 75 | ||||
-rw-r--r-- | lib/Analysis/ValueTracking.cpp | 120 |
3 files changed, 142 insertions, 101 deletions
diff --git a/lib/Analysis/DbgInfoPrinter.cpp b/lib/Analysis/DbgInfoPrinter.cpp index e43bc81ffa..6346a90a68 100644 --- a/lib/Analysis/DbgInfoPrinter.cpp +++ b/lib/Analysis/DbgInfoPrinter.cpp @@ -33,31 +33,29 @@ static cl::opt<bool> PrintDirectory("print-fullpath", cl::desc("Print fullpath when printing debug info"), cl::Hidden); namespace { - struct VISIBILITY_HIDDEN PrintDbgInfo : public FunctionPass { + struct VISIBILITY_HIDDEN PrintDbgInfo : public FunctionPass { private: raw_ostream &Out; void printStopPoint(const DbgStopPointInst *DSI); void printFuncStart(const DbgFuncStartInst *FS); void printVariableDeclaration(const Value *V); - public: - static char ID; // Pass identification - PrintDbgInfo() : FunctionPass(&ID), Out(outs()) {} + public: + static char ID; // Pass identification + PrintDbgInfo() : FunctionPass(&ID), Out(outs()) {} - virtual bool runOnFunction(Function &F); - virtual void getAnalysisUsage(AnalysisUsage &AU) const { - AU.setPreservesAll(); - } - - }; - char PrintDbgInfo::ID = 0; - static RegisterPass<PrintDbgInfo> X("print-dbginfo", - "Print debug info in human readable form"); + virtual bool runOnFunction(Function &F); + virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AU.setPreservesAll(); + } + }; + char PrintDbgInfo::ID = 0; + static RegisterPass<PrintDbgInfo> X("print-dbginfo", + "Print debug info in human readable form"); } FunctionPass *llvm::createDbgInfoPrinterPass() { return new PrintDbgInfo(); } -void PrintDbgInfo::printVariableDeclaration(const Value *V) -{ +void PrintDbgInfo::printVariableDeclaration(const Value *V) { std::string DisplayName, File, Directory, Type; unsigned LineNo; if (getLocationInfo(V, DisplayName, Type, LineNo, File, Directory)) { @@ -75,24 +73,22 @@ void PrintDbgInfo::printVariableDeclaration(const Value *V) void PrintDbgInfo::printStopPoint(const DbgStopPointInst *DSI) { if (PrintDirectory) { - std::string dir; - GetConstantStringInfo(DSI->getDirectory(), dir); - Out << dir << "/"; + const char *Dir = GetConstantStringInfo(DSI->getDirectory()); + Out << (Dir ? Dir : "") << "/"; } - std::string file; - GetConstantStringInfo(DSI->getFileName(), file); - Out << file << ":" << DSI->getLine(); - if (unsigned Col = DSI->getColumn()) { + + const char *FN = GetConstantStringInfo(DSI->getFileName()); + Out << (FN ? FN : "") << ":" << DSI->getLine(); + + if (unsigned Col = DSI->getColumn()) Out << ":" << Col; - } } void PrintDbgInfo::printFuncStart(const DbgFuncStartInst *FS) { DISubprogram Subprogram(cast<GlobalVariable>(FS->getSubprogram())); - std::string Res1, Res2; - Out << ";fully qualified function name: " << Subprogram.getDisplayName(Res1) - << " return type: " << Subprogram.getType().getName(Res2) + Out << ";fully qualified function name: " << Subprogram.getDisplayName() + << " return type: " << Subprogram.getType().getName() << " at line " << Subprogram.getLineNumber() << "\n\n"; } diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp index d9f0aa53e9..901455700e 100644 --- a/lib/Analysis/DebugInfo.cpp +++ b/lib/Analysis/DebugInfo.cpp @@ -35,24 +35,16 @@ DIDescriptor::DIDescriptor(GlobalVariable *gv, unsigned RequiredTag) { GV = 0; } -const std::string & -DIDescriptor::getStringField(unsigned Elt, std::string &Result) const { - if (GV == 0) { - Result.clear(); - return Result; - } +const char *DIDescriptor::getStringField(unsigned Elt) const { + if (GV == 0) + return 0; Constant *C = GV->getInitializer(); - if (C == 0 || Elt >= C->getNumOperands()) { - Result.clear(); - return Result; - } + if (C == 0 || Elt >= C->getNumOperands()) + return 0; // Fills in the string if it succeeds - if (!GetConstantStringInfo(C->getOperand(Elt), Result)) - Result.clear(); - - return Result; + return GetConstantStringInfo(C->getOperand(Elt)); } uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const { @@ -190,11 +182,9 @@ unsigned DIArray::getNumElements() const { bool DICompileUnit::Verify() const { if (isNull()) return false; - std::string Res; - if (getFilename(Res).empty()) - return false; + // It is possible that directory and produce string is empty. - return true; + return getFilename(); } /// Verify - Verify that a type descriptor is well formed. @@ -505,7 +495,7 @@ DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){ /// CreateBasicType - Create a basic type like int, float, etc. DIBasicType DIFactory::CreateBasicType(DIDescriptor Context, - const std::string &Name, + const std::string &Name, DICompileUnit CompileUnit, unsigned LineNumber, uint64_t SizeInBits, @@ -894,8 +884,7 @@ namespace llvm { } bool getLocationInfo(const Value *V, std::string &DisplayName, std::string &Type, - unsigned &LineNo, std::string &File, std::string &Dir) - { + unsigned &LineNo, std::string &File, std::string &Dir) { DICompileUnit Unit; DIType TypeD; if (GlobalVariable *GV = dyn_cast<GlobalVariable>(const_cast<Value*>(V))) { @@ -903,7 +892,11 @@ namespace llvm { if (!DIGV) return false; DIGlobalVariable Var(cast<GlobalVariable>(DIGV)); - Var.getDisplayName(DisplayName); + const char *DN = Var.getDisplayName(); + if (DN) + DisplayName = DN; + else + DisplayName.clear(); LineNo = Var.getLineNumber(); Unit = Var.getCompileUnit(); TypeD = Var.getType(); @@ -912,14 +905,24 @@ namespace llvm { if (!DDI) return false; DIVariable Var(cast<GlobalVariable>(DDI->getVariable())); - Var.getName(DisplayName); + const char *DN = Var.getName(); + if (DN) + DisplayName = DN; + else + DisplayName.clear(); LineNo = Var.getLineNumber(); Unit = Var.getCompileUnit(); TypeD = Var.getType(); } - TypeD.getName(Type); - Unit.getFilename(File); - Unit.getDirectory(Dir); + Type.clear(); + File.clear(); + Dir.clear(); + const char *Str = TypeD.getName(); + if (Str) Type = Str; + Str = Unit.getFilename(); + if (Str) File = Str; + Str = Unit.getDirectory(); + if (Str) Dir = Str; return true; } } @@ -929,17 +932,17 @@ void DICompileUnit::dump() const { if (getLanguage()) cerr << " [" << dwarf::LanguageString(getLanguage()) << "] "; - std::string Res1, Res2; - cerr << " [" << getDirectory(Res1) << "/" << getFilename(Res2) << " ]"; + const char *Dir = getDirectory(); + const char *FN = getFilename(); + cerr << " [" << (Dir ? Dir : "") << "/" << (FN ? FN : "") << " ]"; } /// dump - print type. void DIType::dump() const { if (isNull()) return; - std::string Res; - if (!getName(Res).empty()) - cerr << " [" << Res << "] "; + if (const char *N = getName()) + cerr << " [" << N << "] "; unsigned Tag = getTag(); cerr << " [" << dwarf::TagString(Tag) << "] "; @@ -996,9 +999,8 @@ void DICompositeType::dump() const { /// dump - print global. void DIGlobal::dump() const { - std::string Res; - if (!getName(Res).empty()) - cerr << " [" << Res << "] "; + if (const char *N = getName()) + cerr << " [" << N << "] "; unsigned Tag = getTag(); cerr << " [" << dwarf::TagString(Tag) << "] "; @@ -1031,9 +1033,8 @@ void DIGlobalVariable::dump() const { /// dump - print variable. void DIVariable::dump() const { - std::string Res; - if (!getName(Res).empty()) - cerr << " [" << Res << "] "; + if (const char *N = getName()) + cerr << " [" << N << "] "; getCompileUnit().dump(); cerr << " [" << getLineNumber() << "] "; diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index 20fa69ea24..d3a7d1bfeb 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/lib/Analysis/ValueTracking.cpp @@ -17,9 +17,10 @@ #include "llvm/Instructions.h" #include "llvm/GlobalVariable.h" #include "llvm/IntrinsicInst.h" -#include "llvm/Target/TargetData.h" +#include "llvm/ADT/DenseMap.h" #include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Support/MathExtras.h" +#include "llvm/Target/TargetData.h" #include <cstring> using namespace llvm; @@ -928,6 +929,7 @@ Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin, return FindInsertedValue(I->getAggregateOperand(), Idxs.begin(), Idxs.end(), InsertBefore); } + // Otherwise, we don't know (such as, extracting from a function return value // or load instruction) return 0; @@ -936,55 +938,86 @@ Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin, /// GetConstantStringInfo - This function computes the length of a /// null-terminated C string pointed to by V. If successful, it returns true /// and returns the string in Str. If unsuccessful, it returns false. -bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset, - bool StopAtNul) { - // If V is NULL then return false; - if (V == NULL) return false; +const char *llvm::GetConstantStringInfo(Value *V, uint64_t Offset, + bool StopAtNul) { + static DenseMap<Value*, std::string> StringInfoMap; + static DenseMap<Value*, bool> NulMap; + + // If we've already determined that the Value is NUL, then return 0. + if (NulMap[V]) + return 0; + + // Check to see if we've already calculated the string info. + if (StringInfoMap.find(V) != StringInfoMap.end()) + return StringInfoMap.lookup(V).c_str(); + + // If V is NULL then return nul. + if (V == 0) { + NulMap[V] = true; + return 0; + } + + std::string *Str = &StringInfoMap.FindAndConstruct(V).second; + Str->clear(); // Look through bitcast instructions. if (BitCastInst *BCI = dyn_cast<BitCastInst>(V)) - return GetConstantStringInfo(BCI->getOperand(0), Str, Offset, StopAtNul); - + return GetConstantStringInfo(BCI->getOperand(0), Offset, StopAtNul); + // If the value is not a GEP instruction nor a constant expression with a // GEP instruction, then return false because ConstantArray can't occur // any other way User *GEP = 0; + if (GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(V)) { GEP = GEPI; } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { if (CE->getOpcode() == Instruction::BitCast) - return GetConstantStringInfo(CE->getOperand(0), Str, Offset, StopAtNul); - if (CE->getOpcode() != Instruction::GetElementPtr) - return false; + return GetConstantStringInfo(CE->getOperand(0), Offset, StopAtNul); + + if (CE->getOpcode() != Instruction::GetElementPtr) { + NulMap[V] = true; + return 0; + } + GEP = CE; } if (GEP) { // Make sure the GEP has exactly three arguments. - if (GEP->getNumOperands() != 3) - return false; - + if (GEP->getNumOperands() != 3) { + NulMap[V] = true; + return 0; + } + // Make sure the index-ee is a pointer to array of i8. const PointerType *PT = cast<PointerType>(GEP->getOperand(0)->getType()); const ArrayType *AT = dyn_cast<ArrayType>(PT->getElementType()); - if (AT == 0 || AT->getElementType() != Type::Int8Ty) - return false; + if (AT == 0 || AT->getElementType() != Type::Int8Ty) { + NulMap[V] = true; + return 0; + } // Check to make sure that the first operand of the GEP is an integer and // has value 0 so that we are sure we're indexing into the initializer. ConstantInt *FirstIdx = dyn_cast<ConstantInt>(GEP->getOperand(1)); - if (FirstIdx == 0 || !FirstIdx->isZero()) - return false; + if (FirstIdx == 0 || !FirstIdx->isZero()) { + NulMap[V] = true; + return 0; + } // If the second index isn't a ConstantInt, then this is a variable index // into the array. If this occurs, we can't say anything meaningful about // the string. uint64_t StartIdx = 0; - if (ConstantInt *CI = dyn_cast<ConstantInt>(GEP->getOperand(2))) + if (ConstantInt *CI = dyn_cast<ConstantInt>(GEP->getOperand(2))) { StartIdx = CI->getZExtValue(); - else - return false; - return GetConstantStringInfo(GEP->getOperand(0), Str, StartIdx+Offset, + } else { + NulMap[V] = true; + return 0; + } + + return GetConstantStringInfo(GEP->getOperand(0), StartIdx + Offset, StopAtNul); } @@ -992,42 +1025,53 @@ bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset, // variable that is a constant and is initialized. The referenced constant // initializer is the array that we'll use for optimization. GlobalVariable* GV = dyn_cast<GlobalVariable>(V); - if (!GV || !GV->isConstant() || !GV->hasInitializer()) - return false; + if (!GV || !GV->isConstant() || !GV->hasInitializer()) { + NulMap[V] = true; + return 0; + } Constant *GlobalInit = GV->getInitializer(); // Handle the ConstantAggregateZero case - if (isa<ConstantAggregateZero>(GlobalInit)) { + if (isa<ConstantAggregateZero>(GlobalInit)) // This is a degenerate case. The initializer is constant zero so the // length of the string must be zero. - Str.clear(); - return true; - } + return ""; // Must be a Constant Array ConstantArray *Array = dyn_cast<ConstantArray>(GlobalInit); - if (Array == 0 || Array->getType()->getElementType() != Type::Int8Ty) - return false; + if (Array == 0 || Array->getType()->getElementType() != Type::Int8Ty) { + NulMap[V] = true; + return 0; + } // Get the number of elements in the array uint64_t NumElts = Array->getType()->getNumElements(); - if (Offset > NumElts) - return false; + if (Offset > NumElts) { + NulMap[V] = true; + return 0; + } // Traverse the constant array from 'Offset' which is the place the GEP refers // to in the array. - Str.reserve(NumElts-Offset); + Str->reserve(NumElts - Offset); + for (unsigned i = Offset; i != NumElts; ++i) { Constant *Elt = Array->getOperand(i); ConstantInt *CI = dyn_cast<ConstantInt>(Elt); - if (!CI) // This array isn't suitable, non-int initializer. - return false; + + if (!CI) { // This array isn't suitable, non-int initializer. + StringInfoMap.erase(V); + NulMap[V] = true; + return 0; + } + if (StopAtNul && CI->isZero()) - return true; // we found end of string, success! - Str += (char)CI->getZExtValue(); + return Str->c_str(); // we found end of string, success! + + Str->operator+=((char)CI->getZExtValue()); } - + // The array isn't null terminated, but maybe this is a memcpy, not a strcpy. - return true; + return Str->c_str(); } |