Currently, an AsmPrinterHandler has several methods that allow to
dynamically hook in unwind or debug info emission, e.g. at begin/end of
every function or instruction. The class hierarchy and the actually
overridden functions are as follows:
(SymSz=setSymbolSize, mFE=markFunctionEnd, BBS=BasicBlockSection,
FL=Funclet; b=beginX, e=endX)
SymSz Mod Fn mFE BBS FL Inst
AsmPrinterHandler - - - - - - -
` PseudoProbeHandler - - - - - - -
` WinCFGuard - e e - - - -
` EHStreamer - - - - - - -
` DwarfCFIException - e be - be - -
` ARMException - - be e - - -
` AIXException - - e - - - -
` WinException - e be e - be -
` WasmException - e be - - - -
` DebugHandlerBase - b be - be - be
` BTFDebug - e - - - - b
` CodeViewDebug - be - - - - b
` DWARFDebug yes be - - - - b
Doing virtual function calls per instruction is costly and useless when
the called function does nothing.
This commit performs the following clean-up/improvements:
- PseudoProbeHandler is no longer an AsmPrinterHandler -- it used
nothing of its functionality to hook in at the possible points. This
avoids virtual function calls when a pseudo probe printer is present.
- DebugHandlerBase is no longer an AsmPrinterHandler, but a separate
base class. DebugHandlerBase is the only remaining "hook" for begin/end
instruction and setSymbolSize (only used by DWARFDebug). begin/end for
function and basic block sections are never overriden and therefore are
no longer virtual. (Originally I intended there to be only one debug
handler, but BPF as the only target supports two at the same time: DWARF
and BTF.)
- AsmPrinterHandler no longer has begin/end instruction and
setSymbolSize hooks -- these were only used by DebugHandlerBase. This
avoid iterating over handlers in every instruction.
AsmPrinterHandler Mod Fn mFE BBS FL
` WinCFGuard e e - - -
` EHStreamer - - - - -
` DwarfCFIException e be - be -
` ARMException - be e - -
` AIXException - e - - -
` WinException e be e - be
` WasmException e be - - -
SymSz Mod Fn BBS Inst
DebugHandlerBase - b be be be
` BTFDebug - e b
` CodeViewDebug - be b
` DWARFDebug yes be b
PseudoProbeHandler (no shared methods)
To continue allowing external users (e.g., Julia) to hook in at every
instruction, a new method addDebugHandler is exposed.
This results in a performance improvement, especially in the -O0 -g0
case with unwind information (e.g., JIT baseline).
50 lines
1.6 KiB
C++
50 lines
1.6 KiB
C++
//===-- WinCFGuard.h - Windows Control Flow Guard Handling ----*- C++ -*--===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file contains support for writing the metadata for Windows Control Flow
|
|
// Guard, including address-taken functions, and valid longjmp targets.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_WINCFGUARD_H
|
|
#define LLVM_LIB_CODEGEN_ASMPRINTER_WINCFGUARD_H
|
|
|
|
#include "llvm/CodeGen/AsmPrinterHandler.h"
|
|
#include "llvm/Support/Compiler.h"
|
|
#include <vector>
|
|
|
|
namespace llvm {
|
|
|
|
class LLVM_LIBRARY_VISIBILITY WinCFGuard : public AsmPrinterHandler {
|
|
/// Target of directive emission.
|
|
AsmPrinter *Asm;
|
|
std::vector<const MCSymbol *> LongjmpTargets;
|
|
MCSymbol *lookupImpSymbol(const MCSymbol *Sym);
|
|
|
|
public:
|
|
WinCFGuard(AsmPrinter *A);
|
|
~WinCFGuard() override;
|
|
|
|
/// Emit the Control Flow Guard function ID table.
|
|
void endModule() override;
|
|
|
|
/// Gather pre-function debug information.
|
|
/// Every beginFunction(MF) call should be followed by an endFunction(MF)
|
|
/// call.
|
|
void beginFunction(const MachineFunction *MF) override {}
|
|
|
|
/// Gather post-function debug information.
|
|
/// Please note that some AsmPrinter implementations may not call
|
|
/// beginFunction at all.
|
|
void endFunction(const MachineFunction *MF) override;
|
|
};
|
|
|
|
} // namespace llvm
|
|
|
|
#endif
|