Skip to content

Commit ec0c675

Browse files
authored
Initial import of code to amd-debug (llvm#1432)
2 parents 56cd70b + dcedc5d commit ec0c675

File tree

307 files changed

+56591
-7212
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

307 files changed

+56591
-7212
lines changed

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ class CodeGenOptions : public CodeGenOptionsBase {
164164
Never, // No loop is assumed to be finite.
165165
};
166166

167+
enum class HeterogeneousDwarfOpts {
168+
Disabled, //< Do not emit any heterogeneous dwarf metadata.
169+
DIExpression, //< Enable DIExpression-based metadata.
170+
};
171+
bool isHeterogeneousDwarfEnabled() const {
172+
return getHeterogeneousDwarfMode() != HeterogeneousDwarfOpts::Disabled;
173+
}
174+
167175
enum AssignmentTrackingOpts {
168176
Disabled,
169177
Enabled,

clang/include/clang/Basic/DebugOptions.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ DEBUGOPT(DebugStrictDwarf, 1, 1) ///< Whether or not to use strict DWARF info.
7171
DEBUGOPT(DebugOmitUnreferencedMethods, 1, 0) ///< Omit unreferenced member
7272
///< functions in type debug info.
7373

74+
/// Control DWARF extensions for heterogeneous debugging enablement and approach.
75+
BENIGN_ENUM_DEBUGOPT(HeterogeneousDwarfMode, HeterogeneousDwarfOpts, 2,
76+
HeterogeneousDwarfOpts::Disabled)
77+
7478
/// Control the Assignment Tracking debug info feature.
7579
BENIGN_ENUM_DEBUGOPT(AssignmentTrackingMode, AssignmentTrackingOpts, 2,
7680
AssignmentTrackingOpts::Disabled)

clang/include/clang/Driver/Options.td

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4494,6 +4494,23 @@ def gdwarf32 : Flag<["-"], "gdwarf32">, Group<g_Group>,
44944494
Visibility<[ClangOption, CC1Option, CC1AsOption]>,
44954495
HelpText<"Enables DWARF32 format for ELF binaries, if debug information emission is enabled.">;
44964496

4497+
def gheterogeneous_dwarf_EQ : Joined<["-"], "gheterogeneous-dwarf=">,
4498+
Group<g_Group>, Visibility<[ClangOption, CC1Option]>,
4499+
HelpText<"Control DWARF extensions for heterogeneous debugging">,
4500+
Values<"disabled,diexpression">,
4501+
NormalizedValuesScope<"CodeGenOptions::HeterogeneousDwarfOpts">,
4502+
NormalizedValues<["Disabled","DIExpression"]>,
4503+
MarshallingInfoEnum<CodeGenOpts<"HeterogeneousDwarfMode">, "Disabled">;
4504+
def gheterogeneous_dwarf : Flag<["-"], "gheterogeneous-dwarf">, Group<g_Group>,
4505+
Visibility<[ClangOption, CC1Option]>,
4506+
HelpText<"Enable DIExpression-based DWARF extensions for heterogeneous debugging">,
4507+
Alias<gheterogeneous_dwarf_EQ>, AliasArgs<["diexpression"]>;
4508+
def gno_heterogeneous_dwarf : Flag<["-"], "gno-heterogeneous-dwarf">,
4509+
Visibility<[ClangOption, CC1Option]>,
4510+
Group<g_Group>,
4511+
HelpText<"Disable DWARF extensions for heterogeneous debugging">,
4512+
Alias<gheterogeneous_dwarf_EQ>, AliasArgs<["disabled"]>;
4513+
44974514
def gcodeview : Flag<["-"], "gcodeview">,
44984515
HelpText<"Generate CodeView debug information">,
44994516
Visibility<[ClangOption, CC1Option, CC1AsOption, CLOption, DXCOption]>,

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 586 additions & 18 deletions
Large diffs are not rendered by default.

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,17 @@ class CGDebugInfo {
539539
/// Emit information about a global variable.
540540
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
541541

542+
/// Emit information about a global variable (-gheterogeneous-dwarf).
543+
void EmitGlobalVariableForHeterogeneousDwarf(llvm::GlobalVariable *GV,
544+
const VarDecl *Decl);
545+
542546
/// Emit a constant global variable's debug info.
543547
void EmitGlobalVariable(const ValueDecl *VD, const APValue &Init);
544548

549+
/// Emit a constant global variable's debug info (-gheterogeneous-dwarf).
550+
void EmitGlobalVariableForHeterogeneousDwarf(const ValueDecl *VD,
551+
const APValue &Init);
552+
545553
/// Emit information about an external variable.
546554
void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
547555

@@ -645,6 +653,20 @@ class CGDebugInfo {
645653
CGBuilderTy &Builder,
646654
const bool UsePointerValue = false);
647655

656+
/// Emit call to llvm.dbg.declare for a variable definition.
657+
/// Returns a pointer to the DILocalVariable associated with the
658+
/// llvm.dbg.def, or nullptr otherwise.
659+
llvm::DILocalVariable *EmitDeclareForHeterogeneousDwarf(
660+
const VarDecl *decl, llvm::Value *AI, std::optional<unsigned> ArgNo,
661+
CGBuilderTy &Builder, const bool UsePointerValue = false);
662+
663+
/// Emit call to llvm.dbg.declare for a structured binding definition.
664+
/// Returns a pointer to the DILocalVariable associated with the
665+
/// llvm.dbg.def, or nullptr otherwise.
666+
llvm::DILocalVariable *EmitDeclareForHeterogeneousDwarf(
667+
const BindingDecl *decl, llvm::Value *AI, std::optional<unsigned> ArgNo,
668+
CGBuilderTy &Builder, const bool UsePointerValue = false);
669+
648670
/// Emit call to llvm.dbg.declare for a binding declaration.
649671
/// Returns a pointer to the DILocalVariable associated with the
650672
/// llvm.dbg.declare, or nullptr otherwise.
@@ -653,6 +675,8 @@ class CGDebugInfo {
653675
CGBuilderTy &Builder,
654676
const bool UsePointerValue = false);
655677

678+
// FIXME: EmitDef(const BindingDecl *...
679+
656680
struct BlockByRefType {
657681
/// The wrapper struct used inside the __block_literal struct.
658682
llvm::DIType *BlockByRefWrapper;
@@ -776,8 +800,20 @@ class CGDebugInfo {
776800
llvm::DIGlobalVariableExpression *
777801
CollectAnonRecordDecls(const RecordDecl *RD, llvm::DIFile *Unit,
778802
unsigned LineNo, StringRef LinkageName,
779-
llvm::GlobalVariable *Var, llvm::DIScope *DContext);
803+
llvm::dwarf::MemorySpace MS, llvm::GlobalVariable *Var,
804+
llvm::DIScope *DContext);
780805

806+
/// Return a global variable that represents one of the collection of global
807+
/// variables created for an anonmyous union (-gheterogeneous-dwarf).
808+
///
809+
/// Recursively collect all of the member fields of a global
810+
/// anonymous decl and create static variables for them. The first
811+
/// time this is called it needs to be on a union and then from
812+
/// there we can have additional unnamed fields.
813+
llvm::DIGlobalVariableExpression *CollectAnonRecordDeclsForHeterogeneousDwarf(
814+
const RecordDecl *RD, llvm::DIFile *Unit, unsigned LineNo,
815+
StringRef LinkageName, llvm::dwarf::MemorySpace MS,
816+
llvm::GlobalVariable *Var, llvm::DIScope *DContext);
781817

782818
/// Return flags which enable debug info emission for call sites, provided
783819
/// that it is supported and enabled.

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4920,6 +4920,35 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T,
49204920
renderDwarfFormat(D, T, Args, CmdArgs, EffectiveDWARFVersion);
49214921
RenderDebugInfoCompressionArgs(Args, CmdArgs, D, TC);
49224922

4923+
bool EmitDwarfForAMDGCN = EmitDwarf && T.isAMDGCN();
4924+
if (EmitDwarfForAMDGCN)
4925+
CmdArgs.append({"-mllvm", "-amdgpu-spill-cfi-saved-regs"});
4926+
if (Arg *A = Args.getLastArg(options::OPT_gheterogeneous_dwarf_EQ)) {
4927+
A->render(Args, CmdArgs);
4928+
} else if (EmitDwarfForAMDGCN) {
4929+
#ifndef NDEBUG
4930+
// There doesn't seem to be a straightforward way to "render" an option
4931+
// acquired from the OptTable into a string we can append to CmdArgs.
4932+
// All of the logic is buried in "accept" which works directly in terms
4933+
// of an ArgList.
4934+
//
4935+
// Instead, assert that the static string we are adding to CmdArgs has
4936+
// the same shape as what a bare -gheterogeneous-dwarf would alias to
4937+
// if the user has provided it in ArgList.
4938+
const Option GHeterogeneousDwarf =
4939+
getDriverOptTable().getOption(options::OPT_gheterogeneous_dwarf);
4940+
const Option Aliased = GHeterogeneousDwarf.getAlias();
4941+
assert(Aliased.isValid() && "gheterogeneous-dwarf must be an alias");
4942+
assert(Aliased.getName() == "gheterogeneous-dwarf=" &&
4943+
"gheterogeneous-dwarf must alias gheterogeneous-dwarf=");
4944+
assert(StringRef(GHeterogeneousDwarf.getAliasArgs()) == "diexpression" &&
4945+
GHeterogeneousDwarf.getAliasArgs()[strlen("diexpression") + 1] ==
4946+
'\0' &&
4947+
"gheterogeneous-dwarf must alias gheterogeneous-dwarf=diexpression");
4948+
#endif
4949+
CmdArgs.push_back("-gheterogeneous-dwarf=diexpression");
4950+
}
4951+
49234952
// This controls whether or not we perform JustMyCode instrumentation.
49244953
if (Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc, false)) {
49254954
if (TC.getTriple().isOSBinFormatELF() ||

0 commit comments

Comments
 (0)