LLVM 22.0.0git
EHContGuardTargets.cpp
Go to the documentation of this file.
1//===-- EHContGuardTargets.cpp - EH continuation target symbols -*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file contains a machine function pass to insert a symbol before each
11/// valid target where the unwinder in Windows may continue exectution after an
12/// exception is thrown and store this in the MachineFunction's EHContTargets
13/// vector. This will be used to emit the table of valid targets used by Windows
14/// EH Continuation Guard.
15///
16//===----------------------------------------------------------------------===//
17
18#include "llvm/ADT/Statistic.h"
22#include "llvm/CodeGen/Passes.h"
23#include "llvm/IR/Module.h"
25
26using namespace llvm;
27
28#define DEBUG_TYPE "ehcontguard-catchret"
29
30STATISTIC(EHContGuardTargetsFound, "Number of EHCont Guard targets");
31
32namespace {
33
34/// MachineFunction pass to insert a symbol before each valid catchret target
35/// and store these in the MachineFunction's CatchRetTargets vector.
36class EHContGuardTargets : public MachineFunctionPass {
37public:
38 static char ID;
39
40 EHContGuardTargets() : MachineFunctionPass(ID) {
42 }
43
44 StringRef getPassName() const override {
45 return "EH Cont Guard catchret targets";
46 }
47
48 bool runOnMachineFunction(MachineFunction &MF) override;
49};
50
51} // end anonymous namespace
52
53char EHContGuardTargets::ID = 0;
54
55INITIALIZE_PASS(EHContGuardTargets, "EHContGuardTargets",
56 "Insert symbols at valid targets for /guard:ehcont", false,
57 false)
59 return new EHContGuardTargets();
60}
61
62bool EHContGuardTargets::runOnMachineFunction(MachineFunction &MF) {
63
64 // Skip modules for which the ehcontguard flag is not set.
65 if (!MF.getFunction().getParent()->getModuleFlag("ehcontguard"))
66 return false;
67
68 // Skip functions that do not have targets
69 if (!MF.hasEHContTarget())
70 return false;
71
72 bool Result = false;
73
74 for (MachineBasicBlock &MBB : MF) {
75 if (MBB.isEHContTarget()) {
76 MF.addEHContTarget(MBB.getEHContSymbol());
77 EHContGuardTargetsFound++;
78 Result = true;
79 }
80 }
81
82 return Result;
83}
MachineBasicBlock & MBB
Module.h This file contains the declarations for the Module class.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
Module * getParent()
Get the module that this global value is contained inside of...
LLVM_ABI MCSymbol * getEHContSymbol() const
Return the Windows EH Continuation Symbol for this basic block.
bool isEHContTarget() const
Returns true if this is a target of Windows EH Continuation Guard.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Function & getFunction()
Return the LLVM function that this machine code represents.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Definition Module.cpp:353
static LLVM_ABI PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void initializeEHContGuardTargetsPass(PassRegistry &)
LLVM_ABI FunctionPass * createEHContGuardTargetsPass()
Creates Windows EH Continuation Guard target identification pass.