X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FIR%2FDIBuilder.cpp;h=a621f71a7f56b77c893f9fc6a921eebf6471c9a3;hb=79f9f85c04e1ed29670ed7a87df879bb5b42a0f1;hp=8dd5165eb2970290fcea9c4cbe16795aa21be417;hpb=99a4b59b85c622eaa83677cd4bd92c8c7c663606;p=oota-llvm.git diff --git a/lib/IR/DIBuilder.cpp b/lib/IR/DIBuilder.cpp index 8dd5165eb29..a621f71a7f5 100644 --- a/lib/IR/DIBuilder.cpp +++ b/lib/IR/DIBuilder.cpp @@ -102,7 +102,8 @@ DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename, StringRef Producer, bool isOptimized, StringRef Flags, unsigned RunTimeVer, StringRef SplitName, - DebugEmissionKind Kind) { + DebugEmissionKind Kind, + bool EmitDebugInfo) { assert(((Lang <= dwarf::DW_LANG_OCaml && Lang >= dwarf::DW_LANG_C89) || (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) && @@ -140,8 +141,14 @@ DICompileUnit DIBuilder::createCompileUnit(unsigned Lang, StringRef Filename, MDNode *CUNode = MDNode::get(VMContext, Elts); // Create a named metadata so that it is easier to find cu in a module. - NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); - NMD->addOperand(CUNode); + // Note that we only generate this when the caller wants to actually + // emit debug information. When we are only interested in tracking + // source line locations throughout the backend, we prevent codegen from + // emitting debug info in the final output by not generating llvm.dbg.cu. + if (EmitDebugInfo) { + NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); + NMD->addOperand(CUNode); + } return DICompileUnit(CUNode); } @@ -355,7 +362,6 @@ DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) { DIDerivedType DIBuilder::createTypedef(DIType Ty, StringRef Name, DIFile File, unsigned LineNo, DIDescriptor Context) { // typedefs are encoded in DIDerivedType format. - assert(Ty.isType() && "Invalid typedef type!"); Value *Elts[] = { GetTagConstant(VMContext, dwarf::DW_TAG_typedef), File.getFileNode(), @@ -714,9 +720,9 @@ DICompositeType DIBuilder::createUnionType(DIDescriptor Scope, StringRef Name, } /// createSubroutineType - Create subroutine type. -DICompositeType DIBuilder::createSubroutineType(DIFile File, - DIArray ParameterTypes, - unsigned Flags) { +DISubroutineType DIBuilder::createSubroutineType(DIFile File, + DITypeArray ParameterTypes, + unsigned Flags) { // TAG_subroutine_type is encoded in DICompositeType format. Value *Elts[] = { GetTagConstant(VMContext, dwarf::DW_TAG_subroutine_type), @@ -735,7 +741,7 @@ DICompositeType DIBuilder::createSubroutineType(DIFile File, nullptr, nullptr // Type Identifer }; - return DICompositeType(MDNode::get(VMContext, Elts)); + return DISubroutineType(MDNode::get(VMContext, Elts)); } /// createEnumerationType - Create debugging information entry for an @@ -869,11 +875,8 @@ void DIBuilder::retainType(DIType T) { /// createUnspecifiedParameter - Create unspeicified type descriptor /// for the subroutine type. -DIDescriptor DIBuilder::createUnspecifiedParameter() { - Value *Elts[] = { - GetTagConstant(VMContext, dwarf::DW_TAG_unspecified_parameters) - }; - return DIDescriptor(MDNode::get(VMContext, Elts)); +DIBasicType DIBuilder::createUnspecifiedParameter() { + return DIBasicType(); } /// createForwardDecl - Create a temporary forward-declared type that @@ -902,6 +905,40 @@ DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope, UniqueIdentifier.empty() ? nullptr : MDString::get(VMContext, UniqueIdentifier) }; + MDNode *Node = MDNode::get(VMContext, Elts); + DICompositeType RetTy(Node); + assert(RetTy.isCompositeType() && + "createForwardDecl result should be a DIType"); + if (!UniqueIdentifier.empty()) + retainType(RetTy); + return RetTy; +} + +/// createForwardDecl - Create a temporary forward-declared type that +/// can be RAUW'd if the full type is seen. +DICompositeType DIBuilder::createReplaceableForwardDecl( + unsigned Tag, StringRef Name, DIDescriptor Scope, DIFile F, unsigned Line, + unsigned RuntimeLang, uint64_t SizeInBits, uint64_t AlignInBits, + StringRef UniqueIdentifier) { + // Create a temporary MDNode. + Value *Elts[] = { + GetTagConstant(VMContext, Tag), + F.getFileNode(), + DIScope(getNonCompileUnitScope(Scope)).getRef(), + MDString::get(VMContext, Name), + ConstantInt::get(Type::getInt32Ty(VMContext), Line), + ConstantInt::get(Type::getInt64Ty(VMContext), SizeInBits), + ConstantInt::get(Type::getInt64Ty(VMContext), AlignInBits), + ConstantInt::get(Type::getInt32Ty(VMContext), 0), // Offset + ConstantInt::get(Type::getInt32Ty(VMContext), DIDescriptor::FlagFwdDecl), + nullptr, + DIArray(), + ConstantInt::get(Type::getInt32Ty(VMContext), RuntimeLang), + nullptr, + nullptr, //TemplateParams + UniqueIdentifier.empty() ? nullptr + : MDString::get(VMContext, UniqueIdentifier) + }; MDNode *Node = MDNode::getTemporary(VMContext, Elts); DICompositeType RetTy(Node); assert(RetTy.isCompositeType() && @@ -916,6 +953,18 @@ DIArray DIBuilder::getOrCreateArray(ArrayRef Elements) { return DIArray(MDNode::get(VMContext, Elements)); } +/// getOrCreateTypeArray - Get a DITypeArray, create one if required. +DITypeArray DIBuilder::getOrCreateTypeArray(ArrayRef Elements) { + SmallVector Elts; + for (unsigned i = 0, e = Elements.size(); i != e; ++i) { + if (Elements[i] && isa(Elements[i])) + Elts.push_back(DIType(cast(Elements[i])).getRef()); + else + Elts.push_back(Elements[i]); + } + return DITypeArray(MDNode::get(VMContext, Elts)); +} + /// getOrCreateSubrange - Create a descriptor for a value range. This /// implicitly uniques the values returned. DISubrange DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) { @@ -1035,18 +1084,41 @@ DIVariable DIBuilder::createComplexVariable(unsigned Tag, DIDescriptor Scope, DITypeRef Ty, ArrayRef Addr, unsigned ArgNo) { - SmallVector Elts; - Elts.push_back(GetTagConstant(VMContext, Tag)); - Elts.push_back(getNonCompileUnitScope(Scope)), - Elts.push_back(MDString::get(VMContext, Name)); - Elts.push_back(F); - Elts.push_back(ConstantInt::get(Type::getInt32Ty(VMContext), - (LineNo | (ArgNo << 24)))); - Elts.push_back(Ty); - Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext))); - Elts.push_back(Constant::getNullValue(Type::getInt32Ty(VMContext))); - Elts.append(Addr.begin(), Addr.end()); + assert(Addr.size() > 0 && "complex address is empty"); + Value *Elts[] = { + GetTagConstant(VMContext, Tag), + getNonCompileUnitScope(Scope), + MDString::get(VMContext, Name), + F, + ConstantInt::get(Type::getInt32Ty(VMContext), + (LineNo | (ArgNo << 24))), + Ty, + Constant::getNullValue(Type::getInt32Ty(VMContext)), + Constant::getNullValue(Type::getInt32Ty(VMContext)), + MDNode::get(VMContext, Addr) + }; + return DIVariable(MDNode::get(VMContext, Elts)); +} + +/// createVariablePiece - Create a descriptor to describe one part +/// of aggregate variable that is fragmented across multiple Values. +DIVariable DIBuilder::createVariablePiece(DIVariable Variable, + unsigned OffsetInBytes, + unsigned SizeInBytes) { + assert(SizeInBytes > 0 && "zero-size piece"); + Value *Addr[] = { + ConstantInt::get(Type::getInt32Ty(VMContext), OpPiece), + ConstantInt::get(Type::getInt32Ty(VMContext), OffsetInBytes), + ConstantInt::get(Type::getInt32Ty(VMContext), SizeInBytes) + }; + + assert((Variable->getNumOperands() == 8 || Variable.isVariablePiece()) && + "variable already has a complex address"); + SmallVector Elts; + for (unsigned i = 0; i < 8; ++i) + Elts.push_back(Variable->getOperand(i)); + Elts.push_back(MDNode::get(VMContext, Addr)); return DIVariable(MDNode::get(VMContext, Elts)); } @@ -1126,7 +1198,6 @@ DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name, assert(getNonCompileUnitScope(Context) && "Methods should have both a Context and a context that isn't " "the compile unit."); - Value *TElts[] = { GetTagConstant(VMContext, DW_TAG_base_type) }; Value *Elts[] = { GetTagConstant(VMContext, dwarf::DW_TAG_subprogram), F.getFileNode(), @@ -1146,7 +1217,7 @@ DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name, Fn, TParam, Constant::getNullValue(Type::getInt32Ty(VMContext)), - MDNode::getTemporary(VMContext, TElts), + nullptr, // FIXME: Do we want to use different scope/lines? ConstantInt::get(Type::getInt32Ty(VMContext), LineNo) }; @@ -1194,6 +1265,13 @@ DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope, DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File, unsigned Line, unsigned Col, unsigned Discriminator) { + // FIXME: This isn't thread safe nor the right way to defeat MDNode uniquing. + // I believe the right way is to have a self-referential element in the node. + // Also: why do we bother with line/column - they're not used and the + // documentation (SourceLevelDebugging.rst) claims the line/col are necessary + // for uniquing, yet then we have this other solution (because line/col were + // inadequate) anyway. Remove all 3 and replace them with a self-reference. + // Defeat MDNode uniquing for lexical blocks by using unique id. static unsigned int unique_id = 0; Value *Elts[] = {