Skip to content

Commit

Permalink
CodeGen: Stop using DIDescriptor::is*() and auto-casting
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dexonsmith committed Apr 6, 2015
1 parent 573ca05 commit 0477045
Show file tree
Hide file tree
Showing 22 changed files with 143 additions and 167 deletions.
9 changes: 5 additions & 4 deletions include/llvm/CodeGen/MachineInstrBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ class MachineInstrBuilder {

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;
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 << ":";
}
Expand Down
17 changes: 10 additions & 7 deletions lib/CodeGen/AsmPrinter/DebugLocEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DebugLocEntry {
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.
Expand Down Expand Up @@ -75,9 +75,11 @@ class DebugLocEntry {
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 &);
};
Expand All @@ -101,10 +103,11 @@ class DebugLocEntry {
/// 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);
Expand Down
35 changes: 16 additions & 19 deletions lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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");
Expand All @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -607,7 +605,7 @@ DwarfCompileUnit::constructAbstractSubprogramScopeDIE(LexicalScope *Scope) {
if (AbsDef)
return;

DISubprogram SP(Scope->getScopeNode());
DISubprogram SP = cast<MDSubprogram>(Scope->getScopeNode());

DIE *ContextDIE;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down
66 changes: 31 additions & 35 deletions lib/CodeGen/AsmPrinter/DwarfDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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()));
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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));
}
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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));
});
}

Expand All @@ -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);
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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())) {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion lib/CodeGen/AsmPrinter/DwarfDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class DbgVariable {
}

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;
Expand Down
Loading

0 comments on commit 0477045

Please sign in to comment.