void DIBuilder::finalize() {
DIArray Enums = getOrCreateArray(AllEnumTypes);
- DIType(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);
- DIType(TempRetainTypes).replaceAllUsesWith(RetainTypes);
+ TempRetainTypes->replaceAllUsesWith(RetainTypes.get());
DIArray SPs = getOrCreateArray(AllSubprograms);
- DIType(TempSubprograms).replaceAllUsesWith(SPs);
- for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
- DISubprogram SP(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);
- DIType(Temp).replaceAllUsesWith(AV);
+ TempMDTuple(Temp)->replaceAllUsesWith(AV.get());
}
}
DIArray GVs = getOrCreateArray(AllGVs);
- DIType(TempGVs).replaceAllUsesWith(GVs);
+ TempGVs->replaceAllUsesWith(GVs.get());
SmallVector<Metadata *, 16> RetainValuesI(AllImportedModules.begin(),
AllImportedModules.end());
DIArray IMs = getOrCreateArray(RetainValuesI);
- DIType(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.
- MDNode *CUNode = MDCompileUnit::get(
+ 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
}
trackIfUnresolved(CUNode);
- return DICompileUnit(CUNode);
+ return CUNode;
}
static DIImportedEntity
createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope Context,
Metadata *NS, unsigned Line, StringRef Name,
SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) {
- DIImportedEntity M = MDImportedEntity::get(C, Tag, Context, NS, Line, Name);
+ DIImportedEntity M =
+ MDImportedEntity::get(C, Tag, Context, DebugNodeRef(NS), Line, Name);
AllImportedModules.emplace_back(M.get());
return M;
}
}
DIDerivedType DIBuilder::createReferenceType(unsigned Tag, DIType RTy) {
- assert(RTy.isType() && "Unable to create reference type");
+ assert(RTy && "Unable to create reference type");
return MDDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr,
MDTypeRef::get(RTy), 0, 0, 0, 0);
}
DIDerivedType DIBuilder::createFriend(DIType Ty, DIType FriendTy) {
// typedefs are encoded in DIDerivedType format.
- assert(Ty.isType() && "Invalid type!");
- assert(FriendTy.isType() && "Invalid friend type!");
+ assert(Ty && "Invalid type!");
+ assert(FriendTy && "Invalid friend type!");
return MDDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0,
MDTypeRef::get(Ty), MDTypeRef::get(FriendTy), 0, 0,
0, 0);
DIDerivedType DIBuilder::createInheritance(DIType Ty, DIType BaseTy,
uint64_t BaseOffset,
unsigned Flags) {
- assert(Ty.isType() && "Unable to create inheritance");
+ assert(Ty && "Unable to create inheritance");
return MDDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr,
0, MDTypeRef::get(Ty), MDTypeRef::get(BaseTy), 0, 0,
BaseOffset, Flags);
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,
DIType VTableHolder,
MDNode *TemplateParams,
StringRef UniqueIdentifier) {
- assert((!Context || Context.isScope() || Context.isType()) &&
+ assert((!Context || isa<MDScope>(Context)) &&
"createClassType should be called with a valid Context");
// TAG_class_type is encoded in DICompositeType format.
DICompositeType R = MDCompositeType::get(
SmallVector<llvm::Metadata *, 16> Elts;
for (unsigned i = 0, e = Elements.size(); i != e; ++i) {
if (Elements[i] && isa<MDNode>(Elements[i]))
- Elts.push_back(MDTypeRef::get(DIType(cast<MDNode>(Elements[i]))));
+ Elts.push_back(MDTypeRef::get(cast<MDType>(Elements[i])));
else
Elts.push_back(Elements[i]);
}
}
static void checkGlobalVariableScope(DIDescriptor Context) {
- MDNode *TheCtx = getNonCompileUnitScope(Context);
- if (DIScope(TheCtx).isCompositeType()) {
- assert(!DICompositeType(TheCtx).getIdentifier() &&
+#ifndef NDEBUG
+ if (DICompositeType CT =
+ dyn_cast_or_null<MDCompositeType>(getNonCompileUnitScope(Context)))
+ assert(!CT.getIdentifier() &&
"Context of a global variable should not be a type with identifier");
- }
+#endif
}
DIGlobalVariable DIBuilder::createGlobalVariable(
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();
}
// FIXME: Why is "!Context" okay here?
// FIXME: WHy doesn't this check for a subprogram or lexical block (AFAICT
// the only valid scopes)?
- DIDescriptor Context(getNonCompileUnitScope(Scope));
- assert((!Context || Context.isScope()) &&
- "createLocalVariable should be called with a valid Context");
+ DIScope Context = getNonCompileUnitScope(Scope);
auto *Node = MDLocalVariable::get(
VMContext, Tag, cast_or_null<MDLocalScope>(Context.get()), Name, File,
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),
+ ScopeLine, nullptr, 0, 0, Flags, isOptimized, Fn,
cast_or_null<MDTuple>(TParams), cast_or_null<MDSubprogram>(Decl),
MDTuple::getTemporary(VMContext, None).release());
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), nullptr)
- .release();
+ isDefinition, ScopeLine, nullptr, 0, 0, Flags, isOptimized, Fn,
+ cast_or_null<MDTuple>(TParams), cast_or_null<MDSubprogram>(Decl),
+ nullptr).release();
}
DISubprogram DIBuilder::createMethod(DIDescriptor Context, StringRef Name,
"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 *Node = MDSubprogram::get(
- VMContext, MDScopeRef::get(DIScope(Context)), Name, LinkageName, F.get(),
- LineNo, cast_or_null<MDSubroutineType>(Ty.get()), isLocalToUnit,
+ 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);
+ isOptimized, Fn, cast_or_null<MDTuple>(TParam), nullptr, nullptr);
if (isDefinition)
- AllSubprograms.push_back(Node);
- DISubprogram S(Node);
- assert(S.isSubprogram() && "createMethod should return a valid DISubprogram");
- trackIfUnresolved(S);
- return S;
+ AllSubprograms.push_back(SP);
+ trackIfUnresolved(SP);
+ return SP;
}
DINameSpace DIBuilder::createNameSpace(DIDescriptor Scope, StringRef Name,
Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
DIExpression Expr,
Instruction *InsertBefore) {
- assert(VarInfo.isVariable() &&
- "empty or invalid DIVariable passed to dbg.declare");
+ assert(VarInfo && "empty or invalid DIVariable passed to dbg.declare");
if (!DeclareFn)
DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
Instruction *DIBuilder::insertDeclare(Value *Storage, DIVariable VarInfo,
DIExpression Expr,
BasicBlock *InsertAtEnd) {
- assert(VarInfo.isVariable() &&
- "empty or invalid DIVariable passed to dbg.declare");
+ assert(VarInfo && "empty or invalid DIVariable passed to dbg.declare");
if (!DeclareFn)
DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
DIExpression Expr,
Instruction *InsertBefore) {
assert(V && "no value passed to dbg.value");
- assert(VarInfo.isVariable() &&
- "empty or invalid DIVariable passed to dbg.value");
+ assert(VarInfo && "empty or invalid DIVariable passed to dbg.value");
if (!ValueFn)
ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
DIExpression Expr,
BasicBlock *InsertAtEnd) {
assert(V && "no value passed to dbg.value");
- assert(VarInfo.isVariable() &&
- "empty or invalid DIVariable passed to dbg.value");
+ assert(VarInfo && "empty or invalid DIVariable passed to dbg.value");
if (!ValueFn)
ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value);
}
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());
}