1//===-- CodeGen/AsmPrinter/DwarfException.cpp - Dwarf Exception Impl ------===//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//===----------------------------------------------------------------------===//
9// This file contains support for writing DWARF exception info into asm files.
11//===----------------------------------------------------------------------===//
31void DwarfCFIException::addPersonality(
const GlobalValue *Personality) {
33 Personalities.push_back(Personality);
36/// endModule - Emit all exception information that should come after the
39 // SjLj uses this pass and it doesn't need this info.
40 if (!
Asm->MAI->usesCFIForEH())
50 // Emit indirect reference table for all used personality functions
51 for (
const GlobalValue *Personality : Personalities) {
56 Personalities.clear();
60 shouldEmitPersonality = shouldEmitLSDA =
false;
63 // If any landing pads survive, we need an EH table.
66 // See if we need frame move info.
67 bool shouldEmitMoves =
73 if (
F.hasPersonalityFn())
76 // Emit a personality function even when there are no landing pads
77 forceEmitPersonality =
78 // ...if a personality function is explicitly specified
79 F.hasPersonalityFn() &&
80 // ... and it's not known to be a noop in the absence of invokes
82 // ... and we're not explicitly asked not to emit it
83 F.needsUnwindTableEntry();
85 shouldEmitPersonality =
86 (forceEmitPersonality ||
91 shouldEmitLSDA = shouldEmitPersonality &&
97 MAI.
usesCFIForEH() && (shouldEmitPersonality || shouldEmitMoves);
99 shouldEmitCFI =
Asm->usesCFIWithoutEH() && shouldEmitMoves;
106 if (!hasEmittedCFISections) {
108 // If we don't say anything it implies `.cfi_sections .eh_frame`, so we
109 // chose not to be verbose in that case. And with `ForceDwarfFrameSection`,
110 // we should always emit .debug_frame.
112 Asm->TM.Options.ForceDwarfFrameSection ||
113 Asm->TM.Options.MCOptions.EmitSFrameUnwind)
114 Asm->OutStreamer->emitCFISections(
116 Asm->TM.Options.MCOptions.EmitSFrameUnwind);
117 hasEmittedCFISections =
true;
120 Asm->OutStreamer->emitCFIStartProc(
/*IsSimple=*/false);
122 // Indicate personality routine, if any.
123 if (!shouldEmitPersonality)
126 auto &
F =
MBB.getParent()->getFunction();
128 assert(
P &&
"Expected personality function");
129 // Record the personality function.
135 Asm->OutStreamer->emitCFIPersonality(Sym, PerEncoding);
137 // Provide LSDA information.
139 Asm->OutStreamer->emitCFILsda(
Asm->getMBBExceptionSym(
MBB),
145 Asm->OutStreamer->emitCFIEndProc();
148/// endFunction - Gather and emit post-function exception information.
151 if (!shouldEmitPersonality)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains constants used for implementing Dwarf debug support.
This class is intended to be used as a driving class for all asm writers.
@ None
Do not emit either .eh_frame or .debug_frame.
@ Debug
Emit .debug_frame.
void endBasicBlockSection(const MachineBasicBlock &MBB) override
Process the end of a basic-block-section within a function.
~DwarfCFIException() override
void beginBasicBlockSection(const MachineBasicBlock &MBB) override
Process the beginning of a new basic-block-section within a function.
void endFunction(const MachineFunction *) override
Gather and emit post-function exception information.
void endModule() override
Emit all exception information that should come after the content.
DwarfCFIException(AsmPrinter *A)
void beginFunction(const MachineFunction *MF) override
Gather pre-function exception information.
AsmPrinter * Asm
Target of directive emission.
MCSymbol * emitExceptionTable()
Emit landing pads and actions.
MachineModuleInfo * MMI
Collected machine module information.
EHStreamer(AsmPrinter *A)
This class is intended to be used as a base class for asm properties and features specific to the tar...
bool usesCFIForEH() const
Returns true if the exception handling method for the platform uses call frame information to unwind.
ExceptionHandling getExceptionHandlingType() const
const MCAsmInfo * getAsmInfo() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
MCContext & getContext() const
Function & getFunction()
Return the LLVM function that this machine code represents.
const std::vector< LandingPadInfo > & getLandingPads() const
Return a reference to the landing pad info for the current function.
unsigned getLSDAEncoding() const
virtual MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const
unsigned getPersonalityEncoding() const
virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM, const MCSymbol *Sym, const MachineModuleInfo *MMI) const
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
@ None
No exception support.
bool isNoOpWithoutInvoke(EHPersonality Pers)
Return true if this personality may be safely removed if there are no invoke instructions remaining i...
LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.