diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h index b6b4c18ad17f7..8d2684698233a 100644 --- a/llvm/include/llvm/CodeGen/AsmPrinter.h +++ b/llvm/include/llvm/CodeGen/AsmPrinter.h @@ -449,9 +449,9 @@ class AsmPrinter : public MachineFunctionPass { /// Since emitting CFI unwind information is entangled with supporting the /// exceptions, this returns true for platforms which use CFI unwind - /// information for debugging purpose when + /// information for other purposes (debugging, sanitizers, ...) when /// `MCAsmInfo::ExceptionsType == ExceptionHandling::None`. - bool needsCFIForDebug() const; + bool usesCFIWithoutEH() const; /// Print to the current output stream assembly representations of the /// constants in the constant pool MCP. This is used to print out constants diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h index ab8c36a412fc4..c28cd12112358 100644 --- a/llvm/include/llvm/MC/MCAsmInfo.h +++ b/llvm/include/llvm/MC/MCAsmInfo.h @@ -453,9 +453,9 @@ class MCAsmInfo { /// Exception handling format for the target. Defaults to None. ExceptionHandling ExceptionsType = ExceptionHandling::None; - /// True if target uses CFI unwind information for debugging purpose when - /// `ExceptionsType == ExceptionHandling::None`. - bool UsesCFIForDebug = false; + /// True if target uses CFI unwind information for other purposes than EH + /// (debugging / sanitizers) when `ExceptionsType == ExceptionHandling::None`. + bool UsesCFIWithoutEH = false; /// Windows exception handling data (.pdata) encoding. Defaults to Invalid. WinEH::EncodingType WinEHEncodingType = WinEH::EncodingType::Invalid; @@ -785,7 +785,9 @@ class MCAsmInfo { ExceptionsType = EH; } - bool doesUseCFIForDebug() const { return UsesCFIForDebug; } + bool usesCFIWithoutEH() const { + return ExceptionsType == ExceptionHandling::None && UsesCFIWithoutEH; + } /// Returns true if the exception handling method for the platform uses call /// frame information to unwind. diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 8b81bdfbfda64..162634cfb402b 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -541,7 +541,7 @@ bool AsmPrinter::doInitialization(Module &M) { break; } assert(MAI->getExceptionHandlingType() == ExceptionHandling::DwarfCFI || - ModuleCFISection != CFISection::EH); + usesCFIWithoutEH() || ModuleCFISection != CFISection::EH); break; default: break; @@ -550,7 +550,7 @@ bool AsmPrinter::doInitialization(Module &M) { EHStreamer *ES = nullptr; switch (MAI->getExceptionHandlingType()) { case ExceptionHandling::None: - if (!needsCFIForDebug()) + if (!usesCFIWithoutEH()) break; [[fallthrough]]; case ExceptionHandling::SjLj: @@ -1266,6 +1266,9 @@ AsmPrinter::getFunctionCFISectionType(const Function &F) const { F.needsUnwindTableEntry()) return CFISection::EH; + if (MAI->usesCFIWithoutEH() && F.hasUWTable()) + return CFISection::EH; + assert(MMI != nullptr && "Invalid machine module info"); if (MMI->hasDebugInfo() || TM.Options.ForceDwarfFrameSection) return CFISection::Debug; @@ -1282,14 +1285,13 @@ bool AsmPrinter::needsSEHMoves() { return MAI->usesWindowsCFI() && MF->getFunction().needsUnwindTableEntry(); } -bool AsmPrinter::needsCFIForDebug() const { - return MAI->getExceptionHandlingType() == ExceptionHandling::None && - MAI->doesUseCFIForDebug() && ModuleCFISection == CFISection::Debug; +bool AsmPrinter::usesCFIWithoutEH() const { + return MAI->usesCFIWithoutEH() && ModuleCFISection != CFISection::None; } void AsmPrinter::emitCFIInstruction(const MachineInstr &MI) { ExceptionHandling ExceptionHandlingType = MAI->getExceptionHandlingType(); - if (!needsCFIForDebug() && + if (!usesCFIWithoutEH() && ExceptionHandlingType != ExceptionHandling::DwarfCFI && ExceptionHandlingType != ExceptionHandling::ARM) return; diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp index df4fe8d49806a..10c844ddb14a1 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp @@ -94,7 +94,7 @@ void DwarfCFIException::beginFunction(const MachineFunction *MF) { shouldEmitCFI = MAI.usesCFIForEH() && (shouldEmitPersonality || shouldEmitMoves); else - shouldEmitCFI = Asm->needsCFIForDebug() && shouldEmitMoves; + shouldEmitCFI = Asm->usesCFIWithoutEH() && shouldEmitMoves; } void DwarfCFIException::beginBasicBlockSection(const MachineBasicBlock &MBB) { diff --git a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCAsmInfo.cpp b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCAsmInfo.cpp index a988c0412c31e..d539d75fdff06 100644 --- a/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCAsmInfo.cpp +++ b/llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCAsmInfo.cpp @@ -40,7 +40,7 @@ AMDGPUMCAsmInfo::AMDGPUMCAsmInfo(const Triple &TT, HasNoDeadStrip = true; //===--- Dwarf Emission Directives -----------------------------------===// SupportsDebugInformation = true; - UsesCFIForDebug = true; + UsesCFIWithoutEH = true; DwarfRegNumForCFI = true; UseIntegratedAssembler = false; diff --git a/llvm/test/CodeGen/AMDGPU/eh_frame.ll b/llvm/test/CodeGen/AMDGPU/eh_frame.ll new file mode 100644 index 0000000000000..ea705374272be --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/eh_frame.ll @@ -0,0 +1,29 @@ +; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx908 -o - < %s | FileCheck %s --check-prefix=EH +; RUN: llc -mtriple=amdgcn-amd-amdhsa --force-dwarf-frame-section -o - < %s | FileCheck %s --check-prefix=BOTH +; RUN: llc -mtriple=amdgcn-amd-amdhsa --exception-model=dwarf -o - < %s | FileCheck %s --check-prefix=EH +; RUN: llc -mtriple=amdgcn-amd-amdhsa --force-dwarf-frame-section --exception-model=dwarf -o - < %s | FileCheck %s --check-prefix=BOTH + +; EH: f: +; EH-NOT: .cfi_sections +; EH: .cfi_startproc + +; BOTH: f: +; BOTH: .cfi_sections .eh_frame, .debug_frame +; BOTH: .cfi_startproc + +define void @f() nounwind uwtable !dbg !0 { +entry: + ret void +} + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!7} +!5 = !{!0} + +!0 = distinct !DISubprogram(name: "f", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !2, scopeLine: 1, file: !6, scope: !1, type: !3) +!1 = !DIFile(filename: "/home/llvm/test.c", directory: "/home/llvm/build") +!2 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang", isOptimized: true, emissionKind: FullDebug, file: !6, enums: !{}, retainedTypes: !{}) +!3 = !DISubroutineType(types: !4) +!4 = !{null} +!6 = !DIFile(filename: "/home/llvm/test.c", directory: "/home/llvm/build") +!7 = !{i32 1, !"Debug Info Version", i32 3} diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_generated_funcs.ll.generated.expected b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_generated_funcs.ll.generated.expected index 758ea1a3bdc48..3c0c6f0de3463 100644 --- a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_generated_funcs.ll.generated.expected +++ b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_generated_funcs.ll.generated.expected @@ -67,6 +67,7 @@ attributes #0 = { noredzone nounwind ssp uwtable "frame-pointer"="all" } ; CHECK-LABEL: check_boundaries: ; CHECK: check_boundaries$local: ; CHECK-NEXT: .type check_boundaries$local,@function +; CHECK-NEXT: .cfi_startproc ; CHECK-NEXT: ; %bb.0: ; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) ; CHECK-NEXT: s_mov_b32 s4, s33 @@ -78,6 +79,7 @@ attributes #0 = { noredzone nounwind ssp uwtable "frame-pointer"="all" } ; CHECK-LABEL: main: ; CHECK: main$local: ; CHECK-NEXT: .type main$local,@function +; CHECK-NEXT: .cfi_startproc ; CHECK-NEXT: ; %bb.0: ; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) ; CHECK-NEXT: s_mov_b32 s6, s33 diff --git a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_generated_funcs.ll.nogenerated.expected b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_generated_funcs.ll.nogenerated.expected index a8a36fd2328c2..304298cd5f1c3 100644 --- a/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_generated_funcs.ll.nogenerated.expected +++ b/llvm/test/tools/UpdateTestChecks/update_llc_test_checks/Inputs/amdgpu_generated_funcs.ll.nogenerated.expected @@ -8,6 +8,7 @@ define dso_local i32 @check_boundaries() #0 { ; CHECK-LABEL: check_boundaries: ; CHECK: check_boundaries$local: ; CHECK-NEXT: .type check_boundaries$local,@function +; CHECK-NEXT: .cfi_startproc ; CHECK-NEXT: ; %bb.0: ; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) ; CHECK-NEXT: s_mov_b32 s4, s33 @@ -55,6 +56,7 @@ define dso_local i32 @main() #0 { ; CHECK-LABEL: main: ; CHECK: main$local: ; CHECK-NEXT: .type main$local,@function +; CHECK-NEXT: .cfi_startproc ; CHECK-NEXT: ; %bb.0: ; CHECK-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0) ; CHECK-NEXT: s_mov_b32 s6, s33