Path: blob/main/contrib/llvm-project/llvm/lib/CodeGen/EHContGuardCatchret.cpp
35234 views
//===-- EHContGuardCatchret.cpp - Catchret target symbols -------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file9/// This file contains a machine function pass to insert a symbol before each10/// valid catchret target and store this in the MachineFunction's11/// CatchRetTargets vector. This will be used to emit the table of valid targets12/// used by EHCont Guard.13///14//===----------------------------------------------------------------------===//1516#include "llvm/ADT/Statistic.h"17#include "llvm/CodeGen/MachineBasicBlock.h"18#include "llvm/CodeGen/MachineFunctionPass.h"19#include "llvm/CodeGen/MachineModuleInfo.h"20#include "llvm/CodeGen/Passes.h"21#include "llvm/IR/Module.h"22#include "llvm/InitializePasses.h"2324using namespace llvm;2526#define DEBUG_TYPE "ehcontguard-catchret"2728STATISTIC(EHContGuardCatchretTargets,29"Number of EHCont Guard catchret targets");3031namespace {3233/// MachineFunction pass to insert a symbol before each valid catchret target34/// and store these in the MachineFunction's CatchRetTargets vector.35class EHContGuardCatchret : public MachineFunctionPass {36public:37static char ID;3839EHContGuardCatchret() : MachineFunctionPass(ID) {40initializeEHContGuardCatchretPass(*PassRegistry::getPassRegistry());41}4243StringRef getPassName() const override {44return "EH Cont Guard catchret targets";45}4647bool runOnMachineFunction(MachineFunction &MF) override;48};4950} // end anonymous namespace5152char EHContGuardCatchret::ID = 0;5354INITIALIZE_PASS(EHContGuardCatchret, "EHContGuardCatchret",55"Insert symbols at valid catchret targets for /guard:ehcont",56false, false)57FunctionPass *llvm::createEHContGuardCatchretPass() {58return new EHContGuardCatchret();59}6061bool EHContGuardCatchret::runOnMachineFunction(MachineFunction &MF) {6263// Skip modules for which the ehcontguard flag is not set.64if (!MF.getFunction().getParent()->getModuleFlag("ehcontguard"))65return false;6667// Skip functions that do not have catchret68if (!MF.hasEHCatchret())69return false;7071bool Result = false;7273for (MachineBasicBlock &MBB : MF) {74if (MBB.isEHCatchretTarget()) {75MF.addCatchretTarget(MBB.getEHCatchretSymbol());76EHContGuardCatchretTargets++;77Result = true;78}79}8081return Result;82}838485