DebugInfo: Add MDLocalScope, a legal scope for locals

Add a subclass of `MDScope` to explicitly categorize the legal scopes
for locals -- in particular, scopes that are legal for `MDLocation`,
`MDLexicalBlockBase`, and `MDLocalVariable`.  This provides a convenient
`isa<>` target for the verifier, and eventually I'll be changing the
above classes' `getScope()` to specifically return it.  Currently, its
subclasses are `MDSubprogram`, `MDLexicalBlock`, and
`MDLexicalBlockFile`.

I've gone with `MDLocalScope` for now -- a little ambiguous since it's a
scope *for* locals, not a scope that's local -- but I'm open to more
descriptive names if someone can think of something better.  Regardless,
the code docs should make it clear enough.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233092 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2015-03-24 16:44:29 +00:00
parent 63ccf14139
commit ab10069039
2 changed files with 26 additions and 4 deletions

View File

@ -894,11 +894,31 @@ public:
}
};
/// \brief A scope for locals.
///
/// A legal scope for lexical blocks, local variables, and debug info
/// locations. Subclasses are \a MDSubprogram, \a MDLexicalBlock, and \a
/// MDLexicalBlockFile.
class MDLocalScope : public MDScope {
protected:
MDLocalScope(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Tag,
ArrayRef<Metadata *> Ops)
: MDScope(C, ID, Storage, Tag, Ops) {}
~MDLocalScope() {}
public:
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == MDSubprogramKind ||
MD->getMetadataID() == MDLexicalBlockKind ||
MD->getMetadataID() == MDLexicalBlockFileKind;
}
};
/// \brief Subprogram description.
///
/// TODO: Remove DisplayName. It's always equal to Name.
/// TODO: Split up flags.
class MDSubprogram : public MDScope {
class MDSubprogram : public MDLocalScope {
friend class LLVMContextImpl;
friend class MDNode;
@ -915,7 +935,8 @@ class MDSubprogram : public MDScope {
unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
bool IsOptimized, ArrayRef<Metadata *> Ops)
: MDScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram, Ops),
: MDLocalScope(C, MDSubprogramKind, Storage, dwarf::DW_TAG_subprogram,
Ops),
Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
@ -1023,11 +1044,11 @@ public:
}
};
class MDLexicalBlockBase : public MDScope {
class MDLexicalBlockBase : public MDLocalScope {
protected:
MDLexicalBlockBase(LLVMContext &C, unsigned ID, StorageType Storage,
ArrayRef<Metadata *> Ops)
: MDScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
: MDLocalScope(C, ID, Storage, dwarf::DW_TAG_lexical_block, Ops) {}
~MDLexicalBlockBase() {}
public:

View File

@ -76,6 +76,7 @@ HANDLE_SPECIALIZED_MDNODE_LEAF(MDCompositeType)
HANDLE_SPECIALIZED_MDNODE_LEAF(MDSubroutineType)
HANDLE_SPECIALIZED_MDNODE_LEAF(MDFile)
HANDLE_SPECIALIZED_MDNODE_LEAF(MDCompileUnit)
HANDLE_SPECIALIZED_MDNODE_BRANCH(MDLocalScope)
HANDLE_SPECIALIZED_MDNODE_LEAF(MDSubprogram)
HANDLE_SPECIALIZED_MDNODE_BRANCH(MDLexicalBlockBase)
HANDLE_SPECIALIZED_MDNODE_LEAF(MDLexicalBlock)