Skip to content
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

[flang-legacy] - Additional -gheterogeneous-dwarf support #83

Open
wants to merge 1 commit into
base: aomp-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ CODEGENOPT(RelaxELFRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no}
CODEGENOPT(AsmVerbose , 1, 0) ///< -dA, -fverbose-asm.
CODEGENOPT(Dwarf64 , 1, 0) ///< -gdwarf64.
CODEGENOPT(Dwarf32 , 1, 1) ///< -gdwarf32.
CODEGENOPT(HeterogeneousDwarf, 1, 0) ///< Enable DWARF extensions for
///< heterogeneous debugging.
/// Control DWARF extensions for heterogeneous debugging enablement and approach.
ENUM_CODEGENOPT(HeterogeneousDwarfMode, HeterogeneousDwarfOpts, 2,
HeterogeneousDwarfOpts::Disabled)
CODEGENOPT(PreserveAsmComments, 1, 1) ///< -dA, -fno-preserve-as-comments.
CODEGENOPT(AssumeSaneOperatorNew , 1, 1) ///< implicit __attribute__((malloc)) operator new
CODEGENOPT(AssumeUniqueVTables , 1, 1) ///< Assume a class has only one vtable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ class CodeGenOptions : public CodeGenOptionsBase {
Never, // No loop is assumed to be finite.
};

enum class HeterogeneousDwarfOpts {
Disabled, //< Do not emit any heterogeneous dwarf metadata.
DIExpr, //< Enable DIExpr-based metadata.
DIExpression, //< Enable DIExpression-based metadata.
};
bool isHeterogeneousDwarfEnabled() const {
return getHeterogeneousDwarfMode() != HeterogeneousDwarfOpts::Disabled;
}
bool isHeterogeneousDwarfDIExpr() const {
return getHeterogeneousDwarfMode() == HeterogeneousDwarfOpts::DIExpr;
}
bool isHeterogeneousDwarfDIExpression() const {
return getHeterogeneousDwarfMode() == HeterogeneousDwarfOpts::DIExpression;
}

