X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FIR%2FDIBuilder.cpp;h=a621f71a7f56b77c893f9fc6a921eebf6471c9a3;hb=7af88ec907537f9a5de343d439fbca1344f28a29;hp=92edacc04a77440842a37c7d0618ba17b3b3b5dd;hpb=675e527ab856409294cccc0641ffc7f981fdd5e1;p=oota-llvm.git diff --git a/lib/IR/DIBuilder.cpp b/lib/IR/DIBuilder.cpp index 92edacc04a7..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); } @@ -713,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), @@ -734,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 @@ -868,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 @@ -949,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) { @@ -1068,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)); }