CodeGen: Stop using DIDescriptor::is*() and auto-casting

Same as r234255, but for lib/CodeGen and lib/Target.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234258 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2015-04-06 23:27:40 +00:00
parent 573ca050d2
commit 0477045c32
22 changed files with 143 additions and 167 deletions

View File

@ -174,7 +174,8 @@ public:
const MachineInstrBuilder &addMetadata(const MDNode *MD) const {
MI->addOperand(*MF, MachineOperand::CreateMetadata(MD));
assert((MI->isDebugValue() ? MI->getDebugVariable().isVariable() : true) &&
assert((MI->isDebugValue() ? static_cast<bool>(MI->getDebugVariable())
: true) &&
"first MDNode argument of a DBG_VALUE not a DIVariable");
return *this;
}
@ -356,8 +357,8 @@ inline MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL,
unsigned Reg, unsigned Offset,
const MDNode *Variable, const MDNode *Expr) {
assert(isa<MDLocalVariable>(Variable) && "not a DIVariable");
assert(DIExpression(Expr)->isValid() && "not a DIExpression");
assert(DIVariable(Variable)->isValidLocationForIntrinsic(DL) &&
assert(cast<MDExpression>(Expr)->isValid() && "not a DIExpression");
assert(cast<MDLocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
"Expected inlined-at fields to agree");
if (IsIndirect)
return BuildMI(MF, DL, MCID)
@ -385,7 +386,7 @@ inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB,
unsigned Reg, unsigned Offset,
const MDNode *Variable, const MDNode *Expr) {
assert(isa<MDLocalVariable>(Variable) && "not a DIVariable");
assert(DIExpression(Expr)->isValid() && "not a DIExpression");
assert(cast<MDExpression>(Expr)->isValid() && "not a DIExpression");
MachineFunction &MF = *BB.getParent();
MachineInstr *MI =
BuildMI(MF, DL, MCID, IsIndirect, Reg, Offset, Variable, Expr);

View File

@ -671,8 +671,8 @@ static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) {
OS << "DEBUG_VALUE: ";
DIVariable V = MI->getDebugVariable();
if (V.getContext().isSubprogram()) {
StringRef Name = DISubprogram(V.getContext()).getDisplayName();
if (DISubprogram SP = dyn_cast<MDSubprogram>(V.getContext())) {
StringRef Name = SP.getDisplayName();
if (!Name.empty())
OS << Name << ":";
}

View File

@ -43,7 +43,7 @@ public:
Value(const MDNode *Var, const MDNode *Expr, MachineLocation Loc)
: Variable(Var), Expression(Expr), EntryKind(E_Location), Loc(Loc) {
assert(isa<MDLocalVariable>(Var));
assert(DIExpression(Expr)->isValid());
assert(cast<MDExpression>(Expr)->isValid());
}
/// The variable to which this location entry corresponds.
@ -75,9 +75,11 @@ public:
const ConstantInt *getConstantInt() const { return Constant.CIP; }
MachineLocation getLoc() const { return Loc; }
const MDNode *getVariableNode() const { return Variable; }
DIVariable getVariable() const { return DIVariable(Variable); }
DIVariable getVariable() const { return cast<MDLocalVariable>(Variable); }
bool isBitPiece() const { return getExpression().isBitPiece(); }
DIExpression getExpression() const { return DIExpression(Expression); }
DIExpression getExpression() const {
return cast_or_null<MDExpression>(Expression);
}
friend bool operator==(const Value &, const Value &);
friend bool operator<(const Value &, const Value &);
};
@ -101,10 +103,11 @@ public:
/// Return true if the merge was successful.
bool MergeValues(const DebugLocEntry &Next) {
if (Begin == Next.Begin) {
DIExpression Expr(Values[0].Expression);
DIVariable Var(Values[0].Variable);
DIExpression NextExpr(Next.Values[0].Expression);
DIVariable NextVar(Next.Values[0].Variable);
DIExpression Expr = cast_or_null<MDExpression>(Values[0].Expression);
DIVariable Var = cast_or_null<MDLocalVariable>(Values[0].Variable);
DIExpression NextExpr =
cast_or_null<MDExpression>(Next.Values[0].Expression);
DIVariable NextVar = cast_or_null<MDLocalVariable>(Next.Values[0].Variable);
if (Var == NextVar && Expr.isBitPiece() &&
NextExpr.isBitPiece()) {
addValues(Next.Values);

View File

@ -101,7 +101,7 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(DIGlobalVariable GV) {
if (DIE *Die = getDIE(GV))
return Die;
assert(GV.isGlobalVariable());
assert(GV);
DIScope GVContext = GV.getContext();
DIType GTy = DD->resolve(GV.getType());
@ -307,7 +307,7 @@ void DwarfCompileUnit::constructScopeDIE(
DIScope DS(Scope->getScopeNode());
assert((Scope->getInlinedAt() || !DS.isSubprogram()) &&
assert((Scope->getInlinedAt() || !isa<MDSubprogram>(DS)) &&
"Only handle inlined subprograms here, use "
"constructSubprogramScopeDIE for non-inlined "
"subprograms");
@ -318,7 +318,7 @@ void DwarfCompileUnit::constructScopeDIE(
// avoid creating un-used children then removing them later when we find out
// the scope DIE is null.
std::unique_ptr<DIE> ScopeDIE;
if (Scope->getParent() && DS.isSubprogram()) {
if (Scope->getParent() && isa<MDSubprogram>(DS)) {
ScopeDIE = constructInlinedScopeDIE(Scope);
if (!ScopeDIE)
return;
@ -340,7 +340,7 @@ void DwarfCompileUnit::constructScopeDIE(
// There is no need to emit empty lexical block DIE.
for (const auto &E : DD->findImportedEntitiesForScope(DS))
Children.push_back(
constructImportedEntityDIE(DIImportedEntity(E.second)));
constructImportedEntityDIE(cast<MDImportedEntity>(E.second)));
}
// If there are only other scopes as children, put them directly in the
@ -562,9 +562,7 @@ void DwarfCompileUnit::constructSubprogramScopeDIE(LexicalScope *Scope) {
assert(Scope && Scope->getScopeNode());
assert(!Scope->getInlinedAt());
assert(!Scope->isAbstractScope());
DISubprogram Sub(Scope->getScopeNode());
assert(Sub.isSubprogram());
DISubprogram Sub = cast<MDSubprogram>(Scope->getScopeNode());
DD->getProcessedSPNodes().insert(Sub);
@ -607,7 +605,7 @@ DwarfCompileUnit::constructAbstractSubprogramScopeDIE(LexicalScope *Scope) {
if (AbsDef)
return;
DISubprogram SP(Scope->getScopeNode());
DISubprogram SP = cast<MDSubprogram>(Scope->getScopeNode());
DIE *ContextDIE;
@ -641,14 +639,14 @@ DwarfCompileUnit::constructImportedEntityDIE(const DIImportedEntity &Module) {
insertDIE(Module, IMDie.get());
DIE *EntityDie;
DIDescriptor Entity = resolve(Module.getEntity());
if (Entity.isNameSpace())
EntityDie = getOrCreateNameSpace(DINameSpace(Entity));
else if (Entity.isSubprogram())
EntityDie = getOrCreateSubprogramDIE(DISubprogram(Entity));
else if (Entity.isType())
EntityDie = getOrCreateTypeDIE(DIType(Entity));
else if (Entity.isGlobalVariable())
EntityDie = getOrCreateGlobalVariableDIE(DIGlobalVariable(Entity));
if (auto *NS = dyn_cast<MDNamespace>(Entity))
EntityDie = getOrCreateNameSpace(NS);
else if (auto *SP = dyn_cast<MDSubprogram>(Entity))
EntityDie = getOrCreateSubprogramDIE(SP);
else if (auto *T = dyn_cast<MDType>(Entity))
EntityDie = getOrCreateTypeDIE(T);
else if (auto *GV = dyn_cast<MDGlobalVariable>(Entity))
EntityDie = getOrCreateGlobalVariableDIE(GV);
else
EntityDie = getDIE(Entity);
assert(EntityDie);
@ -681,7 +679,7 @@ void DwarfCompileUnit::finishSubprogramDefinition(DISubprogram SP) {
}
}
void DwarfCompileUnit::collectDeadVariables(DISubprogram SP) {
assert(SP.isSubprogram() && "CU's subprogram list contains a non-subprogram");
assert(SP && "CU's subprogram list contains a non-subprogram");
assert(SP.isDefinition() &&
"CU's subprogram list contains a subprogram declaration");
DIArray Variables = SP.getVariables();
@ -693,8 +691,7 @@ void DwarfCompileUnit::collectDeadVariables(DISubprogram SP) {
SPDIE = getDIE(SP);
assert(SPDIE);
for (unsigned vi = 0, ve = Variables.getNumElements(); vi != ve; ++vi) {
DIVariable DV(Variables.getElement(vi));
assert(DV.isVariable());
DIVariable DV = cast<MDLocalVariable>(Variables.getElement(vi));
DbgVariable NewVar(DV, DIExpression(), DD);
auto VariableDie = constructVariableDIE(NewVar);
applyVariableAttributes(NewVar, *VariableDie);

View File

@ -134,7 +134,7 @@ template <typename T> T DbgVariable::resolve(DIRef<T> Ref) const {
}
bool DbgVariable::isBlockByrefVariable() const {
assert(Var.isVariable() && "Invalid complex DbgVariable!");
assert(Var && "Invalid complex DbgVariable!");
return Var.isBlockByrefVariable(DD->getTypeIdentifierMap());
}
@ -171,11 +171,11 @@ DIType DbgVariable::getType() const {
uint16_t tag = Ty.getTag();
if (tag == dwarf::DW_TAG_pointer_type)
subType = resolve(DIDerivedType(Ty).getTypeDerivedFrom());
subType = resolve(DITypeRef(cast<MDDerivedType>(Ty)->getBaseType()));
DIArray Elements = DICompositeType(subType).getElements();
DIArray Elements(cast<MDCompositeTypeBase>(subType)->getElements());
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
DIDerivedType DT(Elements.getElement(i));
DIDerivedType DT = cast<MDDerivedTypeBase>(Elements.getElement(i));
if (getName() == DT.getName())
return (resolve(DT.getTypeDerivedFrom()));
}
@ -302,11 +302,10 @@ void DwarfDebug::addSubprogramNames(DISubprogram SP, DIE &Die) {
bool DwarfDebug::isSubprogramContext(const MDNode *Context) {
if (!Context)
return false;
DIDescriptor D(Context);
if (D.isSubprogram())
if (isa<MDSubprogram>(Context))
return true;
if (D.isType())
return isSubprogramContext(resolve(DIType(Context).getContext()));
if (DIType T = dyn_cast<MDType>(Context))
return isSubprogramContext(resolve(T.getContext()));
return false;
}
@ -420,7 +419,7 @@ DwarfCompileUnit &DwarfDebug::constructDwarfCompileUnit(DICompileUnit DIUnit) {
void DwarfDebug::constructAndAddImportedEntityDIE(DwarfCompileUnit &TheCU,
const MDNode *N) {
DIImportedEntity Module(N);
DIImportedEntity Module = cast<MDImportedEntity>(N);
if (DIE *D = TheCU.getOrCreateContextDIE(Module.getContext()))
D->addChild(TheCU.constructImportedEntityDIE(Module));
}
@ -444,12 +443,12 @@ void DwarfDebug::beginModule() {
SingleCU = CU_Nodes->getNumOperands() == 1;
for (MDNode *N : CU_Nodes->operands()) {
DICompileUnit CUNode(N);
DICompileUnit CUNode = cast<MDCompileUnit>(N);
DwarfCompileUnit &CU = constructDwarfCompileUnit(CUNode);
DIArray ImportedEntities = CUNode.getImportedEntities();
for (unsigned i = 0, e = ImportedEntities.getNumElements(); i != e; ++i)
ScopesWithImportedEntities.push_back(std::make_pair(
DIImportedEntity(ImportedEntities.getElement(i)).getContext(),
cast<MDImportedEntity>(ImportedEntities.getElement(i))->getScope(),
ImportedEntities.getElement(i)));
// Stable sort to preserve the order of appearance of imported entities.
// This is to avoid out-of-order processing of interdependent declarations
@ -458,24 +457,25 @@ void DwarfDebug::beginModule() {
ScopesWithImportedEntities.end(), less_first());
DIArray GVs = CUNode.getGlobalVariables();
for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i)
CU.getOrCreateGlobalVariableDIE(DIGlobalVariable(GVs.getElement(i)));
CU.getOrCreateGlobalVariableDIE(
cast<MDGlobalVariable>(GVs.getElement(i)));
DIArray SPs = CUNode.getSubprograms();
for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i)
SPMap.insert(std::make_pair(SPs.getElement(i), &CU));
DIArray EnumTypes = CUNode.getEnumTypes();
for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i) {
DIType Ty(EnumTypes.getElement(i));
DIType Ty = cast<MDType>(EnumTypes.getElement(i));
// The enum types array by design contains pointers to
// MDNodes rather than DIRefs. Unique them here.
DIType UniqueTy(resolve(Ty.getRef()));
DIType UniqueTy = cast<MDType>(resolve(Ty.getRef()));
CU.getOrCreateTypeDIE(UniqueTy);
}
DIArray RetainedTypes = CUNode.getRetainedTypes();
for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i) {
DIType Ty(RetainedTypes.getElement(i));
DIType Ty = cast<MDType>(RetainedTypes.getElement(i));
// The retained types array by design contains pointers to
// MDNodes rather than DIRefs. Unique them here.
DIType UniqueTy(resolve(Ty.getRef()));
DIType UniqueTy = cast<MDType>(resolve(Ty.getRef()));
CU.getOrCreateTypeDIE(UniqueTy);
}
// Emit imported_modules last so that the relevant context is already
@ -509,7 +509,7 @@ void DwarfDebug::finishVariableDefinitions() {
void DwarfDebug::finishSubprogramDefinitions() {
for (const auto &P : SPMap)
forBothCUs(*P.second, [&](DwarfCompileUnit &CU) {
CU.finishSubprogramDefinition(DISubprogram(P.first));
CU.finishSubprogramDefinition(cast<MDSubprogram>(P.first));
});
}
@ -520,14 +520,14 @@ void DwarfDebug::collectDeadVariables() {
if (NamedMDNode *CU_Nodes = M->getNamedMetadata("llvm.dbg.cu")) {
for (MDNode *N : CU_Nodes->operands()) {
DICompileUnit TheCU(N);
DICompileUnit TheCU = cast<MDCompileUnit>(N);
// Construct subprogram DIE and add variables DIEs.
DwarfCompileUnit *SPCU =
static_cast<DwarfCompileUnit *>(CUMap.lookup(TheCU));
assert(SPCU && "Unable to find Compile Unit!");
DIArray Subprograms = TheCU.getSubprograms();
for (unsigned i = 0, e = Subprograms.getNumElements(); i != e; ++i) {
DISubprogram SP(Subprograms.getElement(i));
DISubprogram SP = cast<MDSubprogram>(Subprograms.getElement(i));
if (ProcessedSPNodes.count(SP) != 0)
continue;
SPCU->collectDeadVariables(SP);
@ -732,10 +732,10 @@ void DwarfDebug::collectVariableInfoFromMMITable(
if (!Scope)
continue;
DIVariable DV(VI.Var);
DIVariable DV = cast<MDLocalVariable>(VI.Var);
assert(DV->isValidLocationForIntrinsic(VI.Loc) &&
"Expected inlined-at fields to agree");
DIExpression Expr(VI.Expr);
DIExpression Expr = cast_or_null<MDExpression>(VI.Expr);
ensureAbstractVariableIsCreatedIfScoped(DV, Scope->getScopeNode());
auto RegVar = make_unique<DbgVariable>(DV, Expr, this, VI.Slot);
if (InfoHolder.addScopeVariable(Scope, RegVar.get()))
@ -894,7 +894,7 @@ DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU, DISubprogram SP,
collectVariableInfoFromMMITable(Processed);
for (const auto &I : DbgValues) {
DIVariable DV(I.first);
DIVariable DV = cast<MDLocalVariable>(I.first);
if (Processed.count(DV))
continue;
@ -942,8 +942,7 @@ DwarfDebug::collectVariableInfo(DwarfCompileUnit &TheCU, DISubprogram SP,
// Collect info for variables that were optimized out.
DIArray Variables = SP.getVariables();
for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) {
DIVariable DV(Variables.getElement(i));
assert(DV.isVariable());
DIVariable DV = cast<MDLocalVariable>(Variables.getElement(i));
if (!Processed.insert(DV).second)
continue;
if (LexicalScope *Scope = LScopes.findLexicalScope(DV.get()->getScope())) {
@ -1140,8 +1139,8 @@ void DwarfDebug::beginFunction(const MachineFunction *MF) {
// The first mention of a function argument gets the CurrentFnBegin
// label, so arguments are visible when breaking at function entry.
DIVariable DIVar(Ranges.front().first->getDebugVariable());
if (DIVar.isVariable() && DIVar.getTag() == dwarf::DW_TAG_arg_variable &&
DIVariable DIVar = Ranges.front().first->getDebugVariable();
if (DIVar.getTag() == dwarf::DW_TAG_arg_variable &&
getDISubprogram(DIVar.getContext()).describes(MF->getFunction())) {
LabelsBeforeInsn[Ranges.front().first] = Asm->getFunctionBegin();
if (Ranges.front().first->getDebugExpression().isBitPiece()) {
@ -1198,7 +1197,7 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
Asm->OutStreamer.getContext().setDwarfCompileUnitID(0);
LexicalScope *FnScope = LScopes.getCurrentFunctionScope();
DISubprogram SP(FnScope->getScopeNode());
DISubprogram SP = cast<MDSubprogram>(FnScope->getScopeNode());
DwarfCompileUnit &TheCU = *SPMap.lookup(SP);
SmallPtrSet<const MDNode *, 16> ProcessedVars;
@ -1228,13 +1227,11 @@ void DwarfDebug::endFunction(const MachineFunction *MF) {
#endif
// Construct abstract scopes.
for (LexicalScope *AScope : LScopes.getAbstractScopesList()) {
DISubprogram SP(AScope->getScopeNode());
assert(SP.isSubprogram());
DISubprogram SP = cast<MDSubprogram>(AScope->getScopeNode());
// Collect info for variables that were optimized out.
DIArray Variables = SP.getVariables();
for (unsigned i = 0, e = Variables.getNumElements(); i != e; ++i) {
DIVariable DV(Variables.getElement(i));
assert(DV && DV.isVariable());
DIVariable DV = cast<MDLocalVariable>(Variables.getElement(i));
if (!ProcessedVars.insert(DV).second)
continue;
ensureAbstractVariableIsCreated(DV, DV.getContext());
@ -1269,12 +1266,11 @@ void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
StringRef Dir;
unsigned Src = 1;
unsigned Discriminator = 0;
if (DIScope Scope = DIScope(S)) {
assert(Scope.isScope());
if (DIScope Scope = cast_or_null<MDScope>(S)) {
Fn = Scope.getFilename();
Dir = Scope.getDirectory();
if (Scope.isLexicalBlockFile())
Discriminator = DILexicalBlockFile(S).getDiscriminator();
if (DILexicalBlockFile LBF = dyn_cast<MDLexicalBlockFile>(Scope))
Discriminator = LBF.getDiscriminator();
unsigned CUID = Asm->OutStreamer.getContext().getDwarfCompileUnitID();
Src = static_cast<DwarfCompileUnit &>(*InfoHolder.getUnits()[CUID])

View File

@ -153,7 +153,7 @@ public:
}
bool variableHasComplexAddress() const {
assert(Var.isVariable() && "Invalid complex DbgVariable!");
assert(Var && "Invalid complex DbgVariable!");
assert(Expr.size() == 1 &&
"variableHasComplexAddress() invoked on multi-FI variable");
return Expr.back().getNumElements() > 0;

View File

@ -175,8 +175,8 @@ static bool isShareableAcrossCUs(DIDescriptor D) {
// level already) but may be implementable for some value in projects
// building multiple independent libraries with LTO and then linking those
// together.
return (D.isType() ||
(D.isSubprogram() && !DISubprogram(D).isDefinition())) &&
return (isa<MDType>(D) ||
(isa<MDSubprogram>(D) && !cast<MDSubprogram>(D)->isDefinition())) &&
!GenerateDwarfTypeUnits;
}
@ -397,7 +397,7 @@ void DwarfUnit::addSourceLine(DIE &Die, unsigned Line, StringRef File,
/// addSourceLine - Add location information to specified debug information
/// entry.
void DwarfUnit::addSourceLine(DIE &Die, DIVariable V) {
assert(V.isVariable());
assert(V);
addSourceLine(Die, V.getLineNumber(), V.getContext().getFilename(),
V.getContext().getDirectory());
@ -406,7 +406,7 @@ void DwarfUnit::addSourceLine(DIE &Die, DIVariable V) {
/// addSourceLine - Add location information to specified debug information
/// entry.
void DwarfUnit::addSourceLine(DIE &Die, DIGlobalVariable G) {
assert(G.isGlobalVariable());
assert(G);
addSourceLine(Die, G.getLineNumber(), G.getFilename(), G.getDirectory());
}
@ -414,7 +414,7 @@ void DwarfUnit::addSourceLine(DIE &Die, DIGlobalVariable G) {
/// addSourceLine - Add location information to specified debug information
/// entry.
void DwarfUnit::addSourceLine(DIE &Die, DISubprogram SP) {
assert(SP.isSubprogram());
assert(SP);
addSourceLine(Die, SP.getLineNumber(), SP.getFilename(), SP.getDirectory());
}
@ -422,7 +422,7 @@ void DwarfUnit::addSourceLine(DIE &Die, DISubprogram SP) {
/// addSourceLine - Add location information to specified debug information
/// entry.
void DwarfUnit::addSourceLine(DIE &Die, DIType Ty) {
assert(Ty.isType());
assert(Ty);
addSourceLine(Die, Ty.getLineNumber(), Ty.getFilename(), Ty.getDirectory());
}
@ -430,7 +430,7 @@ void DwarfUnit::addSourceLine(DIE &Die, DIType Ty) {
/// addSourceLine - Add location information to specified debug information
/// entry.
void DwarfUnit::addSourceLine(DIE &Die, DIObjCProperty Ty) {
assert(Ty.isObjCProperty());
assert(Ty);
DIFile File = Ty.getFile();
addSourceLine(Die, Ty.getLineNumber(), File.getFilename(),
@ -529,12 +529,12 @@ void DwarfUnit::addBlockByrefAddress(const DbgVariable &DV, DIE &Die,
StringRef varName = DV.getName();
if (Tag == dwarf::DW_TAG_pointer_type) {
DIDerivedType DTy(Ty);
DIDerivedType DTy = cast<MDDerivedType>(Ty);
TmpTy = resolve(DTy.getTypeDerivedFrom());
isPointer = true;
}
DICompositeType blockStruct(TmpTy);
DICompositeType blockStruct = cast<MDCompositeTypeBase>(TmpTy);
// Find the __forwarding field and the variable field in the __Block_byref
// struct.
@ -543,7 +543,7 @@ void DwarfUnit::addBlockByrefAddress(const DbgVariable &DV, DIE &Die,
DIDerivedType forwardingField;
for (unsigned i = 0, N = Fields.getNumElements(); i < N; ++i) {
DIDerivedType DT(Fields.getElement(i));
DIDerivedType DT = cast<MDDerivedTypeBase>(Fields.getElement(i));
StringRef fieldName = DT.getName();
if (fieldName == "__forwarding")
forwardingField = DT;
@ -599,8 +599,7 @@ void DwarfUnit::addBlockByrefAddress(const DbgVariable &DV, DIE &Die,
/// Return true if type encoding is unsigned.
static bool isUnsignedDIType(DwarfDebug *DD, DIType Ty) {
DIDerivedType DTy(Ty);
if (DTy.isDerivedType()) {
if (DIDerivedType DTy = dyn_cast<MDDerivedTypeBase>(Ty)) {
dwarf::Tag T = (dwarf::Tag)Ty.getTag();
// Encode pointer constants as unsigned bytes. This is used at least for
// null pointer constant emission.
@ -630,8 +629,7 @@ static bool isUnsignedDIType(DwarfDebug *DD, DIType Ty) {
return false;
}
DIBasicType BTy(Ty);
assert(BTy.isBasicType());
DIBasicType BTy = cast<MDBasicType>(Ty);
unsigned Encoding = BTy.getEncoding();
assert((Encoding == dwarf::DW_ATE_unsigned ||
Encoding == dwarf::DW_ATE_unsigned_char ||
@ -668,8 +666,8 @@ static uint64_t getBaseTypeSize(DwarfDebug *DD, DIDerivedType Ty) {
BaseType.getTag() == dwarf::DW_TAG_rvalue_reference_type)
return Ty.getSizeInBits();
if (BaseType.isDerivedType())
return getBaseTypeSize(DD, DIDerivedType(BaseType));
if (auto *DT = dyn_cast<MDDerivedTypeBase>(BaseType))
return getBaseTypeSize(DD, DT);
return BaseType.getSizeInBits();
}
@ -771,25 +769,23 @@ void DwarfUnit::addTemplateParams(DIE &Buffer, DIArray TParams) {
// Add template parameters.
for (unsigned i = 0, e = TParams.getNumElements(); i != e; ++i) {
DIDescriptor Element = TParams.getElement(i);
if (Element.isTemplateTypeParameter())
constructTemplateTypeParameterDIE(Buffer,
DITemplateTypeParameter(Element));
else if (Element.isTemplateValueParameter())
constructTemplateValueParameterDIE(Buffer,
DITemplateValueParameter(Element));
if (auto *TTP = dyn_cast<MDTemplateTypeParameter>(Element))
constructTemplateTypeParameterDIE(Buffer, TTP);
else if (auto *TVP = dyn_cast<MDTemplateValueParameter>(Element))
constructTemplateValueParameterDIE(Buffer, TVP);
}
}
/// getOrCreateContextDIE - Get context owner's DIE.
DIE *DwarfUnit::getOrCreateContextDIE(DIScope Context) {
if (!Context || Context.isFile())
if (!Context || isa<MDFile>(Context))
return &getUnitDie();
if (Context.isType())
return getOrCreateTypeDIE(DIType(Context));
if (Context.isNameSpace())
return getOrCreateNameSpace(DINameSpace(Context));
if (Context.isSubprogram())
return getOrCreateSubprogramDIE(DISubprogram(Context));
if (auto *T = dyn_cast<MDType>(Context))
return getOrCreateTypeDIE(T);
if (auto *NS = dyn_cast<MDNamespace>(Context))
return getOrCreateNameSpace(NS);
if (auto *SP = dyn_cast<MDSubprogram>(Context))
return getOrCreateSubprogramDIE(SP);
return getDIE(Context);
}
@ -815,14 +811,14 @@ DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) {
if (!TyNode)
return nullptr;
DIType Ty(TyNode);
assert(Ty.isType());
DIType Ty = cast<MDType>(TyNode);
assert(Ty == resolve(Ty.getRef()) &&
"type was not uniqued, possible ODR violation.");
// DW_TAG_restrict_type is not supported in DWARF2
if (Ty.getTag() == dwarf::DW_TAG_restrict_type && DD->getDwarfVersion() <= 2)
return getOrCreateTypeDIE(resolve(DIDerivedType(Ty).getTypeDerivedFrom()));
return getOrCreateTypeDIE(
resolve(DITypeRef(cast<MDDerivedType>(Ty)->getBaseType())));
// Construct the context before querying for the existence of the DIE in case
// such construction creates the DIE.
@ -838,10 +834,9 @@ DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) {
updateAcceleratorTables(Context, Ty, TyDIE);
if (Ty.isBasicType())
constructTypeDIE(TyDIE, DIBasicType(Ty));
else if (Ty.isCompositeType()) {
DICompositeType CTy(Ty);
if (auto *BT = dyn_cast<MDBasicType>(Ty))
constructTypeDIE(TyDIE, BT);
else if (DICompositeType CTy = dyn_cast<MDCompositeTypeBase>(Ty)) {
if (GenerateDwarfTypeUnits && !Ty.isForwardDecl())
if (MDString *TypeId = CTy.getIdentifier()) {
DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
@ -850,8 +845,7 @@ DIE *DwarfUnit::getOrCreateTypeDIE(const MDNode *TyNode) {
}
constructTypeDIE(TyDIE, CTy);
} else {
assert(Ty.isDerivedType() && "Unknown kind of DIType");
constructTypeDIE(TyDIE, DIDerivedType(Ty));
constructTypeDIE(TyDIE, cast<MDDerivedType>(Ty));
}
return &TyDIE;
@ -861,8 +855,7 @@ void DwarfUnit::updateAcceleratorTables(DIScope Context, DIType Ty,
const DIE &TyDIE) {
if (!Ty.getName().empty() && !Ty.isForwardDecl()) {
bool IsImplementation = 0;
if (Ty.isCompositeType()) {
DICompositeType CT(Ty);
if (DICompositeType CT = dyn_cast<MDCompositeTypeBase>(Ty)) {
// A runtime language of 0 actually means C/C++ and that any
// non-negative value is some version of Objective-C/C++.
IsImplementation = (CT.getRunTimeLang() == 0) || CT.isObjcClassComplete();
@ -870,8 +863,8 @@ void DwarfUnit::updateAcceleratorTables(DIScope Context, DIType Ty,
unsigned Flags = IsImplementation ? dwarf::DW_FLAG_type_implementation : 0;
DD->addAccelType(Ty.getName(), TyDIE, Flags);
if (!Context || Context.isCompileUnit() || Context.isFile() ||
Context.isNameSpace())
if (!Context || isa<MDCompileUnit>(Context) || isa<MDFile>(Context) ||
isa<MDNamespace>(Context))
addGlobalType(Ty, TyDIE, Context);
}
}
@ -912,7 +905,7 @@ std::string DwarfUnit::getParentContextString(DIScope Context) const {
std::string CS;
SmallVector<DIScope, 1> Parents;
while (!Context.isCompileUnit()) {
while (!isa<MDCompileUnit>(Context)) {
Parents.push_back(Context);
if (Context.getContext())
Context = resolve(Context.getContext());
@ -929,7 +922,7 @@ std::string DwarfUnit::getParentContextString(DIScope Context) const {
I != E; ++I) {
DIScope Ctx = *I;
StringRef Name = Ctx.getName();
if (Name.empty() && Ctx.isNameSpace())
if (Name.empty() && isa<MDNamespace>(Ctx))
Name = "(anonymous namespace)";
if (!Name.empty()) {
CS += Name;
@ -1020,7 +1013,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
break;
case dwarf::DW_TAG_subroutine_type: {
// Add return type. A void return won't have a type.
DITypeArray Elements = DISubroutineType(CTy).getTypeArray();
DITypeArray Elements(cast<MDSubroutineType>(CTy)->getTypeArray());
DIType RTy(resolve(Elements.getElement(0)));
if (RTy)
addType(Buffer, RTy);
@ -1053,10 +1046,11 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
DIArray Elements = CTy.getElements();
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
DIDescriptor Element = Elements.getElement(i);
if (Element.isSubprogram())
getOrCreateSubprogramDIE(DISubprogram(Element));
else if (Element.isDerivedType()) {
DIDerivedType DDTy(Element);
if (!Element)
continue;
if (auto *SP = dyn_cast<MDSubprogram>(Element))
getOrCreateSubprogramDIE(SP);
else if (DIDerivedType DDTy = dyn_cast<MDDerivedTypeBase>(Element)) {
if (DDTy.getTag() == dwarf::DW_TAG_friend) {
DIE &ElemDie = createAndAddDIE(dwarf::DW_TAG_friend, Buffer);
addType(ElemDie, resolve(DDTy.getTypeDerivedFrom()),
@ -1066,8 +1060,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
} else {
constructMemberDIE(Buffer, DDTy);
}
} else if (Element.isObjCProperty()) {
DIObjCProperty Property(Element);
} else if (DIObjCProperty Property = dyn_cast<MDObjCProperty>(Element)) {
DIE &ElemDie = createAndAddDIE(Property.getTag(), Buffer);
StringRef PropertyName = Property.getObjCPropertyName();
addString(ElemDie, dwarf::DW_AT_APPLE_property_name, PropertyName);
@ -1102,8 +1095,7 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
Entry = createDIEEntry(ElemDie);
insertDIEEntry(Element, Entry);
}
} else
continue;
}
}
if (CTy.isAppleBlockExtension())
@ -1111,8 +1103,8 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, DICompositeType CTy) {
// This is outside the DWARF spec, but GDB expects a DW_AT_containing_type
// inside C++ composite types to point to the base class with the vtable.
DICompositeType ContainingType(resolve(CTy.getContainingType()));
if (ContainingType)
if (DICompositeType ContainingType =
dyn_cast_or_null<MDCompositeType>(resolve(CTy.getContainingType())))
addDIEEntry(Buffer, dwarf::DW_AT_containing_type,
*getOrCreateTypeDIE(ContainingType));
@ -1434,7 +1426,7 @@ void DwarfUnit::constructArrayTypeDIE(DIE &Buffer, DICompositeType CTy) {
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
DIDescriptor Element = Elements.getElement(i);
if (Element.getTag() == dwarf::DW_TAG_subrange_type)
constructSubrangeDIE(Buffer, DISubrange(Element), IdxTy);
constructSubrangeDIE(Buffer, cast<MDSubrange>(Element), IdxTy);
}
}
@ -1444,8 +1436,8 @@ void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy) {
// Add enumerators to enumeration type.
for (unsigned i = 0, N = Elements.getNumElements(); i < N; ++i) {
DIEnumerator Enum(Elements.getElement(i));
if (Enum.isEnumerator()) {
DIEnumerator Enum = dyn_cast_or_null<MDEnumerator>(Elements.getElement(i));
if (Enum) {
DIE &Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer);
StringRef Name = Enum.getName();
addString(Enumerator, dwarf::DW_AT_name, Name);

View File

@ -20,12 +20,11 @@ namespace llvm {
StringRef WinCodeViewLineTables::getFullFilepath(const MDNode *S) {
assert(S);
DIDescriptor D(S);
assert((D.isCompileUnit() || D.isFile() || D.isSubprogram() ||
D.isLexicalBlockFile() || D.isLexicalBlock()) &&
assert((isa<MDCompileUnit>(S) || isa<MDFile>(S) || isa<MDSubprogram>(S) ||
isa<MDLexicalBlockBase>(S)) &&
"Unexpected scope info");
DIScope Scope(S);
DIScope Scope = cast<MDScope>(S);
StringRef Dir = Scope.getDirectory(),
Filename = Scope.getFilename();
char *&Result = DirAndFilenameToFilepathMap[std::make_pair(Dir, Filename)];

View File

@ -1232,7 +1232,7 @@ void InlineSpiller::spillAroundUses(unsigned Reg) {
DebugLoc DL = MI->getDebugLoc();
DEBUG(dbgs() << "Modifying debug info due to spill:" << "\t" << *MI);
MachineBasicBlock *MBB = MI->getParent();
assert(DIVariable(Var)->isValidLocationForIntrinsic(DL) &&
assert(cast<MDLocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
"Expected inlined-at fields to agree");
BuildMI(*MBB, MBB->erase(MI), DL, TII.get(TargetOpcode::DBG_VALUE))
.addFrameIndex(StackSlot)

View File

@ -157,8 +157,8 @@ LexicalScopes::getOrCreateRegularScope(const MDLocalScope *Scope) {
false)).first;
if (!Parent) {
assert(DIDescriptor(Scope).isSubprogram());
assert(DISubprogram(Scope).describes(MF->getFunction()));
assert(
DISubprogram(cast<MDSubprogram>(Scope)).describes(MF->getFunction()));
assert(!CurrentFnLexicalScope);
CurrentFnLexicalScope = &I->second;
}

View File

@ -358,7 +358,7 @@ public:
} // namespace
void UserValue::print(raw_ostream &OS, const TargetRegisterInfo *TRI) {
DIVariable DV(Variable);
DIVariable DV = cast<MDLocalVariable>(Variable);
OS << "!\"";
DV.printExtendedName(OS);
OS << "\"\t";
@ -944,7 +944,8 @@ void UserValue::insertDebugValue(MachineBasicBlock *MBB, SlotIndex Idx,
MachineOperand &Loc = locations[LocNo];
++NumInsertedDebugValues;
assert(DIVariable(Variable)->isValidLocationForIntrinsic(getDebugLoc()) &&
assert(cast<MDLocalVariable>(Variable)
->isValidLocationForIntrinsic(getDebugLoc()) &&
"Expected inlined-at fields to agree");
if (Loc.isReg())
BuildMI(*MBB, I, getDebugLoc(), TII.get(TargetOpcode::DBG_VALUE),

View File

@ -1619,11 +1619,8 @@ void MachineInstr::print(raw_ostream &OS, bool SkipOpers) const {
}
if (isDebugValue() && MO.isMetadata()) {
// Pretty print DBG_VALUE instructions.
const MDNode *MD = MO.getMetadata();
DIDescriptor DI(MD);
DIVariable DIV(MD);
if (DI.isVariable() && !DIV.getName().empty())
DIVariable DIV = dyn_cast<MDLocalVariable>(MO.getMetadata());
if (DIV && !DIV.getName().empty())
OS << "!\"" << DIV.getName() << '\"';
else
MO.print(OS, TRI);
@ -1713,7 +1710,7 @@ void MachineInstr::print(raw_ostream &OS, bool SkipOpers) const {
// Print debug location information.
if (isDebugValue() && getOperand(e - 2).isMetadata()) {
if (!HaveSemi) OS << ";";
DIVariable DV(getOperand(e - 2).getMetadata());
DIVariable DV = cast<MDLocalVariable>(getOperand(e - 2).getMetadata());
OS << " line no:" << DV.getLineNumber();
if (auto *InlinedAt = DV.getInlinedAt()) {
DebugLoc InlinedAtDL(InlinedAt);

View File

@ -302,7 +302,7 @@ void RAFast::spillVirtReg(MachineBasicBlock::iterator MI,
bool IsIndirect = DBG->isIndirectDebugValue();
uint64_t Offset = IsIndirect ? DBG->getOperand(1).getImm() : 0;
DebugLoc DL = DBG->getDebugLoc();
assert(DIVariable(Var)->isValidLocationForIntrinsic(DL) &&
assert(cast<MDLocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
"Expected inlined-at fields to agree");
MachineInstr *NewDV =
BuildMI(*MBB, MI, DL, TII->get(TargetOpcode::DBG_VALUE))
@ -873,8 +873,9 @@ void RAFast::AllocateBasicBlock() {
const MDNode *Expr = MI->getDebugExpression();
DebugLoc DL = MI->getDebugLoc();
MachineBasicBlock *MBB = MI->getParent();
assert(DIVariable(Var)->isValidLocationForIntrinsic(DL) &&
"Expected inlined-at fields to agree");
assert(
cast<MDLocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
"Expected inlined-at fields to agree");
MachineInstr *NewDV = BuildMI(*MBB, MBB->erase(MI), DL,
TII->get(TargetOpcode::DBG_VALUE))
.addFrameIndex(SS)

View File

@ -1088,9 +1088,7 @@ bool FastISel::selectIntrinsicCall(const IntrinsicInst *II) {
}
case Intrinsic::dbg_declare: {
const DbgDeclareInst *DI = cast<DbgDeclareInst>(II);
DIVariable DIVar(DI->getVariable());
assert((!DIVar || DIVar.isVariable()) &&
"Variable in DbgDeclareInst should be either null or a DIVariable.");
DIVariable DIVar = DI->getVariable();
if (!DIVar || !FuncInfo.MF->getMMI().hasDebugInfo()) {
DEBUG(dbgs() << "Dropping debug info for " << *DI << "\n");
return true;

View File

@ -202,9 +202,7 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
// during the initial isel pass through the IR so that it is done
// in a predictable order.
if (const DbgDeclareInst *DI = dyn_cast<DbgDeclareInst>(I)) {
DIVariable DIVar(DI->getVariable());
assert((!DIVar || DIVar.isVariable()) &&
"Variable in DbgDeclareInst should be either null or a DIVariable.");
DIVariable DIVar = DI->getVariable();
if (MMI.hasDebugInfo() && DIVar && DI->getDebugLoc()) {
// Don't handle byval struct arguments or VLAs, for example.
// Non-byval arguments are handled here (they refer to the stack

View File

@ -650,7 +650,7 @@ InstrEmitter::EmitDbgValue(SDDbgValue *SD,
MDNode *Var = SD->getVariable();
MDNode *Expr = SD->getExpression();
DebugLoc DL = SD->getDebugLoc();
assert(DIVariable(Var)->isValidLocationForIntrinsic(DL) &&
assert(cast<MDLocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
"Expected inlined-at fields to agree");
if (SD->getKind() == SDDbgValue::FRAMEIX) {

View File

@ -5902,7 +5902,7 @@ SDNode *SelectionDAG::getNodeIfExists(unsigned Opcode, SDVTList VTList,
SDDbgValue *SelectionDAG::getDbgValue(MDNode *Var, MDNode *Expr, SDNode *N,
unsigned R, bool IsIndirect, uint64_t Off,
DebugLoc DL, unsigned O) {
assert(DIVariable(Var)->isValidLocationForIntrinsic(DL) &&
assert(cast<MDLocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
"Expected inlined-at fields to agree");
return new (Allocator) SDDbgValue(Var, Expr, N, R, IsIndirect, Off, DL, O);
}
@ -5911,7 +5911,7 @@ SDDbgValue *SelectionDAG::getDbgValue(MDNode *Var, MDNode *Expr, SDNode *N,
SDDbgValue *SelectionDAG::getConstantDbgValue(MDNode *Var, MDNode *Expr,
const Value *C, uint64_t Off,
DebugLoc DL, unsigned O) {
assert(DIVariable(Var)->isValidLocationForIntrinsic(DL) &&
assert(cast<MDLocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
"Expected inlined-at fields to agree");
return new (Allocator) SDDbgValue(Var, Expr, C, Off, DL, O);
}
@ -5920,7 +5920,7 @@ SDDbgValue *SelectionDAG::getConstantDbgValue(MDNode *Var, MDNode *Expr,
SDDbgValue *SelectionDAG::getFrameIndexDbgValue(MDNode *Var, MDNode *Expr,
unsigned FI, uint64_t Off,
DebugLoc DL, unsigned O) {
assert(DIVariable(Var)->isValidLocationForIntrinsic(DL) &&
assert(cast<MDLocalVariable>(Var)->isValidLocationForIntrinsic(DL) &&
"Expected inlined-at fields to agree");
return new (Allocator) SDDbgValue(Var, Expr, FI, Off, DL, O);
}

View File

@ -4641,9 +4641,7 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
MDLocalVariable *Variable = DI.getVariable();
MDExpression *Expression = DI.getExpression();
const Value *Address = DI.getAddress();
DIVariable DIVar(Variable);
assert((!DIVar || DIVar.isVariable()) &&
"Variable in DbgDeclareInst should be either null or a DIVariable.");
DIVariable DIVar = Variable;
if (!Address || !DIVar) {
DEBUG(dbgs() << "Dropping debug info for " << DI << "\n");
return nullptr;
@ -4721,9 +4719,7 @@ SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I, unsigned Intrinsic) {
}
case Intrinsic::dbg_value: {
const DbgValueInst &DI = cast<DbgValueInst>(I);
DIVariable DIVar(DI.getVariable());
assert((!DIVar || DIVar.isVariable()) &&
"Variable in DbgValueInst should be either null or a DIVariable.");
DIVariable DIVar = DI.getVariable();
if (!DIVar)
return nullptr;

View File

@ -504,7 +504,7 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
DebugLoc DL = MI->getDebugLoc();
bool IsIndirect = MI->isIndirectDebugValue();
unsigned Offset = IsIndirect ? MI->getOperand(1).getImm() : 0;
assert(DIVariable(Variable)->isValidLocationForIntrinsic(DL) &&
assert(cast<MDLocalVariable>(Variable)->isValidLocationForIntrinsic(DL) &&
"Expected inlined-at fields to agree");
// Def is never a terminator here, so it is ok to increment InsertPos.
BuildMI(*EntryMBB, ++InsertPos, DL, TII->get(TargetOpcode::DBG_VALUE),

View File

@ -464,7 +464,7 @@ void StackColoring::remapInstructions(DenseMap<int, int> &SlotRemap) {
continue;
if (SlotRemap.count(VI.Slot)) {
DEBUG(dbgs() << "Remapping debug info for ["
<< DIVariable(VI.Var).getName() << "].\n");
<< cast<MDLocalVariable>(VI.Var)->getName() << "].\n");
VI.Slot = SlotRemap[VI.Slot];
FixedDbg++;
}

View File

@ -371,7 +371,7 @@ void AArch64AsmPrinter::PrintDebugValueComment(const MachineInstr *MI,
assert(NOps == 4);
OS << '\t' << MAI->getCommentString() << "DEBUG_VALUE: ";
// cast away const; DIetc do not take const operands for some reason.
DIVariable V(const_cast<MDNode *>(MI->getOperand(NOps - 1).getMetadata()));
DIVariable V = cast<MDLocalVariable>(MI->getOperand(NOps - 2).getMetadata());
OS << V.getName();
OS << " <- ";
// Frame address. Currently handles register +- offset only.

View File

@ -129,10 +129,7 @@ void NVPTXAsmPrinter::emitLineNumberAsDotLoc(const MachineInstr &MI) {
if (!curLoc)
return;
DIScope Scope(curLoc.getScope());
assert((!Scope || Scope.isScope()) &&
"Scope of a DebugLoc should be null or a DIScope.");
DIScope Scope = cast_or_null<MDScope>(curLoc.getScope());
if (!Scope)
return;