enum AssignmentTrackingOpts {
Disabled,
Enabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3543,12 +3543,20 @@ def gdwarf64 : Flag<["-"], "gdwarf64">, Group<g_Group>,
def gdwarf32 : Flag<["-"], "gdwarf32">, Group<g_Group>,
Flags<[CC1Option, CC1AsOption]>,
HelpText<"Enables DWARF32 format for ELF binaries, if debug information emission is enabled.">;
def gheterogeneous_dwarf : Flag<["-"], "gheterogeneous-dwarf">,
def gheterogeneous_dwarf_EQ : Joined<["-"], "gheterogeneous-dwarf=">,
Group<g_Group>, Flags<[CC1Option]>,
HelpText<"Enable DWARF extensions for heterogeneous debugging">,
MarshallingInfoFlag<CodeGenOpts<"HeterogeneousDwarf">>;
HelpText<"Control DWARF extensions for heterogeneous debugging">,
Values<"disabled,diexpr,diexpression">,
NormalizedValuesScope<"CodeGenOptions::HeterogeneousDwarfOpts">,
NormalizedValues<["Disabled","DIExpr","DIExpression"]>,
MarshallingInfoEnum<CodeGenOpts<"HeterogeneousDwarfMode">, "Disabled">;
def gheterogeneous_dwarf : Flag<["-"], "gheterogeneous-dwarf">, Group<g_Group>,
HelpText<"Enable DIExpression-based DWARF extensions for heterogeneous debugging">,
Alias<gheterogeneous_dwarf_EQ>, AliasArgs<["diexpression"]>;
def gno_heterogeneous_dwarf : Flag<["-"], "gno-heterogeneous-dwarf">,
Group<g_Group>, HelpText<"Disable DWARF extensions for heterogeneous debugging">;
Group<g_Group>,
HelpText<"Disable DWARF extensions for heterogeneous debugging">,
Alias<gheterogeneous_dwarf_EQ>, AliasArgs<["disabled"]>;

def gcodeview : Flag<["-"], "gcodeview">,
HelpText<"Generate CodeView debug information">,
Expand Down
21 changes: 21 additions & 0 deletions flang-legacy/17.0-4/llvm-legacy/clang/lib/CodeGen/CGDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4624,8 +4624,11 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
std::optional<unsigned> ArgNo,
CGBuilderTy &Builder,
const bool UsePointerValue) {
/*
if (CGM.getCodeGenOpts().HeterogeneousDwarf)
return EmitDef(VD, Storage, ArgNo, Builder, UsePointerValue);
*/
assert(false);

assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
Expand Down Expand Up @@ -4812,8 +4815,11 @@ llvm::DILocalVariable *CGDebugInfo::EmitDef(const VarDecl *VD,
const bool UsePointerValue) {
assert(CGM.getCodeGenOpts().hasReducedDebugInfo() &&
"Call to EmitDef below ReducedDebugInfo");
/*
assert(CGM.getCodeGenOpts().HeterogeneousDwarf &&
"Call to EmitDef without HeterogeneousDwarf enabled");
*/
assert(false);
assert(!LexicalBlockStack.empty() && "Region stack mismatch, stack empty!");
if (VD->hasAttr<NoDebugAttr>())
return nullptr;
Expand Down Expand Up @@ -5442,7 +5448,10 @@ CGDebugInfo::CollectAnonRecordDeclsForHeterogeneousDwarf(
const RecordDecl *RD, llvm::DIFile *Unit, unsigned LineNo,
StringRef LinkageName, llvm::dwarf::MemorySpace MS,
llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
/*
assert(CGM.getCodeGenOpts().HeterogeneousDwarf);
*/
assert(false);

llvm::DIGlobalVariable *GV = nullptr;

Expand Down Expand Up @@ -5695,8 +5704,11 @@ std::string CGDebugInfo::GetName(const Decl *D, bool Qualified) const {

void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
const VarDecl *D) {
/*
if (CGM.getCodeGenOpts().HeterogeneousDwarf)
return EmitGlobalVariableForHeterogeneousDwarf(Var, D);
*/
assert(false);

assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
if (D->hasAttr<NoDebugAttr>())
Expand Down Expand Up @@ -5767,7 +5779,10 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
void CGDebugInfo::EmitGlobalVariableForHeterogeneousDwarf(
llvm::GlobalVariable *Var, const VarDecl *D) {
assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
/*
assert(CGM.getCodeGenOpts().HeterogeneousDwarf);
*/
assert(false);
if (D->hasAttr<NoDebugAttr>())
return;

Expand Down Expand Up @@ -5844,8 +5859,11 @@ void CGDebugInfo::EmitGlobalVariableForHeterogeneousDwarf(
}

void CGDebugInfo::EmitGlobalVariable(const ValueDecl *VD, const APValue &Init) {
/*
if (CGM.getCodeGenOpts().HeterogeneousDwarf)
return EmitGlobalVariableForHeterogeneousDwarf(VD, Init);
*/
assert(false);

assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
if (VD->hasAttr<NoDebugAttr>())
Expand Down Expand Up @@ -6095,8 +6113,11 @@ void CGDebugInfo::EmitGlobalAlias(const llvm::GlobalValue *GV,
void CGDebugInfo::AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
const StringLiteral *S) {
// FIXME: Implement for heterogeneous debug info
/*
if (CGM.getCodeGenOpts().HeterogeneousDwarf)
return;
*/
assert(false);

SourceLocation Loc = S->getStrTokenLoc(0);
PresumedLoc PLoc = CGM.getContext().getSourceManager().getPresumedLoc(Loc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -960,12 +960,15 @@ void CodeGenModule::Release() {
// We support a single version in the linked module. The LLVM
// parser will drop debug info with a different version number
// (and warn about it, too).
/*
uint32_t DebugMetadataVersion =
CodeGenOpts.HeterogeneousDwarf ?
llvm::DEBUG_METADATA_VERSION_HETEROGENEOUS_DWARF :
llvm::DEBUG_METADATA_VERSION;
getModule().addModuleFlag(llvm::Module::Warning, "Debug Info Version",
DebugMetadataVersion);
*/
assert(false);
}

// We need to record the widths of enums and wchar_t, so that we can generate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4551,9 +4551,31 @@ renderDebugOptions(const ToolChain &TC, const Driver &D, const llvm::Triple &T,
bool EmitDwarfForAMDGCN = EmitDwarf && T.isAMDGCN();
if (EmitDwarfForAMDGCN)
CmdArgs.append({"-mllvm", "-amdgpu-spill-cfi-saved-regs"});
if (Args.hasFlag(options::OPT_gheterogeneous_dwarf,
options::OPT_gno_heterogeneous_dwarf, EmitDwarfForAMDGCN))
CmdArgs.push_back("-gheterogeneous-dwarf");
if (Arg *A = Args.getLastArg(options::OPT_gheterogeneous_dwarf_EQ)) {
A->render(Args, CmdArgs);
} else if (EmitDwarfForAMDGCN) {
#ifndef NDEBUG
// There doesn't seem to be a straightforward way to "render" an option
// acquired from the OptTable into a string we can append to CmdArgs.
// All of the logic is buried in "accept" which works directly in terms
// of an ArgList.
//
// Instead, assert that the static string we are adding to CmdArgs has
// the same shape as what a bare -gheterogeneous-dwarf would alias to
// if the user has provided it in ArgList.
const Option GHeterogeneousDwarf =
getDriverOptTable().getOption(options::OPT_gheterogeneous_dwarf);
const Option Aliased = GHeterogeneousDwarf.getAlias();
assert(Aliased.isValid() && "gheterogeneous-dwarf must be an alias");
assert(Aliased.getName() == "gheterogeneous-dwarf=" &&
"gheterogeneous-dwarf must alias gheterogeneous-dwarf=");
assert(StringRef(GHeterogeneousDwarf.getAliasArgs()) == "diexpression" &&
GHeterogeneousDwarf.getAliasArgs()[strlen("diexpression") + 1] ==
'\0' &&
"gheterogeneous-dwarf must alias gheterogeneous-dwarf=diexpression");
#endif
CmdArgs.push_back("-gheterogeneous-dwarf=diexpression");
}
}

static void ProcessVSRuntimeLibrary(const ArgList &Args,
Expand Down