mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-30 20:24:32 +00:00
DebugInfo: Gut DIScope, DIEnumerator and DISubrange
The only class the still has API left is `DIDescriptor` itself. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@235067 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -137,41 +137,27 @@ DECLARE_SIMPLIFY_DESCRIPTOR(DIImportedEntity)
|
|||||||
typedef DebugNodeArray DIArray;
|
typedef DebugNodeArray DIArray;
|
||||||
typedef MDTypeRefArray DITypeArray;
|
typedef MDTypeRefArray DITypeArray;
|
||||||
|
|
||||||
/// \brief This is used to represent ranges, for array bounds.
|
class DISubrange {
|
||||||
class DISubrange : public DIDescriptor {
|
MDSubrange *N;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DISubrange() = default;
|
DISubrange(const MDSubrange *N = nullptr) : N(const_cast<MDSubrange *>(N)) {}
|
||||||
DISubrange(const MDSubrange *N) : DIDescriptor(N) {}
|
|
||||||
|
|
||||||
MDSubrange *get() const {
|
operator MDSubrange *() const { return N; }
|
||||||
return cast_or_null<MDSubrange>(DIDescriptor::get());
|
MDSubrange *operator->() const { return N; }
|
||||||
}
|
MDSubrange &operator*() const { return *N; }
|
||||||
operator MDSubrange *() const { return get(); }
|
|
||||||
MDSubrange *operator->() const { return get(); }
|
|
||||||
MDSubrange &operator*() const { return *get(); }
|
|
||||||
|
|
||||||
int64_t getLo() const { return get()->getLowerBound(); }
|
|
||||||
int64_t getCount() const { return get()->getCount(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \brief A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
|
class DIEnumerator {
|
||||||
///
|
MDEnumerator *N;
|
||||||
/// FIXME: it seems strange that this doesn't have either a reference to the
|
|
||||||
/// type/precision or a file/line pair for location info.
|
|
||||||
class DIEnumerator : public DIDescriptor {
|
|
||||||
public:
|
public:
|
||||||
DIEnumerator() = default;
|
DIEnumerator(const MDEnumerator *N = nullptr)
|
||||||
DIEnumerator(const MDEnumerator *N) : DIDescriptor(N) {}
|
: N(const_cast<MDEnumerator *>(N)) {}
|
||||||
|
|
||||||
MDEnumerator *get() const {
|
operator MDEnumerator *() const { return N; }
|
||||||
return cast_or_null<MDEnumerator>(DIDescriptor::get());
|
MDEnumerator *operator->() const { return N; }
|
||||||
}
|
MDEnumerator &operator*() const { return *N; }
|
||||||
operator MDEnumerator *() const { return get(); }
|
|
||||||
MDEnumerator *operator->() const { return get(); }
|
|
||||||
MDEnumerator &operator*() const { return *get(); }
|
|
||||||
|
|
||||||
StringRef getName() const { return get()->getName(); }
|
|
||||||
int64_t getEnumValue() const { return get()->getValue(); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> class DIRef;
|
template <typename T> class DIRef;
|
||||||
@ -179,34 +165,16 @@ typedef DIRef<DIDescriptor> DIDescriptorRef;
|
|||||||
typedef DIRef<DIScope> DIScopeRef;
|
typedef DIRef<DIScope> DIScopeRef;
|
||||||
typedef DIRef<DIType> DITypeRef;
|
typedef DIRef<DIType> DITypeRef;
|
||||||
|
|
||||||
/// \brief A base class for various scopes.
|
class DIScope {
|
||||||
///
|
MDScope *N;
|
||||||
/// Although, implementation-wise, DIScope is the parent class of most
|
|
||||||
/// other DIxxx classes, including DIType and its descendants, most of
|
|
||||||
/// DIScope's descendants are not a substitutable subtype of
|
|
||||||
/// DIScope. The DIDescriptor::isScope() method only is true for
|
|
||||||
/// DIScopes that are scopes in the strict lexical scope sense
|
|
||||||
/// (DICompileUnit, DISubprogram, etc.), but not for, e.g., a DIType.
|
|
||||||
class DIScope : public DIDescriptor {
|
|
||||||
public:
|
public:
|
||||||
DIScope() = default;
|
DIScope(const MDScope *N = nullptr) : N(const_cast<MDScope *>(N)) {}
|
||||||
DIScope(const MDScope *N) : DIDescriptor(N) {}
|
|
||||||
|
|
||||||
MDScope *get() const { return cast_or_null<MDScope>(DIDescriptor::get()); }
|
operator DIDescriptor() const { return N; }
|
||||||
operator MDScope *() const { return get(); }
|
operator MDScope *() const { return N; }
|
||||||
MDScope *operator->() const { return get(); }
|
MDScope *operator->() const { return N; }
|
||||||
MDScope &operator*() const { return *get(); }
|
MDScope &operator*() const { return *N; }
|
||||||
|
|
||||||
inline DIScopeRef getContext() const;
|
|
||||||
StringRef getName() const { return get()->getName(); }
|
|
||||||
StringRef getFilename() const { return get()->getFilename(); }
|
|
||||||
StringRef getDirectory() const { return get()->getDirectory(); }
|
|
||||||
|
|
||||||
/// \brief Generate a reference to this DIScope.
|
|
||||||
///
|
|
||||||
/// Uses the type identifier instead of the actual MDNode if possible, to
|
|
||||||
/// help type uniquing.
|
|
||||||
DIScopeRef getRef() const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// \brief Represents reference to a DIDescriptor.
|
/// \brief Represents reference to a DIDescriptor.
|
||||||
@ -235,8 +203,6 @@ template <>
|
|||||||
DIScope DIRef<DIScope>::resolve(const DITypeIdentifierMap &Map) const;
|
DIScope DIRef<DIScope>::resolve(const DITypeIdentifierMap &Map) const;
|
||||||
template <> DIType DIRef<DIType>::resolve(const DITypeIdentifierMap &Map) const;
|
template <> DIType DIRef<DIType>::resolve(const DITypeIdentifierMap &Map) const;
|
||||||
|
|
||||||
DIScopeRef DIScope::getContext() const { return get()->getScope(); }
|
|
||||||
|
|
||||||
class DIType {
|
class DIType {
|
||||||
MDType *N;
|
MDType *N;
|
||||||
|
|
||||||
|
@ -1251,9 +1251,9 @@ void DwarfDebug::recordSourceLine(unsigned Line, unsigned Col, const MDNode *S,
|
|||||||
StringRef Dir;
|
StringRef Dir;
|
||||||
unsigned Src = 1;
|
unsigned Src = 1;
|
||||||
unsigned Discriminator = 0;
|
unsigned Discriminator = 0;
|
||||||
if (DIScope Scope = cast_or_null<MDScope>(S)) {
|
if (auto *Scope = cast_or_null<MDScope>(S)) {
|
||||||
Fn = Scope.getFilename();
|
Fn = Scope->getFilename();
|
||||||
Dir = Scope.getDirectory();
|
Dir = Scope->getDirectory();
|
||||||
if (auto *LBF = dyn_cast<MDLexicalBlockFile>(Scope))
|
if (auto *LBF = dyn_cast<MDLexicalBlockFile>(Scope))
|
||||||
Discriminator = LBF->getDiscriminator();
|
Discriminator = LBF->getDiscriminator();
|
||||||
|
|
||||||
|
@ -903,8 +903,8 @@ std::string DwarfUnit::getParentContextString(DIScope Context) const {
|
|||||||
SmallVector<DIScope, 1> Parents;
|
SmallVector<DIScope, 1> Parents;
|
||||||
while (!isa<MDCompileUnit>(Context)) {
|
while (!isa<MDCompileUnit>(Context)) {
|
||||||
Parents.push_back(Context);
|
Parents.push_back(Context);
|
||||||
if (Context.getContext())
|
if (Context->getScope())
|
||||||
Context = resolve(Context.getContext());
|
Context = resolve(Context->getScope());
|
||||||
else
|
else
|
||||||
// Structure, etc types will have a NULL context if they're at the top
|
// Structure, etc types will have a NULL context if they're at the top
|
||||||
// level.
|
// level.
|
||||||
@ -916,8 +916,8 @@ std::string DwarfUnit::getParentContextString(DIScope Context) const {
|
|||||||
for (SmallVectorImpl<DIScope>::reverse_iterator I = Parents.rbegin(),
|
for (SmallVectorImpl<DIScope>::reverse_iterator I = Parents.rbegin(),
|
||||||
E = Parents.rend();
|
E = Parents.rend();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
DIScope Ctx = *I;
|
const MDScope *Ctx = *I;
|
||||||
StringRef Name = Ctx.getName();
|
StringRef Name = Ctx->getName();
|
||||||
if (Name.empty() && isa<MDNamespace>(Ctx))
|
if (Name.empty() && isa<MDNamespace>(Ctx))
|
||||||
Name = "(anonymous namespace)";
|
Name = "(anonymous namespace)";
|
||||||
if (!Name.empty()) {
|
if (!Name.empty()) {
|
||||||
@ -1364,9 +1364,9 @@ void DwarfUnit::constructSubrangeDIE(DIE &Buffer, DISubrange SR, DIE *IndexTy) {
|
|||||||
// C/C++. The Count value is the number of elements. Values are 64 bit. If
|
// C/C++. The Count value is the number of elements. Values are 64 bit. If
|
||||||
// Count == -1 then the array is unbounded and we do not emit
|
// Count == -1 then the array is unbounded and we do not emit
|
||||||
// DW_AT_lower_bound and DW_AT_count attributes.
|
// DW_AT_lower_bound and DW_AT_count attributes.
|
||||||
int64_t LowerBound = SR.getLo();
|
int64_t LowerBound = SR->getLowerBound();
|
||||||
int64_t DefaultLowerBound = getDefaultLowerBound();
|
int64_t DefaultLowerBound = getDefaultLowerBound();
|
||||||
int64_t Count = SR.getCount();
|
int64_t Count = SR->getCount();
|
||||||
|
|
||||||
if (DefaultLowerBound == -1 || LowerBound != DefaultLowerBound)
|
if (DefaultLowerBound == -1 || LowerBound != DefaultLowerBound)
|
||||||
addUInt(DW_Subrange, dwarf::DW_AT_lower_bound, None, LowerBound);
|
addUInt(DW_Subrange, dwarf::DW_AT_lower_bound, None, LowerBound);
|
||||||
@ -1417,12 +1417,12 @@ void DwarfUnit::constructEnumTypeDIE(DIE &Buffer, DICompositeType CTy) {
|
|||||||
|
|
||||||
// Add enumerators to enumeration type.
|
// Add enumerators to enumeration type.
|
||||||
for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
|
for (unsigned i = 0, N = Elements.size(); i < N; ++i) {
|
||||||
DIEnumerator Enum = dyn_cast_or_null<MDEnumerator>(Elements[i]);
|
auto *Enum = dyn_cast_or_null<MDEnumerator>(Elements[i]);
|
||||||
if (Enum) {
|
if (Enum) {
|
||||||
DIE &Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer);
|
DIE &Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer);
|
||||||
StringRef Name = Enum.getName();
|
StringRef Name = Enum->getName();
|
||||||
addString(Enumerator, dwarf::DW_AT_name, Name);
|
addString(Enumerator, dwarf::DW_AT_name, Name);
|
||||||
int64_t Value = Enum.getEnumValue();
|
int64_t Value = Enum->getValue();
|
||||||
addSInt(Enumerator, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata,
|
addSInt(Enumerator, dwarf::DW_AT_const_value, dwarf::DW_FORM_sdata,
|
||||||
Value);
|
Value);
|
||||||
}
|
}
|
||||||
|
@ -24,9 +24,9 @@ StringRef WinCodeViewLineTables::getFullFilepath(const MDNode *S) {
|
|||||||
isa<MDLexicalBlockBase>(S)) &&
|
isa<MDLexicalBlockBase>(S)) &&
|
||||||
"Unexpected scope info");
|
"Unexpected scope info");
|
||||||
|
|
||||||
DIScope Scope = cast<MDScope>(S);
|
auto *Scope = cast<MDScope>(S);
|
||||||
StringRef Dir = Scope.getDirectory(),
|
StringRef Dir = Scope->getDirectory(),
|
||||||
Filename = Scope.getFilename();
|
Filename = Scope->getFilename();
|
||||||
char *&Result = DirAndFilenameToFilepathMap[std::make_pair(Dir, Filename)];
|
char *&Result = DirAndFilenameToFilepathMap[std::make_pair(Dir, Filename)];
|
||||||
if (Result)
|
if (Result)
|
||||||
return Result;
|
return Result;
|
||||||
|
@ -362,9 +362,9 @@ static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS,
|
|||||||
if (!DL)
|
if (!DL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DIScope Scope = cast<MDScope>(DL.getScope());
|
auto *Scope = cast<MDScope>(DL.getScope());
|
||||||
// Omit the directory, because it's likely to be long and uninteresting.
|
// Omit the directory, because it's likely to be long and uninteresting.
|
||||||
CommentOS << Scope.getFilename();
|
CommentOS << Scope->getFilename();
|
||||||
CommentOS << ':' << DL.getLine();
|
CommentOS << ':' << DL.getLine();
|
||||||
if (DL.getCol() != 0)
|
if (DL.getCol() != 0)
|
||||||
CommentOS << ':' << DL.getCol();
|
CommentOS << ':' << DL.getCol();
|
||||||
|
@ -527,8 +527,8 @@ void SDNode::print_details(raw_ostream &OS, const SelectionDAG *G) const {
|
|||||||
if (!L)
|
if (!L)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (DIScope Scope = L->getScope())
|
if (auto *Scope = L->getScope())
|
||||||
OS << Scope.getFilename();
|
OS << Scope->getFilename();
|
||||||
else
|
else
|
||||||
OS << "<unknown>";
|
OS << "<unknown>";
|
||||||
OS << ':' << L->getLine();
|
OS << ':' << L->getLine();
|
||||||
|
@ -348,8 +348,7 @@ DIBuilder::createObjCProperty(StringRef Name, DIFile File, unsigned LineNumber,
|
|||||||
DITemplateTypeParameter
|
DITemplateTypeParameter
|
||||||
DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name,
|
DIBuilder::createTemplateTypeParameter(DIDescriptor Context, StringRef Name,
|
||||||
DIType Ty) {
|
DIType Ty) {
|
||||||
assert((!Context || isa<MDCompileUnit>(Context.get())) &&
|
assert((!Context || isa<MDCompileUnit>(Context)) && "Expected compile unit");
|
||||||
"Expected compile unit");
|
|
||||||
return MDTemplateTypeParameter::get(VMContext, Name, MDTypeRef::get(Ty));
|
return MDTemplateTypeParameter::get(VMContext, Name, MDTypeRef::get(Ty));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,8 +356,7 @@ static DITemplateValueParameter
|
|||||||
createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag,
|
createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag,
|
||||||
DIDescriptor Context, StringRef Name,
|
DIDescriptor Context, StringRef Name,
|
||||||
DIType Ty, Metadata *MD) {
|
DIType Ty, Metadata *MD) {
|
||||||
assert((!Context || isa<MDCompileUnit>(Context.get())) &&
|
assert((!Context || isa<MDCompileUnit>(Context)) && "Expected compile unit");
|
||||||
"Expected compile unit");
|
|
||||||
return MDTemplateValueParameter::get(VMContext, Tag, Name, MDTypeRef::get(Ty),
|
return MDTemplateValueParameter::get(VMContext, Tag, Name, MDTypeRef::get(Ty),
|
||||||
MD);
|
MD);
|
||||||
}
|
}
|
||||||
@ -590,10 +588,10 @@ DIGlobalVariable DIBuilder::createGlobalVariable(
|
|||||||
MDNode *Decl) {
|
MDNode *Decl) {
|
||||||
checkGlobalVariableScope(Context);
|
checkGlobalVariableScope(Context);
|
||||||
|
|
||||||
auto *N = MDGlobalVariable::get(
|
auto *N = MDGlobalVariable::get(VMContext, cast_or_null<MDScope>(Context),
|
||||||
VMContext, cast_or_null<MDScope>(Context.get()), Name, LinkageName, F,
|
Name, LinkageName, F, LineNumber,
|
||||||
LineNumber, MDTypeRef::get(Ty), isLocalToUnit, true, Val,
|
MDTypeRef::get(Ty), isLocalToUnit, true, Val,
|
||||||
cast_or_null<MDDerivedType>(Decl));
|
cast_or_null<MDDerivedType>(Decl));
|
||||||
AllGVs.push_back(N);
|
AllGVs.push_back(N);
|
||||||
return N;
|
return N;
|
||||||
}
|
}
|
||||||
@ -605,9 +603,10 @@ DIGlobalVariable DIBuilder::createTempGlobalVariableFwdDecl(
|
|||||||
checkGlobalVariableScope(Context);
|
checkGlobalVariableScope(Context);
|
||||||
|
|
||||||
return MDGlobalVariable::getTemporary(
|
return MDGlobalVariable::getTemporary(
|
||||||
VMContext, cast_or_null<MDScope>(Context.get()), Name, LinkageName,
|
VMContext, cast_or_null<MDScope>(Context), Name, LinkageName, F,
|
||||||
F, LineNumber, MDTypeRef::get(Ty), isLocalToUnit, false, Val,
|
LineNumber, MDTypeRef::get(Ty), isLocalToUnit, false, Val,
|
||||||
cast_or_null<MDDerivedType>(Decl)).release();
|
cast_or_null<MDDerivedType>(Decl))
|
||||||
|
.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
|
DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
|
||||||
@ -622,8 +621,8 @@ DIVariable DIBuilder::createLocalVariable(unsigned Tag, DIDescriptor Scope,
|
|||||||
DIScope Context = getNonCompileUnitScope(Scope);
|
DIScope Context = getNonCompileUnitScope(Scope);
|
||||||
|
|
||||||
auto *Node = MDLocalVariable::get(
|
auto *Node = MDLocalVariable::get(
|
||||||
VMContext, Tag, cast_or_null<MDLocalScope>(Context.get()), Name, File,
|
VMContext, Tag, cast_or_null<MDLocalScope>(Context), Name, File, LineNo,
|
||||||
LineNo, MDTypeRef::get(Ty), ArgNo, Flags);
|
MDTypeRef::get(Ty), ArgNo, Flags);
|
||||||
if (AlwaysPreserve) {
|
if (AlwaysPreserve) {
|
||||||
// The optimizer may remove local variable. If there is an interest
|
// The optimizer may remove local variable. If there is an interest
|
||||||
// to preserve variable info in such situation then stash it in a
|
// to preserve variable info in such situation then stash it in a
|
||||||
|
@ -33,8 +33,6 @@
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace llvm::dwarf;
|
using namespace llvm::dwarf;
|
||||||
|
|
||||||
DIScopeRef DIScope::getRef() const { return MDScopeRef::get(get()); }
|
|
||||||
|
|
||||||
DISubprogram llvm::getDISubprogram(const MDNode *Scope) {
|
DISubprogram llvm::getDISubprogram(const MDNode *Scope) {
|
||||||
if (auto *LocalScope = dyn_cast_or_null<MDLocalScope>(Scope))
|
if (auto *LocalScope = dyn_cast_or_null<MDLocalScope>(Scope))
|
||||||
return LocalScope->getSubprogram();
|
return LocalScope->getSubprogram();
|
||||||
|
@ -86,8 +86,8 @@ void DebugLoc::print(raw_ostream &OS) const {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Print source line info.
|
// Print source line info.
|
||||||
DIScope Scope = cast<MDScope>(getScope());
|
auto *Scope = cast<MDScope>(getScope());
|
||||||
OS << Scope.getFilename();
|
OS << Scope->getFilename();
|
||||||
OS << ':' << getLine();
|
OS << ':' << getLine();
|
||||||
if (getCol() != 0)
|
if (getCol() != 0)
|
||||||
OS << ':' << getCol();
|
OS << ':' << getCol();
|
||||||
|
@ -129,12 +129,12 @@ void NVPTXAsmPrinter::emitLineNumberAsDotLoc(const MachineInstr &MI) {
|
|||||||
if (!curLoc)
|
if (!curLoc)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DIScope Scope = cast_or_null<MDScope>(curLoc.getScope());
|
auto *Scope = cast_or_null<MDScope>(curLoc.getScope());
|
||||||
if (!Scope)
|
if (!Scope)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
StringRef fileName(Scope.getFilename());
|
StringRef fileName(Scope->getFilename());
|
||||||
StringRef dirName(Scope.getDirectory());
|
StringRef dirName(Scope->getDirectory());
|
||||||
SmallString<128> FullPathName = dirName;
|
SmallString<128> FullPathName = dirName;
|
||||||
if (!dirName.empty() && !sys::path::is_absolute(fileName)) {
|
if (!dirName.empty() && !sys::path::is_absolute(fileName)) {
|
||||||
sys::path::append(FullPathName, fileName);
|
sys::path::append(FullPathName, fileName);
|
||||||
|
@ -193,8 +193,8 @@ bool AddDiscriminators::runOnFunction(Function &F) {
|
|||||||
// Create a new lexical scope and compute a new discriminator
|
// Create a new lexical scope and compute a new discriminator
|
||||||
// number for it.
|
// number for it.
|
||||||
StringRef Filename = FirstDIL->getFilename();
|
StringRef Filename = FirstDIL->getFilename();
|
||||||
DIScope Scope = FirstDIL->getScope();
|
auto *Scope = FirstDIL->getScope();
|
||||||
DIFile File = Builder.createFile(Filename, Scope.getDirectory());
|
DIFile File = Builder.createFile(Filename, Scope->getDirectory());
|
||||||
|
|
||||||
// FIXME: Calculate the discriminator here, based on local information,
|
// FIXME: Calculate the discriminator here, based on local information,
|
||||||
// and delete MDLocation::computeNewDiscriminator(). The current
|
// and delete MDLocation::computeNewDiscriminator(). The current
|
||||||
|
Reference in New Issue
Block a user