LLVM 24.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
19#include "llvm/ADT/Statistic.h"
23#include "llvm/CodeGen/Passes.h"
24#include "llvm/IR/Module.h"
26
27using namespace llvm;
28
29#define DEBUG_TYPE "ehcontguard-catchret"
30
31STATISTIC(EHContGuardTargetsFound, "Number of EHCont Guard targets");
32
34 // Skip modules for which the ehcontguard flag is not set.
35 if (!MF.getFunction().getParent()->getModuleFlag("ehcontguard"))
36 return false;
37
38 // Skip functions that do not have targets
39 if (!MF.hasEHContTarget())
40 return false;
41
42 bool Result = false;
43
44 for (MachineBasicBlock &MBB : MF) {
45 if (MBB.isEHContTarget()) {
46 MF.addEHContTarget(MBB.getEHContSymbol());
47 EHContGuardTargetsFound++;
48 Result = true;
49 }
50 }
51
52 return Result;
53}
54
55namespace {
56
57/// MachineFunction pass to insert a symbol before each valid catchret target
58/// and store these in the MachineFunction's CatchRetTargets vector.
59class EHContGuardTargetsLegacy : public MachineFunctionPass {
60public:
61 static char ID;
62
63 EHContGuardTargetsLegacy() : MachineFunctionPass(ID) {}
64
65 StringRef getPassName() const override {
66 return "EH Cont Guard catchret targets";
67 }
68
69 void getAnalysisUsage(AnalysisUsage &AU) const override {
70 AU.setPreservesCFG();
72 }
73
74 bool runOnMachineFunction(MachineFunction &MF) override {
75 return runEHContGuardTargets(MF);
76 }
77};
78
79} // end anonymous namespace
80
81char EHContGuardTargetsLegacy::ID = 0;
82
83INITIALIZE_PASS(EHContGuardTargetsLegacy, "EHContGuardTargets",
84 "Insert symbols at valid targets for /guard:ehcont", false,
85 false)
87 return new EHContGuardTargetsLegacy();
88}
89
MachineBasicBlock & MBB
static bool runEHContGuardTargets(MachineFunction &MF)
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
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:275
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
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...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
void addEHContTarget(MCSymbol *Target)
Add the specified symbol to the list of targets for Windows EH Continuation Guard.
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:358
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI FunctionPass * createEHContGuardTargetsLegacy()
Creates Windows EH Continuation Guard target identification pass.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.