[MachineScheduler] Fix physreg dependencies of ExitSU (#123541)
[llvm-project.git] / llvm / lib / CodeGen / EHContGuardCatchret.cpp
blobcd1cdb065361845c711b4ab18e741bb3970f63aa
1 //===-- EHContGuardCatchret.cpp - Catchret 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 catchret target and store this in the MachineFunction's
12 /// CatchRetTargets vector. This will be used to emit the table of valid targets
13 /// used by EHCont Guard.
14 ///
15 //===----------------------------------------------------------------------===//
17 #include "llvm/ADT/Statistic.h"
18 #include "llvm/CodeGen/MachineBasicBlock.h"
19 #include "llvm/CodeGen/MachineFunctionPass.h"
20 #include "llvm/CodeGen/MachineModuleInfo.h"
21 #include "llvm/CodeGen/Passes.h"
22 #include "llvm/IR/Module.h"
23 #include "llvm/InitializePasses.h"
25 using namespace llvm;
27 #define DEBUG_TYPE "ehcontguard-catchret"
29 STATISTIC(EHContGuardCatchretTargets,
30 "Number of EHCont Guard catchret targets");
32 namespace {
34 /// MachineFunction pass to insert a symbol before each valid catchret target
35 /// and store these in the MachineFunction's CatchRetTargets vector.
36 class EHContGuardCatchret : public MachineFunctionPass {
37 public:
38 static char ID;
40 EHContGuardCatchret() : MachineFunctionPass(ID) {
41 initializeEHContGuardCatchretPass(*PassRegistry::getPassRegistry());
44 StringRef getPassName() const override {
45 return "EH Cont Guard catchret targets";
48 bool runOnMachineFunction(MachineFunction &MF) override;
51 } // end anonymous namespace
53 char EHContGuardCatchret::ID = 0;
55 INITIALIZE_PASS(EHContGuardCatchret, "EHContGuardCatchret",
56 "Insert symbols at valid catchret targets for /guard:ehcont",
57 false, false)
58 FunctionPass *llvm::createEHContGuardCatchretPass() {
59 return new EHContGuardCatchret();
62 bool EHContGuardCatchret::runOnMachineFunction(MachineFunction &MF) {
64 // Skip modules for which the ehcontguard flag is not set.
65 if (!MF.getFunction().getParent()->getModuleFlag("ehcontguard"))
66 return false;
68 // Skip functions that do not have catchret
69 if (!MF.hasEHCatchret())
70 return false;
72 bool Result = false;
74 for (MachineBasicBlock &MBB : MF) {
75 if (MBB.isEHCatchretTarget()) {
76 MF.addCatchretTarget(MBB.getEHCatchretSymbol());
77 EHContGuardCatchretTargets++;
78 Result = true;
82 return Result;