From 0582ae99ba75a556d6ff63b254da327d32ba036f Mon Sep 17 00:00:00 2001 From: Bill Wendling Date: Fri, 13 Mar 2009 04:39:26 +0000 Subject: Oops...I committed too much. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66867 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/DebugInfo.h | 42 ++++---- include/llvm/Analysis/ValueTracking.h | 14 +-- lib/Analysis/DbgInfoPrinter.cpp | 48 ++++----- lib/Analysis/DebugInfo.cpp | 75 +++++++------- lib/Analysis/ValueTracking.cpp | 120 +++++++---------------- lib/CodeGen/AsmPrinter/DwarfWriter.cpp | 65 +++++++----- lib/CodeGen/SelectionDAG/FastISel.cpp | 10 +- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 5 +- lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 7 +- lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp | 20 ++-- lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp | 4 +- lib/Debugger/ProgramInfo.cpp | 12 +-- lib/Transforms/Scalar/InstructionCombining.cpp | 7 +- lib/Transforms/Scalar/SimplifyLibCalls.cpp | 58 ++++++----- 14 files changed, 233 insertions(+), 254 deletions(-) diff --git a/include/llvm/Analysis/DebugInfo.h b/include/llvm/Analysis/DebugInfo.h index b31896e6ff..c6f09283bd 100644 --- a/include/llvm/Analysis/DebugInfo.h +++ b/include/llvm/Analysis/DebugInfo.h @@ -40,7 +40,7 @@ namespace llvm { /// not, the debug info is corrupt and we ignore it. DIDescriptor(GlobalVariable *GV, unsigned RequiredTag); - const char *getStringField(unsigned Elt) const; + const std::string &getStringField(unsigned Elt, std::string &Result) const; unsigned getUnsignedField(unsigned Elt) const { return (unsigned)getUInt64Field(Elt); } @@ -106,14 +106,14 @@ namespace llvm { explicit DICompileUnit(GlobalVariable *GV = 0); unsigned getLanguage() const { return getUnsignedField(2); } - const char *getFilename() const { - return getStringField(3); + const std::string &getFilename(std::string &F) const { + return getStringField(3, F); } - const char *getDirectory() const { - return getStringField(4); + const std::string &getDirectory(std::string &F) const { + return getStringField(4, F); } - const char *getProducer() const { - return getStringField(5); + const std::string &getProducer(std::string &F) const { + return getStringField(5, F); } /// isMain - Each input file is encoded as a separate compile unit in LLVM @@ -127,7 +127,9 @@ namespace llvm { bool isMain() const { return getUnsignedField(6); } bool isOptimized() const { return getUnsignedField(7); } - const char *getFlags() const { return getStringField(8); } + const std::string &getFlags(std::string &F) const { + return getStringField(8, F); + } unsigned getRunTimeVersion() const { return getUnsignedField(9); } /// Verify - Verify that a compile unit is well formed. @@ -144,8 +146,8 @@ namespace llvm { public: explicit DIEnumerator(GlobalVariable *GV = 0); - const char *getName() const { - return getStringField(1); + const std::string &getName(std::string &F) const { + return getStringField(1, F); } uint64_t getEnumValue() const { return getUInt64Field(2); } }; @@ -190,7 +192,9 @@ namespace llvm { virtual ~DIType() {} DIDescriptor getContext() const { return getDescriptorField(1); } - const char *getName() const { return getStringField(2); } + const std::string &getName(std::string &F) const { + return getStringField(2, F); + } DICompileUnit getCompileUnit() const{ return getFieldAs(3); } unsigned getLineNumber() const { return getUnsignedField(4); } uint64_t getSizeInBits() const { return getUInt64Field(5); } @@ -272,14 +276,14 @@ namespace llvm { virtual ~DIGlobal() {} DIDescriptor getContext() const { return getDescriptorField(2); } - const char *getName() const { - return getStringField(3); + const std::string &getName(std::string &F) const { + return getStringField(3, F); } - const char *getDisplayName() const { - return getStringField(4); + const std::string &getDisplayName(std::string &F) const { + return getStringField(4, F); } - const char *getLinkageName() const { - return getStringField(5); + const std::string &getLinkageName(std::string &F) const { + return getStringField(5, F); } DICompileUnit getCompileUnit() const{ return getFieldAs(6); } unsigned getLineNumber() const { return getUnsignedField(7); } @@ -327,8 +331,8 @@ namespace llvm { explicit DIVariable(GlobalVariable *GV = 0); DIDescriptor getContext() const { return getDescriptorField(1); } - const char *getName() const { - return getStringField(2); + const std::string &getName(std::string &F) const { + return getStringField(2, F); } DICompileUnit getCompileUnit() const{ return getFieldAs(3); } unsigned getLineNumber() const { return getUnsignedField(4); } diff --git a/include/llvm/Analysis/ValueTracking.h b/include/llvm/Analysis/ValueTracking.h index cefa076e79..5f5f77a5c9 100644 --- a/include/llvm/Analysis/ValueTracking.h +++ b/include/llvm/Analysis/ValueTracking.h @@ -75,13 +75,13 @@ namespace llvm { } /// GetConstantStringInfo - This function computes the length of a - /// null-terminated C string pointed to by V. If successful, it returns the - /// string. If unsuccessful, it returns NUL. If StopAtNul is set to true - /// (the default), the returned string is truncated by a nul character in the - /// global. If StopAtNul is false, the nul character is included in the - /// result string. - const char *GetConstantStringInfo(Value *V, uint64_t Offset = 0, - bool StopAtNul = true); + /// null-terminated C string pointed to by V. If successful, it returns true + /// and returns the string in Str. If unsuccessful, it returns false. If + /// StopAtNul is set to true (the default), the returned string is truncated + /// by a nul character in the global. If StopAtNul is false, the nul + /// character is included in the result string. + bool GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset = 0, + bool StopAtNul = true); } // end namespace llvm #endif diff --git a/lib/Analysis/DbgInfoPrinter.cpp b/lib/Analysis/DbgInfoPrinter.cpp index 6346a90a68..e43bc81ffa 100644 --- a/lib/Analysis/DbgInfoPrinter.cpp +++ b/lib/Analysis/DbgInfoPrinter.cpp @@ -33,29 +33,31 @@ static cl::opt 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 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 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)) { @@ -73,22 +75,24 @@ void PrintDbgInfo::printVariableDeclaration(const Value *V) { void PrintDbgInfo::printStopPoint(const DbgStopPointInst *DSI) { if (PrintDirectory) { - const char *Dir = GetConstantStringInfo(DSI->getDirectory()); - Out << (Dir ? Dir : "") << "/"; + std::string dir; + GetConstantStringInfo(DSI->getDirectory(), dir); + Out << dir << "/"; } - - const char *FN = GetConstantStringInfo(DSI->getFileName()); - Out << (FN ? FN : "") << ":" << DSI->getLine(); - - if (unsigned Col = DSI->getColumn()) + std::string file; + GetConstantStringInfo(DSI->getFileName(), file); + Out << file << ":" << DSI->getLine(); + if (unsigned Col = DSI->getColumn()) { Out << ":" << Col; + } } void PrintDbgInfo::printFuncStart(const DbgFuncStartInst *FS) { DISubprogram Subprogram(cast(FS->getSubprogram())); - Out << ";fully qualified function name: " << Subprogram.getDisplayName() - << " return type: " << Subprogram.getType().getName() + std::string Res1, Res2; + Out << ";fully qualified function name: " << Subprogram.getDisplayName(Res1) + << " return type: " << Subprogram.getType().getName(Res2) << " at line " << Subprogram.getLineNumber() << "\n\n"; } diff --git a/lib/Analysis/DebugInfo.cpp b/lib/Analysis/DebugInfo.cpp index 901455700e..d9f0aa53e9 100644 --- a/lib/Analysis/DebugInfo.cpp +++ b/lib/Analysis/DebugInfo.cpp @@ -35,16 +35,24 @@ DIDescriptor::DIDescriptor(GlobalVariable *gv, unsigned RequiredTag) { GV = 0; } -const char *DIDescriptor::getStringField(unsigned Elt) const { - if (GV == 0) - return 0; +const std::string & +DIDescriptor::getStringField(unsigned Elt, std::string &Result) const { + if (GV == 0) { + Result.clear(); + return Result; + } Constant *C = GV->getInitializer(); - if (C == 0 || Elt >= C->getNumOperands()) - return 0; + if (C == 0 || Elt >= C->getNumOperands()) { + Result.clear(); + return Result; + } // Fills in the string if it succeeds - return GetConstantStringInfo(C->getOperand(Elt)); + if (!GetConstantStringInfo(C->getOperand(Elt), Result)) + Result.clear(); + + return Result; } uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const { @@ -182,9 +190,11 @@ 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 getFilename(); + return true; } /// Verify - Verify that a type descriptor is well formed. @@ -495,7 +505,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, @@ -884,7 +894,8 @@ 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(const_cast(V))) { @@ -892,11 +903,7 @@ namespace llvm { if (!DIGV) return false; DIGlobalVariable Var(cast(DIGV)); - const char *DN = Var.getDisplayName(); - if (DN) - DisplayName = DN; - else - DisplayName.clear(); + Var.getDisplayName(DisplayName); LineNo = Var.getLineNumber(); Unit = Var.getCompileUnit(); TypeD = Var.getType(); @@ -905,24 +912,14 @@ namespace llvm { if (!DDI) return false; DIVariable Var(cast(DDI->getVariable())); - const char *DN = Var.getName(); - if (DN) - DisplayName = DN; - else - DisplayName.clear(); + Var.getName(DisplayName); LineNo = Var.getLineNumber(); Unit = Var.getCompileUnit(); TypeD = Var.getType(); } - 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; + TypeD.getName(Type); + Unit.getFilename(File); + Unit.getDirectory(Dir); return true; } } @@ -932,17 +929,17 @@ void DICompileUnit::dump() const { if (getLanguage()) cerr << " [" << dwarf::LanguageString(getLanguage()) << "] "; - const char *Dir = getDirectory(); - const char *FN = getFilename(); - cerr << " [" << (Dir ? Dir : "") << "/" << (FN ? FN : "") << " ]"; + std::string Res1, Res2; + cerr << " [" << getDirectory(Res1) << "/" << getFilename(Res2) << " ]"; } /// dump - print type. void DIType::dump() const { if (isNull()) return; - if (const char *N = getName()) - cerr << " [" << N << "] "; + std::string Res; + if (!getName(Res).empty()) + cerr << " [" << Res << "] "; unsigned Tag = getTag(); cerr << " [" << dwarf::TagString(Tag) << "] "; @@ -999,8 +996,9 @@ void DICompositeType::dump() const { /// dump - print global. void DIGlobal::dump() const { - if (const char *N = getName()) - cerr << " [" << N << "] "; + std::string Res; + if (!getName(Res).empty()) + cerr << " [" << Res << "] "; unsigned Tag = getTag(); cerr << " [" << dwarf::TagString(Tag) << "] "; @@ -1033,8 +1031,9 @@ void DIGlobalVariable::dump() const { /// dump - print variable. void DIVariable::dump() const { - if (const char *N = getName()) - cerr << " [" << N << "] "; + std::string Res; + if (!getName(Res).empty()) + cerr << " [" << Res << "] "; getCompileUnit().dump(); cerr << " [" << getLineNumber() << "] "; diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index d3a7d1bfeb..20fa69ea24 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/lib/Analysis/ValueTracking.cpp @@ -17,10 +17,9 @@ #include "llvm/Instructions.h" #include "llvm/GlobalVariable.h" #include "llvm/IntrinsicInst.h" -#include "llvm/ADT/DenseMap.h" +#include "llvm/Target/TargetData.h" #include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Support/MathExtras.h" -#include "llvm/Target/TargetData.h" #include using namespace llvm; @@ -929,7 +928,6 @@ 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; @@ -938,86 +936,55 @@ 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. -const char *llvm::GetConstantStringInfo(Value *V, uint64_t Offset, - bool StopAtNul) { - static DenseMap StringInfoMap; - static DenseMap 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(); +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; // Look through bitcast instructions. if (BitCastInst *BCI = dyn_cast(V)) - return GetConstantStringInfo(BCI->getOperand(0), Offset, StopAtNul); - + return GetConstantStringInfo(BCI->getOperand(0), Str, 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(V)) { GEP = GEPI; } else if (ConstantExpr *CE = dyn_cast(V)) { if (CE->getOpcode() == Instruction::BitCast) - return GetConstantStringInfo(CE->getOperand(0), Offset, StopAtNul); - - if (CE->getOpcode() != Instruction::GetElementPtr) { - NulMap[V] = true; - return 0; - } - + return GetConstantStringInfo(CE->getOperand(0), Str, Offset, StopAtNul); + if (CE->getOpcode() != Instruction::GetElementPtr) + return false; GEP = CE; } if (GEP) { // Make sure the GEP has exactly three arguments. - if (GEP->getNumOperands() != 3) { - NulMap[V] = true; - return 0; - } - + if (GEP->getNumOperands() != 3) + return false; + // Make sure the index-ee is a pointer to array of i8. const PointerType *PT = cast(GEP->getOperand(0)->getType()); const ArrayType *AT = dyn_cast(PT->getElementType()); - if (AT == 0 || AT->getElementType() != Type::Int8Ty) { - NulMap[V] = true; - return 0; - } + if (AT == 0 || AT->getElementType() != Type::Int8Ty) + return false; // 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(GEP->getOperand(1)); - if (FirstIdx == 0 || !FirstIdx->isZero()) { - NulMap[V] = true; - return 0; - } + if (FirstIdx == 0 || !FirstIdx->isZero()) + return false; // 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(GEP->getOperand(2))) { + if (ConstantInt *CI = dyn_cast(GEP->getOperand(2))) StartIdx = CI->getZExtValue(); - } else { - NulMap[V] = true; - return 0; - } - - return GetConstantStringInfo(GEP->getOperand(0), StartIdx + Offset, + else + return false; + return GetConstantStringInfo(GEP->getOperand(0), Str, StartIdx+Offset, StopAtNul); } @@ -1025,53 +992,42 @@ const char *llvm::GetConstantStringInfo(Value *V, 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(V); - if (!GV || !GV->isConstant() || !GV->hasInitializer()) { - NulMap[V] = true; - return 0; - } + if (!GV || !GV->isConstant() || !GV->hasInitializer()) + return false; Constant *GlobalInit = GV->getInitializer(); // Handle the ConstantAggregateZero case - if (isa(GlobalInit)) + if (isa(GlobalInit)) { // This is a degenerate case. The initializer is constant zero so the // length of the string must be zero. - return ""; + Str.clear(); + return true; + } // Must be a Constant Array ConstantArray *Array = dyn_cast(GlobalInit); - if (Array == 0 || Array->getType()->getElementType() != Type::Int8Ty) { - NulMap[V] = true; - return 0; - } + if (Array == 0 || Array->getType()->getElementType() != Type::Int8Ty) + return false; // Get the number of elements in the array uint64_t NumElts = Array->getType()->getNumElements(); - if (Offset > NumElts) { - NulMap[V] = true; - return 0; - } + if (Offset > NumElts) + return false; // 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(Elt); - - if (!CI) { // This array isn't suitable, non-int initializer. - StringInfoMap.erase(V); - NulMap[V] = true; - return 0; - } - + if (!CI) // This array isn't suitable, non-int initializer. + return false; if (StopAtNul && CI->isZero()) - return Str->c_str(); // we found end of string, success! - - Str->operator+=((char)CI->getZExtValue()); + return true; // we found end of string, success! + Str += (char)CI->getZExtValue(); } - + // The array isn't null terminated, but maybe this is a memcpy, not a strcpy. - return Str->c_str(); + return true; } diff --git a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp index 7190b9269b..4120d9f917 100644 --- a/lib/CodeGen/AsmPrinter/DwarfWriter.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfWriter.cpp @@ -1619,12 +1619,14 @@ private: /// ConstructTypeDIE - Construct basic type die from DIBasicType. void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, DIBasicType BTy) { + // Get core information. - const char *Name = BTy.getName(); + std::string Name; + BTy.getName(Name); Buffer.setTag(DW_TAG_base_type); AddUInt(&Buffer, DW_AT_encoding, DW_FORM_data1, BTy.getEncoding()); // Add name if not anonymous or intermediate type. - if (Name) + if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name); uint64_t Size = BTy.getSizeInBits() >> 3; AddUInt(&Buffer, DW_AT_byte_size, 0, Size); @@ -1633,8 +1635,10 @@ private: /// ConstructTypeDIE - Construct derived type die from DIDerivedType. void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, DIDerivedType DTy) { + // Get core information. - const char *Name = DTy.getName(); + std::string Name; + DTy.getName(Name); uint64_t Size = DTy.getSizeInBits() >> 3; unsigned Tag = DTy.getTag(); @@ -1648,7 +1652,7 @@ private: AddType(DW_Unit, &Buffer, FromTy); // Add name if not anonymous or intermediate type. - if (Name) + if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name); // Add size if non-zero (derived types might be zero-sized.) @@ -1665,7 +1669,8 @@ private: void ConstructTypeDIE(CompileUnit *DW_Unit, DIE &Buffer, DICompositeType CTy) { // Get core information. - const char *Name = CTy.getName(); + std::string Name; + CTy.getName(Name); uint64_t Size = CTy.getSizeInBits() >> 3; unsigned Tag = CTy.getTag(); @@ -1741,7 +1746,7 @@ private: } // Add name if not anonymous or intermediate type. - if (Name) + if (!Name.empty()) AddString(&Buffer, DW_AT_name, DW_FORM_string, Name); if (Tag == DW_TAG_enumeration_type || Tag == DW_TAG_structure_type @@ -1806,7 +1811,8 @@ private: DIE *ConstructEnumTypeDIE(CompileUnit *DW_Unit, DIEnumerator *ETy) { DIE *Enumerator = new DIE(DW_TAG_enumerator); - const char *Name = ETy->getName(); + std::string Name; + ETy->getName(Name); AddString(Enumerator, DW_AT_name, DW_FORM_string, Name); int64_t Value = ETy->getEnumValue(); AddSInt(Enumerator, DW_AT_const_value, DW_FORM_sdata, Value); @@ -1817,10 +1823,12 @@ private: DIE *CreateGlobalVariableDIE(CompileUnit *DW_Unit, const DIGlobalVariable &GV) { DIE *GVDie = new DIE(DW_TAG_variable); - const char *Name = GV.getDisplayName(); + std::string Name; + GV.getDisplayName(Name); AddString(GVDie, DW_AT_name, DW_FORM_string, Name); - const char *LinkageName = GV.getLinkageName(); - if (LinkageName) + std::string LinkageName; + GV.getLinkageName(LinkageName); + if (!LinkageName.empty()) AddString(GVDie, DW_AT_MIPS_linkage_name, DW_FORM_string, LinkageName); AddType(DW_Unit, GVDie, GV.getType()); if (!GV.isLocalToUnit()) @@ -1832,8 +1840,9 @@ private: /// CreateMemberDIE - Create new member DIE. DIE *CreateMemberDIE(CompileUnit *DW_Unit, const DIDerivedType &DT) { DIE *MemberDie = new DIE(DT.getTag()); - const char *Name = DT.getName(); - if (Name) + std::string Name; + DT.getName(Name); + if (!Name.empty()) AddString(MemberDie, DW_AT_name, DW_FORM_string, Name); AddType(DW_Unit, MemberDie, DT.getTypeDerivedFrom()); @@ -1876,10 +1885,12 @@ private: const DISubprogram &SP, bool IsConstructor = false) { DIE *SPDie = new DIE(DW_TAG_subprogram); - const char *Name = SP.getName(); + std::string Name; + SP.getName(Name); AddString(SPDie, DW_AT_name, DW_FORM_string, Name); - const char *LinkageName = SP.getLinkageName(); - if (LinkageName) + std::string LinkageName; + SP.getLinkageName(LinkageName); + if (!LinkageName.empty()) AddString(SPDie, DW_AT_MIPS_linkage_name, DW_FORM_string, LinkageName); AddSourceLine(SPDie, &SP); @@ -1945,7 +1956,8 @@ private: // Define variable debug information entry. DIE *VariableDie = new DIE(Tag); - const char *Name = VD.getName(); + std::string Name; + VD.getName(Name); AddString(VariableDie, DW_AT_name, DW_FORM_string, Name); // Add source line info if available. @@ -2807,23 +2819,24 @@ private: void ConstructCompileUnit(GlobalVariable *GV) { DICompileUnit DIUnit(GV); - const char *Dir = DIUnit.getDirectory(); - const char *FN = DIUnit.getFilename(); - unsigned ID = GetOrCreateSourceID(Dir, FN); + std::string Dir, FN, Prod; + unsigned ID = GetOrCreateSourceID(DIUnit.getDirectory(Dir), + DIUnit.getFilename(FN)); DIE *Die = new DIE(DW_TAG_compile_unit); AddSectionOffset(Die, DW_AT_stmt_list, DW_FORM_data4, DWLabel("section_line", 0), DWLabel("section_line", 0), false); - AddString(Die, DW_AT_producer, DW_FORM_string, DIUnit.getProducer()); + AddString(Die, DW_AT_producer, DW_FORM_string, DIUnit.getProducer(Prod)); AddUInt(Die, DW_AT_language, DW_FORM_data1, DIUnit.getLanguage()); AddString(Die, DW_AT_name, DW_FORM_string, FN); - if (Dir) + if (!Dir.empty()) AddString(Die, DW_AT_comp_dir, DW_FORM_string, Dir); if (DIUnit.isOptimized()) AddUInt(Die, DW_AT_APPLE_optimized, DW_FORM_flag, 1); - const char *Flags = DIUnit.getFlags(); - if (Flags) + std::string Flags; + DIUnit.getFlags(Flags); + if (!Flags.empty()) AddString(Die, DW_AT_APPLE_flags, DW_FORM_string, Flags); unsigned RVer = DIUnit.getRunTimeVersion(); if (RVer) @@ -2882,7 +2895,8 @@ private: // Add to context owner. DW_Unit->getDie()->AddChild(VariableDie); // Expose as global. FIXME - need to check external flag. - DW_Unit->AddGlobal(DI_GV.getName(), VariableDie); + std::string Name; + DW_Unit->AddGlobal(DI_GV.getName(Name), VariableDie); return true; } @@ -2934,7 +2948,8 @@ private: // Add to context owner. Unit->getDie()->AddChild(SubprogramDie); // Expose as global. - Unit->AddGlobal(SP.getName(), SubprogramDie); + std::string Name; + Unit->AddGlobal(SP.getName(Name), SubprogramDie); return true; } diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp index a0ed4755f9..229376d293 100644 --- a/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -319,8 +319,9 @@ bool FastISel::SelectCall(User *I) { DbgStopPointInst *SPI = cast(I); if (DW && DW->ValidDebugInfo(SPI->getContext())) { DICompileUnit CU(cast(SPI->getContext())); - unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(), - CU.getFilename()); + std::string Dir, FN; + unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(Dir), + CU.getFilename(FN)); unsigned Line = SPI->getLine(); unsigned Col = SPI->getColumn(); unsigned ID = DW->RecordSourceLine(Line, Col, SrcFile); @@ -361,8 +362,9 @@ bool FastISel::SelectCall(User *I) { // (most?) gdb expects. DISubprogram Subprogram(cast(SP)); DICompileUnit CompileUnit = Subprogram.getCompileUnit(); - unsigned SrcFile = DW->getOrCreateSourceID(CompileUnit.getDirectory(), - CompileUnit.getFilename()); + std::string Dir, FN; + unsigned SrcFile = DW->getOrCreateSourceID(CompileUnit.getDirectory(Dir), + CompileUnit.getFilename(FN)); // Record the source line but does not create a label for the normal // function start. It will be emitted at asm emission time. However, diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 0854aad9b6..8c074e75eb 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -1287,8 +1287,9 @@ SDValue SelectionDAGLegalize::LegalizeOp(SDValue Op) { GlobalVariable *CU_GV = cast(DSP->getCompileUnit()); if (DW && (useDEBUG_LOC || useLABEL) && !CU_GV->isDeclaration()) { DICompileUnit CU(cast(DSP->getCompileUnit())); - unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(), - CU.getFilename()); + std::string Dir, FN; + unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(Dir), + CU.getFilename(FN)); unsigned Line = DSP->getLine(); unsigned Col = DSP->getColumn(); diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 4afc3b5c3e..71560fe2ae 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -2931,11 +2931,8 @@ static bool isMemSrcFromString(SDValue Src, std::string &Str) { return false; GlobalVariable *GV = dyn_cast(G->getGlobal()); - if (GV) { - const char *SI = GetConstantStringInfo(GV, SrcDelta, false); - Str = (SI ? SI : ""); - if (!Str.empty()) return true; - } + if (GV && GetConstantStringInfo(GV, Str, SrcDelta, false)) + return true; return false; } diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index b3a06ea9d7..0dbc35b224 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -335,8 +335,9 @@ void FunctionLoweringInfo::set(Function &fn, MachineFunction &mf, if (DW && DW->ValidDebugInfo(SPI->getContext())) { DICompileUnit CU(cast(SPI->getContext())); - unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(), - CU.getFilename()); + std::string Dir, FN; + unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(Dir), + CU.getFilename(FN)); unsigned idx = MF->getOrCreateDebugLocID(SrcFile, SPI->getLine(), SPI->getColumn()); @@ -354,8 +355,9 @@ void FunctionLoweringInfo::set(Function &fn, MachineFunction &mf, if (DW->ValidDebugInfo(SP)) { DISubprogram Subprogram(cast(SP)); DICompileUnit CU(Subprogram.getCompileUnit()); - unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(), - CU.getFilename()); + std::string Dir, FN; + unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(Dir), + CU.getFilename(FN)); unsigned Line = Subprogram.getLineNumber(); DL = DebugLoc::get(MF->getOrCreateDebugLocID(SrcFile, Line, 0)); } @@ -3902,8 +3904,9 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { SPI.getColumn(), SPI.getContext())); DICompileUnit CU(cast(SPI.getContext())); - unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(), - CU.getFilename()); + std::string Dir, FN; + unsigned SrcFile = DW->getOrCreateSourceID(CU.getDirectory(Dir), + CU.getFilename(FN)); unsigned idx = MF.getOrCreateDebugLocID(SrcFile, SPI.getLine(), SPI.getColumn()); setCurDebugLoc(DebugLoc::get(idx)); @@ -3947,8 +3950,9 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) { MachineFunction &MF = DAG.getMachineFunction(); DISubprogram Subprogram(cast(SP)); DICompileUnit CompileUnit = Subprogram.getCompileUnit(); - unsigned SrcFile = DW->getOrCreateSourceID(CompileUnit.getDirectory(), - CompileUnit.getFilename()); + std::string Dir, FN; + unsigned SrcFile = DW->getOrCreateSourceID(CompileUnit.getDirectory(Dir), + CompileUnit.getFilename(FN)); // Record the source line but does not create a label for the normal // function start. It will be emitted at asm emission time. However, diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp index 9475ffa859..0392338762 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp @@ -179,8 +179,8 @@ std::string DOTGraphTraits::getNodeLabel(const SDNode *Node, } } else if (const DbgStopPointSDNode *D = dyn_cast(Node)) { DICompileUnit CU(cast(D->getCompileUnit())); - const char *FN = CU.getFilename(); - Op += ": " + std::string(FN ? FN : ""); + std::string FN; + Op += ": " + CU.getFilename(FN); Op += ":" + utostr(D->getLine()); if (D->getColumn() != 0) Op += ":" + utostr(D->getColumn()); diff --git a/lib/Debugger/ProgramInfo.cpp b/lib/Debugger/ProgramInfo.cpp index 2bf993ce5a..125ff556dd 100644 --- a/lib/Debugger/ProgramInfo.cpp +++ b/lib/Debugger/ProgramInfo.cpp @@ -117,10 +117,10 @@ SourceFileInfo::SourceFileInfo(const GlobalVariable *Desc, if (ConstantInt *CUI = dyn_cast(CS->getOperand(1))) Version = CUI->getZExtValue(); - const char *SI = GetConstantStringInfo(CS->getOperand(3)); - BaseName = (SI ? SI : ""); - SI = GetConstantStringInfo(CS->getOperand(4)); - Directory = (SI ? SI : ""); + if (!GetConstantStringInfo(CS->getOperand(3), BaseName)) + BaseName = ""; + if (!GetConstantStringInfo(CS->getOperand(4), Directory)) + Directory = ""; } } @@ -160,8 +160,8 @@ SourceFunctionInfo::SourceFunctionInfo(ProgramInfo &PI, SourceFile = &PI.getSourceFile(GV); // Entry #2 is the function name. - const char *SI = GetConstantStringInfo(CS->getOperand(2)); - Name = (SI ? SI : ""); + if (!GetConstantStringInfo(CS->getOperand(2), Name)) + Name = ""; } } diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 8e8962928d..b2a6864194 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -11043,12 +11043,11 @@ static Instruction *InstCombineLoadCast(InstCombiner &IC, LoadInst &LI, if (ConstantExpr *CE = dyn_cast(CI)) { // Instead of loading constant c string, use corresponding integer value // directly if string length is small enough. - const char *Str = GetConstantStringInfo(CE->getOperand(0)); - if (Str) { - unsigned len = strlen(Str); + std::string Str; + if (GetConstantStringInfo(CE->getOperand(0), Str) && !Str.empty()) { + unsigned len = Str.length(); const Type *Ty = cast(CE->getType())->getElementType(); unsigned numBits = Ty->getPrimitiveSizeInBits(); - // Replace LI with immediate integer store. if ((numBits >> 3) == len + 1) { APInt StrVal(numBits, 0); diff --git a/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/lib/Transforms/Scalar/SimplifyLibCalls.cpp index 9fd926d643..b878e4b479 100644 --- a/lib/Transforms/Scalar/SimplifyLibCalls.cpp +++ b/lib/Transforms/Scalar/SimplifyLibCalls.cpp @@ -551,10 +551,9 @@ struct VISIBILITY_HIDDEN StrChrOpt : public LibCallOptimization { // Otherwise, the character is a constant, see if the first argument is // a string literal. If so, we can constant fold. - const char *SI = GetConstantStringInfo(SrcStr); - if (!SI) + std::string Str; + if (!GetConstantStringInfo(SrcStr, Str)) return 0; - std::string Str = SI; // strchr can find the nul character. Str += '\0'; @@ -593,28 +592,27 @@ struct VISIBILITY_HIDDEN StrCmpOpt : public LibCallOptimization { if (Str1P == Str2P) // strcmp(x,x) -> 0 return ConstantInt::get(CI->getType(), 0); - const char *Str1 = GetConstantStringInfo(Str1P); - const char *Str2 = GetConstantStringInfo(Str1P); - - if (Str1) // strcmp("", x) -> *x + std::string Str1, Str2; + bool HasStr1 = GetConstantStringInfo(Str1P, Str1); + bool HasStr2 = GetConstantStringInfo(Str2P, Str2); + + if (HasStr1 && Str1.empty()) // strcmp("", x) -> *x return B.CreateZExt(B.CreateLoad(Str2P, "strcmpload"), CI->getType()); - if (Str2) // strcmp(x,"") -> *x + if (HasStr2 && Str2.empty()) // strcmp(x,"") -> *x return B.CreateZExt(B.CreateLoad(Str1P, "strcmpload"), CI->getType()); // strcmp(x, y) -> cnst (if both x and y are constant strings) - if (Str1 && Str2) - return ConstantInt::get(CI->getType(), strcmp(Str1, Str2)); + if (HasStr1 && HasStr2) + return ConstantInt::get(CI->getType(), strcmp(Str1.c_str(),Str2.c_str())); // strcmp(P, "x") -> memcmp(P, "x", 2) uint64_t Len1 = GetStringLength(Str1P); uint64_t Len2 = GetStringLength(Str2P); - if (Len1 || Len2) { // Choose the smallest Len excluding 0 which means 'unknown'. if (!Len1 || (Len2 && Len2 < Len1)) Len1 = Len2; - return EmitMemCmp(Str1P, Str2P, ConstantInt::get(TD->getIntPtrType(), Len1), B); } @@ -649,21 +647,21 @@ struct VISIBILITY_HIDDEN StrNCmpOpt : public LibCallOptimization { if (Length == 0) // strncmp(x,y,0) -> 0 return ConstantInt::get(CI->getType(), 0); - - const char *Str1 = GetConstantStringInfo(Str1P); - const char *Str2 = GetConstantStringInfo(Str2P); - - if (Str1) // strncmp("", x, n) -> *x + + std::string Str1, Str2; + bool HasStr1 = GetConstantStringInfo(Str1P, Str1); + bool HasStr2 = GetConstantStringInfo(Str2P, Str2); + + if (HasStr1 && Str1.empty()) // strncmp("", x, n) -> *x return B.CreateZExt(B.CreateLoad(Str2P, "strcmpload"), CI->getType()); - if (Str2) // strncmp(x, "", n) -> *x + if (HasStr2 && Str2.empty()) // strncmp(x, "", n) -> *x return B.CreateZExt(B.CreateLoad(Str1P, "strcmpload"), CI->getType()); // strncmp(x, y) -> cnst (if both x and y are constant strings) - if (Str1 && Str2) + if (HasStr1 && HasStr2) return ConstantInt::get(CI->getType(), - strncmp(Str1, Str2, Length)); - + strncmp(Str1.c_str(), Str2.c_str(), Length)); return 0; } }; @@ -1118,9 +1116,9 @@ struct VISIBILITY_HIDDEN PrintFOpt : public LibCallOptimization { return 0; // Check for a fixed format string. - const char *FormatCStr = GetConstantStringInfo(CI->getOperand(1)); - if (!FormatCStr) return 0; - std::string FormatStr = FormatCStr; + std::string FormatStr; + if (!GetConstantStringInfo(CI->getOperand(1), FormatStr)) + return 0; // Empty format string -> noop. if (FormatStr.empty()) // Tolerate printf's declared void. @@ -1178,9 +1176,9 @@ struct VISIBILITY_HIDDEN SPrintFOpt : public LibCallOptimization { return 0; // Check for a fixed format string. - const char *FormatCStr = GetConstantStringInfo(CI->getOperand(2)); - if (!FormatCStr) return 0; - std::string FormatStr = FormatCStr; + std::string FormatStr; + if (!GetConstantStringInfo(CI->getOperand(2), FormatStr)) + return 0; // If we just have a format string (nothing else crazy) transform it. if (CI->getNumOperands() == 3) { @@ -1299,9 +1297,9 @@ struct VISIBILITY_HIDDEN FPrintFOpt : public LibCallOptimization { return 0; // All the optimizations depend on the format string. - const char *FormatCStr = GetConstantStringInfo(CI->getOperand(2)); - if (!FormatCStr) return 0; - std::string FormatStr = FormatCStr; + std::string FormatStr; + if (!GetConstantStringInfo(CI->getOperand(2), FormatStr)) + return 0; // fprintf(F, "foo") --> fwrite("foo", 3, 1, F) if (CI->getNumOperands() == 3) { -- cgit v1.2.3