-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[llvm][DebugInfo][NFC] Abstract DICompileUnit::SourceLanguage to allow alternate DWARF SourceLanguage encoding #162255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,44 @@ namespace dwarf { | |
enum Tag : uint16_t; | ||
} | ||
|
||
/// Wrapper structure that holds a language name and its version. | ||
/// | ||
/// Some debug-info formats, particularly DWARF, distniguish between | ||
/// language codes that include the version name and codes that don't. | ||
/// DISourceLanguageName may hold either of these. | ||
/// | ||
class DISourceLanguageName { | ||
/// Language name. | ||
/// If \ref Version is not std::nullopt, then this name | ||
/// is version independent (i.e., doesn't include the language | ||
/// version in its name). | ||
uint16_t Name; | ||
|
||
/// Language version. The version scheme is language | ||
/// dependent. | ||
std::optional<uint32_t> Version; | ||
|
||
public: | ||
bool hasVersionedName() const { return Version.has_value(); } | ||
|
||
/// Returns a versioned or unversioned language name. | ||
uint16_t getName() const { return Name; } | ||
|
||
// Transitional API for cases where we do not yet support | ||
// versioned source language names. Use \ref getName instead. | ||
// | ||
// FIXME: remove once all callers of this API account for versioned | ||
// names. | ||
|
||
uint16_t getUnversionedName() const { | ||
assert(!hasVersionedName()); | ||
return Name; | ||
} | ||
|
||
DISourceLanguageName(uint16_t Lang, uint32_t Version) | ||
: Name(Lang), Version(Version) {}; | ||
DISourceLanguageName(uint16_t Lang) : Name(Lang), Version(std::nullopt) {}; | ||
}; | ||
|
||
class DbgVariableRecord; | ||
|
||
LLVM_ABI extern cl::opt<bool> EnableFSDiscriminator; | ||
|
@@ -2003,7 +2041,7 @@ class DICompileUnit : public DIScope { | |
LLVM_ABI static const char *nameTableKindString(DebugNameTableKind PK); | ||
|
||
private: | ||
unsigned SourceLanguage; | ||
DISourceLanguageName SourceLanguage; | ||
unsigned RuntimeVersion; | ||
uint64_t DWOId; | ||
unsigned EmissionKind; | ||
|
@@ -2013,16 +2051,17 @@ class DICompileUnit : public DIScope { | |
bool DebugInfoForProfiling; | ||
bool RangesBaseAddress; | ||
|
||
DICompileUnit(LLVMContext &C, StorageType Storage, unsigned SourceLanguage, | ||
bool IsOptimized, unsigned RuntimeVersion, | ||
unsigned EmissionKind, uint64_t DWOId, bool SplitDebugInlining, | ||
bool DebugInfoForProfiling, unsigned NameTableKind, | ||
bool RangesBaseAddress, ArrayRef<Metadata *> Ops); | ||
DICompileUnit(LLVMContext &C, StorageType Storage, | ||
DISourceLanguageName SourceLanguage, bool IsOptimized, | ||
unsigned RuntimeVersion, unsigned EmissionKind, uint64_t DWOId, | ||
bool SplitDebugInlining, bool DebugInfoForProfiling, | ||
unsigned NameTableKind, bool RangesBaseAddress, | ||
ArrayRef<Metadata *> Ops); | ||
~DICompileUnit() = default; | ||
|
||
static DICompileUnit * | ||
getImpl(LLVMContext &Context, unsigned SourceLanguage, DIFile *File, | ||
StringRef Producer, bool IsOptimized, StringRef Flags, | ||
getImpl(LLVMContext &Context, DISourceLanguageName SourceLanguage, | ||
DIFile *File, StringRef Producer, bool IsOptimized, StringRef Flags, | ||
unsigned RuntimeVersion, StringRef SplitDebugFilename, | ||
unsigned EmissionKind, DICompositeTypeArray EnumTypes, | ||
DIScopeArray RetainedTypes, | ||
|
@@ -2042,8 +2081,8 @@ class DICompileUnit : public DIScope { | |
getCanonicalMDString(Context, SDK), Storage, ShouldCreate); | ||
} | ||
LLVM_ABI static DICompileUnit * | ||
getImpl(LLVMContext &Context, unsigned SourceLanguage, Metadata *File, | ||
MDString *Producer, bool IsOptimized, MDString *Flags, | ||
getImpl(LLVMContext &Context, DISourceLanguageName SourceLanguage, | ||
Metadata *File, MDString *Producer, bool IsOptimized, MDString *Flags, | ||
unsigned RuntimeVersion, MDString *SplitDebugFilename, | ||
unsigned EmissionKind, Metadata *EnumTypes, Metadata *RetainedTypes, | ||
Metadata *GlobalVariables, Metadata *ImportedEntities, | ||
|
@@ -2068,7 +2107,7 @@ class DICompileUnit : public DIScope { | |
|
||
DEFINE_MDNODE_GET_DISTINCT_TEMPORARY( | ||
DICompileUnit, | ||
(unsigned SourceLanguage, DIFile *File, StringRef Producer, | ||
(DISourceLanguageName SourceLanguage, DIFile *File, StringRef Producer, | ||
bool IsOptimized, StringRef Flags, unsigned RuntimeVersion, | ||
StringRef SplitDebugFilename, DebugEmissionKind EmissionKind, | ||
DICompositeTypeArray EnumTypes, DIScopeArray RetainedTypes, | ||
|
@@ -2084,7 +2123,7 @@ class DICompileUnit : public DIScope { | |
SysRoot, SDK)) | ||
DEFINE_MDNODE_GET_DISTINCT_TEMPORARY( | ||
DICompileUnit, | ||
(unsigned SourceLanguage, Metadata *File, MDString *Producer, | ||
(DISourceLanguageName SourceLanguage, Metadata *File, MDString *Producer, | ||
bool IsOptimized, MDString *Flags, unsigned RuntimeVersion, | ||
MDString *SplitDebugFilename, unsigned EmissionKind, Metadata *EnumTypes, | ||
Metadata *RetainedTypes, Metadata *GlobalVariables, | ||
|
@@ -2099,7 +2138,7 @@ class DICompileUnit : public DIScope { | |
|
||
TempDICompileUnit clone() const { return cloneImpl(); } | ||
|
||
unsigned getSourceLanguage() const { return SourceLanguage; } | ||
DISourceLanguageName getSourceLanguage() const { return SourceLanguage; } | ||
bool isOptimized() const { return IsOptimized; } | ||
unsigned getRuntimeVersion() const { return RuntimeVersion; } | ||
DebugEmissionKind getEmissionKind() const { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1866,11 +1866,13 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata( | |
// Ignore Record[0], which indicates whether this compile unit is | ||
// distinct. It's always distinct. | ||
IsDistinct = true; | ||
|
||
auto *CU = DICompileUnit::getDistinct( | ||
Context, Record[1], getMDOrNull(Record[2]), getMDString(Record[3]), | ||
Record[4], getMDString(Record[5]), Record[6], getMDString(Record[7]), | ||
Record[8], getMDOrNull(Record[9]), getMDOrNull(Record[10]), | ||
getMDOrNull(Record[12]), getMDOrNull(Record[13]), | ||
Context, DISourceLanguageName(Record[1]), getMDOrNull(Record[2]), | ||
getMDString(Record[3]), Record[4], getMDString(Record[5]), Record[6], | ||
getMDString(Record[7]), Record[8], getMDOrNull(Record[9]), | ||
getMDOrNull(Record[10]), getMDOrNull(Record[12]), | ||
getMDOrNull(Record[13]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does the AutoUpgrade from the old format work here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally (assuming that the old and new enums are not compatible, we should add a .bc file to the tests with a compile unit in the old format to prove that we can upgrade it correctly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, looks like I misunderstood what this patch is doing — it's NFC as far as the bitcode format is concerned. |
||
Record.size() <= 15 ? nullptr : getMDOrNull(Record[15]), | ||
Record.size() <= 14 ? 0 : Record[14], | ||
Record.size() <= 16 ? true : Record[16], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
possibly flip the order between these?