[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / llvm / lib / CodeGen / EHContGuardCatchret.cpp
blobb26aa792bb9379bcc23698be538da0c0126075c1
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/InitializePasses.h"
24 using namespace llvm;
26 #define DEBUG_TYPE "ehcontguard-catchret"
28 STATISTIC(EHContGuardCatchretTargets,
29 "Number of EHCont Guard catchret targets");
31 namespace {
33 /// MachineFunction pass to insert a symbol before each valid catchret target
34 /// and store these in the MachineFunction's CatchRetTargets vector.
35 class EHContGuardCatchret : public MachineFunctionPass {
36 public:
37 static char ID;
39 EHContGuardCatchret() : MachineFunctionPass(ID) {
40 initializeEHContGuardCatchretPass(*PassRegistry::getPassRegistry());
43 StringRef getPassName() const override {
44 return "EH Cont Guard catchret targets";
47 bool runOnMachineFunction(MachineFunction &MF) override;
50 } // end anonymous namespace
52 char EHContGuardCatchret::ID = 0;
54 INITIALIZE_PASS(EHContGuardCatchret, "EHContGuardCatchret",
55 "Insert symbols at valid catchret targets for /guard:ehcont",
56 false, false)
57 FunctionPass *llvm::createEHContGuardCatchretPass() {
58 return new EHContGuardCatchret();
61 bool EHContGuardCatchret::runOnMachineFunction(MachineFunction &MF) {
63 // Skip modules for which the ehcontguard flag is not set.
64 if (!MF.getMMI().getModule()->getModuleFlag("ehcontguard"))
65 return false;
67 // Skip functions that do not have catchret
68 if (!MF.hasEHCatchret())
69 return false;
71 bool Result = false;
73 for (MachineBasicBlock &MBB : MF) {
74 if (MBB.isEHCatchretTarget()) {
75 MF.addCatchretTarget(MBB.getEHCatchretSymbol());
76 EHContGuardCatchretTargets++;
77 Result = true;
81 return Result;