void DIBuilder::finalize() {
DIArray Enums = getOrCreateArray(AllEnumTypes);
- TempEnumTypes->replaceAllUsesWith(Enums);
+ TempEnumTypes->replaceAllUsesWith(Enums.get());
SmallVector<Metadata *, 16> RetainValues;
// Declarations and definitions of the same type may be retained. Some
if (RetainSet.insert(AllRetainTypes[I]).second)
RetainValues.push_back(AllRetainTypes[I]);
DIArray RetainTypes = getOrCreateArray(RetainValues);
- TempRetainTypes->replaceAllUsesWith(RetainTypes);
+ TempRetainTypes->replaceAllUsesWith(RetainTypes.get());
DIArray SPs = getOrCreateArray(AllSubprograms);
- TempSubprograms->replaceAllUsesWith(SPs);
- for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
- DISubprogram SP = cast<MDSubprogram>(SPs.getElement(i));
- if (MDNode *Temp = SP.getVariablesNodes()) {
+ TempSubprograms->replaceAllUsesWith(SPs.get());
+ for (unsigned i = 0, e = SPs.size(); i != e; ++i) {
+ DISubprogram SP = cast<MDSubprogram>(SPs[i]);
+ if (MDTuple *Temp = SP->getVariables().get()) {
const auto &PV = PreservedVariables.lookup(SP);
SmallVector<Metadata *, 4> Variables(PV.begin(), PV.end());
DIArray AV = getOrCreateArray(Variables);
- Temp->replaceAllUsesWith(AV);
+ TempMDTuple(Temp)->replaceAllUsesWith(AV.get());
}
}
DIArray GVs = getOrCreateArray(AllGVs);
- TempGVs->replaceAllUsesWith(GVs);
+ TempGVs->replaceAllUsesWith(GVs.get());
SmallVector<Metadata *, 16> RetainValuesI(AllImportedModules.begin(),
AllImportedModules.end());
DIArray IMs = getOrCreateArray(RetainValuesI);
- TempImportedModules->replaceAllUsesWith(IMs);
+ TempImportedModules->replaceAllUsesWith(IMs.get());
// Now that all temp nodes have been replaced or deleted, resolve remaining
// cycles.
// TODO: Once we make MDCompileUnit distinct, stop using temporaries here
// (just start with operands assigned to nullptr).
- TempEnumTypes = MDTuple::getTemporary(VMContext, None).release();
- TempRetainTypes = MDTuple::getTemporary(VMContext, None).release();
- TempSubprograms = MDTuple::getTemporary(VMContext, None).release();
- TempGVs = MDTuple::getTemporary(VMContext, None).release();
- TempImportedModules = MDTuple::getTemporary(VMContext, None).release();
+ TempEnumTypes = MDTuple::getTemporary(VMContext, None);
+ TempRetainTypes = MDTuple::getTemporary(VMContext, None);
+ TempSubprograms = MDTuple::getTemporary(VMContext, None);
+ TempGVs = MDTuple::getTemporary(VMContext, None);
+ TempImportedModules = MDTuple::getTemporary(VMContext, None);
// TODO: Switch to getDistinct(). We never want to merge compile units based
// on contents.
MDCompileUnit *CUNode = MDCompileUnit::get(
VMContext, Lang, MDFile::get(VMContext, Filename, Directory), Producer,
- isOptimized, Flags, RunTimeVer, SplitName, Kind, TempEnumTypes,
- TempRetainTypes, TempSubprograms, TempGVs, TempImportedModules);
+ isOptimized, Flags, RunTimeVer, SplitName, Kind, TempEnumTypes.get(),
+ TempRetainTypes.get(), TempSubprograms.get(), TempGVs.get(),
+ TempImportedModules.get());
// Create a named metadata so that it is easier to find cu in a module.
// Note that we only generate this when the caller wants to actually
SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) {
DIImportedEntity M =
MDImportedEntity::get(C, Tag, Context, DebugNodeRef(NS), Line, Name);
- AllImportedModules.emplace_back(M.get());
+ AllImportedModules.emplace_back(M);
return M;
}
DIType Ty, DIArray Val) {
return createTemplateValueParameterHelper(
VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty,
- Val);
+ Val.get());
}
DICompositeType DIBuilder::createClassType(DIDescriptor Context, StringRef Name,
auto *R =
MDCompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0,
nullptr, MDTypeRef::get(Ty), Size, AlignInBits, 0,
- DIType::FlagVector, Subscripts, 0, nullptr);
+ DebugNode::FlagVector, Subscripts, 0, nullptr);
trackIfUnresolved(R);
return R;
}
DIType DIBuilder::createArtificialType(DIType Ty) {
// FIXME: Restrict this to the nodes where it's valid.
- if (Ty.isArtificial())
+ if (Ty->isArtificial())
return Ty;
- return createTypeWithFlags(VMContext, Ty, DIType::FlagArtificial);
+ return createTypeWithFlags(VMContext, Ty, DebugNode::FlagArtificial);
}
DIType DIBuilder::createObjectPointerType(DIType Ty) {
// FIXME: Restrict this to the nodes where it's valid.
- if (Ty.isObjectPointer())
+ if (Ty->isObjectPointer())
return Ty;
- unsigned Flags = DIType::FlagObjectPointer | DIType::FlagArtificial;
+ unsigned Flags = DebugNode::FlagObjectPointer | DebugNode::FlagArtificial;
return createTypeWithFlags(VMContext, Ty, Flags);
}
void DIBuilder::retainType(DIType T) {
- assert(T.get() && "Expected non-null type");
+ assert(T && "Expected non-null type");
AllRetainTypes.emplace_back(T);
}
-DIBasicType DIBuilder::createUnspecifiedParameter() {
- return DIBasicType();
-}
+DIBasicType DIBuilder::createUnspecifiedParameter() { return nullptr; }
DICompositeType
DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIDescriptor Scope,
static void checkGlobalVariableScope(DIDescriptor Context) {
#ifndef NDEBUG
- if (DICompositeType CT =
+ if (auto *CT =
dyn_cast_or_null<MDCompositeType>(getNonCompileUnitScope(Context)))
- assert(!CT.getIdentifier() &&
+ assert(CT->getIdentifier().empty() &&
"Context of a global variable should not be a type with identifier");
#endif
}
auto *N = MDGlobalVariable::get(
VMContext, cast_or_null<MDScope>(Context.get()), Name, LinkageName, F,
- LineNumber, MDTypeRef::get(Ty), isLocalToUnit, true,
- getConstantOrNull(Val), cast_or_null<MDDerivedType>(Decl));
+ LineNumber, MDTypeRef::get(Ty), isLocalToUnit, true, Val,
+ cast_or_null<MDDerivedType>(Decl));
AllGVs.push_back(N);
return N;
}
return MDGlobalVariable::getTemporary(
VMContext, cast_or_null<MDScope>(Context.get()), Name, LinkageName,
- F, LineNumber, MDTypeRef::get(Ty), isLocalToUnit, false, getConstantOrNull(Val),
+ F, LineNumber, MDTypeRef::get(Ty), isLocalToUnit, false, Val,
cast_or_null<MDDerivedType>(Decl)).release();
}
unsigned ScopeLine, unsigned Flags,
bool isOptimized, Function *Fn,
MDNode *TParams, MDNode *Decl) {
- assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
+ assert(Ty->getTag() == dwarf::DW_TAG_subroutine_type &&
"function types should be subroutines");
auto *Node = MDSubprogram::get(
VMContext, MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))),
- Name, LinkageName, File.get(), LineNo,
- cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit, isDefinition,
- ScopeLine, nullptr, 0, 0, Flags, isOptimized, getConstantOrNull(Fn),
- cast_or_null<MDTuple>(TParams), cast_or_null<MDSubprogram>(Decl),
+ Name, LinkageName, File, LineNo, cast_or_null<MDSubroutineType>(Ty),
+ isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized,
+ Fn, cast_or_null<MDTuple>(TParams), cast_or_null<MDSubprogram>(Decl),
MDTuple::getTemporary(VMContext, None).release());
if (isDefinition)
return MDSubprogram::getTemporary(
VMContext,
MDScopeRef::get(DIScope(getNonCompileUnitScope(Context))), Name,
- LinkageName, File.get(), LineNo,
- cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit,
- isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized,
- getConstantOrNull(Fn), cast_or_null<MDTuple>(TParams),
+ LinkageName, File, LineNo, cast_or_null<MDSubroutineType>(Ty),
+ isLocalToUnit, isDefinition, ScopeLine, nullptr, 0, 0, Flags,
+ isOptimized, Fn, cast_or_null<MDTuple>(TParams),
cast_or_null<MDSubprogram>(Decl), nullptr)
.release();
}
DIType VTableHolder, unsigned Flags,
bool isOptimized, Function *Fn,
MDNode *TParam) {
- assert(Ty.getTag() == dwarf::DW_TAG_subroutine_type &&
+ assert(Ty->getTag() == dwarf::DW_TAG_subroutine_type &&
"function types should be subroutines");
assert(getNonCompileUnitScope(Context) &&
"Methods should have both a Context and a context that isn't "
"the compile unit.");
// FIXME: Do we want to use different scope/lines?
auto *SP = MDSubprogram::get(
- VMContext, MDScopeRef::get(cast<MDScope>(Context)), Name, LinkageName,
- F.get(), LineNo, cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit,
- isDefinition, LineNo, MDTypeRef::get(VTableHolder), VK, VIndex, Flags,
- isOptimized, getConstantOrNull(Fn), cast_or_null<MDTuple>(TParam),
- nullptr, nullptr);
+ VMContext, MDScopeRef::get(cast<MDScope>(Context)), Name, LinkageName, F,
+ LineNo, cast_or_null<MDSubroutineType>(Ty), isLocalToUnit, isDefinition,
+ LineNo, MDTypeRef::get(VTableHolder), VK, VIndex, Flags, isOptimized, Fn,
+ cast_or_null<MDTuple>(TParam), nullptr, nullptr);
if (isDefinition)
AllSubprograms.push_back(SP);
DILexicalBlockFile DIBuilder::createLexicalBlockFile(DIDescriptor Scope,
DIFile File,
unsigned Discriminator) {
- return MDLexicalBlockFile::get(VMContext, Scope, File.getFileNode(),
- Discriminator);
+ return MDLexicalBlockFile::get(VMContext, Scope, File, Discriminator);
}
DILexicalBlock DIBuilder::createLexicalBlock(DIDescriptor Scope, DIFile File,
// Make these distinct, to avoid merging two lexical blocks on the same
// file/line/column.
return MDLexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope),
- File.getFileNode(), Line, Col);
+ File, Line, Col);
}
static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) {
return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V));
}
+static Instruction *withDebugLoc(Instruction *I, const MDLocation *DL) {
+ I->setDebugLoc(const_cast<MDLocation *>(DL));
+ return I;
+}
+
Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
- DIExpression Expr,
+ DIExpression Expr, const MDLocation *DL,
Instruction *InsertBefore) {
assert(VarInfo && "empty or invalid DIVariable passed to dbg.declare");
+ assert(DL && "Expected debug loc");
+ assert(DL->getScope()->getSubprogram() ==
+ VarInfo->getScope()->getSubprogram() &&
+ "Expected matching subprograms");
if (!DeclareFn)
DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage),
MetadataAsValue::get(VMContext, VarInfo),
MetadataAsValue::get(VMContext, Expr)};
- return CallInst::Create(DeclareFn, Args, "", InsertBefore);
+ return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertBefore), DL);
}
Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
- DIExpression Expr,
+ DIExpression Expr, const MDLocation *DL,
BasicBlock *InsertAtEnd) {
assert(VarInfo && "empty or invalid DIVariable passed to dbg.declare");
+ assert(DL && "Expected debug loc");
+ assert(DL->getScope()->getSubprogram() ==
+ VarInfo->getScope()->getSubprogram() &&
+ "Expected matching subprograms");
if (!DeclareFn)
DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
// If this block already has a terminator then insert this intrinsic
// before the terminator.
if (TerminatorInst *T = InsertAtEnd->getTerminator())
- return CallInst::Create(DeclareFn, Args, "", T);
- else
- return CallInst::Create(DeclareFn, Args, "", InsertAtEnd);
+ return withDebugLoc(CallInst::Create(DeclareFn, Args, "", T), DL);
+ return withDebugLoc(CallInst::Create(DeclareFn, Args, "", InsertAtEnd), DL);
}
Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
DIVariable VarInfo,
DIExpression Expr,
+ const MDLocation *DL,
Instruction *InsertBefore) {
assert(V && "no value passed to dbg.value");
assert(VarInfo && "empty or invalid DIVariable passed to dbg.value");
+ assert(DL && "Expected debug loc");
+ assert(DL->getScope()->getSubprogram() ==
+ VarInfo->getScope()->getSubprogram() &&
+ "Expected matching subprograms");
if (!ValueFn)
ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
ConstantInt::get(Type::getInt64Ty(VMContext), Offset),
MetadataAsValue::get(VMContext, VarInfo),
MetadataAsValue::get(VMContext, Expr)};
- return CallInst::Create(ValueFn, Args, "", InsertBefore);
+ return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertBefore), DL);
}
Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, uint64_t Offset,
DIVariable VarInfo,
DIExpression Expr,
+ const MDLocation *DL,
BasicBlock *InsertAtEnd) {
assert(V && "no value passed to dbg.value");
assert(VarInfo && "empty or invalid DIVariable passed to dbg.value");
+ assert(DL && "Expected debug loc");
+ assert(DL->getScope()->getSubprogram() ==
+ VarInfo->getScope()->getSubprogram() &&
+ "Expected matching subprograms");
if (!ValueFn)
ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
ConstantInt::get(Type::getInt64Ty(VMContext), Offset),
MetadataAsValue::get(VMContext, VarInfo),
MetadataAsValue::get(VMContext, Expr)};
- return CallInst::Create(ValueFn, Args, "", InsertAtEnd);
+
+ return withDebugLoc(CallInst::Create(ValueFn, Args, "", InsertAtEnd), DL);
}
void DIBuilder::replaceVTableHolder(DICompositeType &T, DICompositeType VTableHolder) {
- T.setContainingType(VTableHolder);
+ {
+ TypedTrackingMDRef<MDCompositeTypeBase> N(T);
+ N->replaceVTableHolder(MDTypeRef::get(VTableHolder));
+ T = N.get();
+ }
// If this didn't create a self-reference, just return.
if (T != VTableHolder)
void DIBuilder::replaceArrays(DICompositeType &T, DIArray Elements,
DIArray TParams) {
- T.setArrays(Elements, TParams);
+ {
+ TypedTrackingMDRef<MDCompositeTypeBase> N(T);
+ if (Elements)
+ N->replaceElements(Elements);
+ if (TParams)
+ N->replaceTemplateParams(MDTemplateParameterArray(TParams));
+ T = N.get();
+ }
// If T isn't resolved, there's no problem.
if (!T->isResolved())
// arrays explicitly if they're unresolved, or else the cycles will be
// orphaned.
if (Elements)
- trackIfUnresolved(Elements);
+ trackIfUnresolved(Elements.get());
if (TParams)
- trackIfUnresolved(TParams);
+ trackIfUnresolved(TParams.get());
}