Path: blob/main/contrib/llvm-project/llvm/lib/CodeGen/EHContGuardTargets.cpp
213765 views
//===-- EHContGuardTargets.cpp - EH continuation 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 target where the unwinder in Windows may continue exectution after an11/// exception is thrown and store this in the MachineFunction's EHContTargets12/// vector. This will be used to emit the table of valid targets used by Windows13/// EH Continuation Guard.14///15//===----------------------------------------------------------------------===//1617#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"2425using namespace llvm;2627#define DEBUG_TYPE "ehcontguard-catchret"2829STATISTIC(EHContGuardTargetsFound, "Number of EHCont Guard targets");3031namespace {3233/// MachineFunction pass to insert a symbol before each valid catchret target34/// and store these in the MachineFunction's CatchRetTargets vector.35class EHContGuardTargets : public MachineFunctionPass {36public:37static char ID;3839EHContGuardTargets() : MachineFunctionPass(ID) {40initializeEHContGuardTargetsPass(*PassRegistry::getPassRegistry());41}4243StringRef getPassName() const override {44return "EH Cont Guard catchret targets";45}4647bool runOnMachineFunction(MachineFunction &MF) override;48};4950} // end anonymous namespace5152char EHContGuardTargets::ID = 0;5354INITIALIZE_PASS(EHContGuardTargets, "EHContGuardTargets",55"Insert symbols at valid targets for /guard:ehcont", false,56false)57FunctionPass *llvm::createEHContGuardTargetsPass() {58return new EHContGuardTargets();59}6061bool EHContGuardTargets::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 targets68if (!MF.hasEHContTarget())69return false;7071bool Result = false;7273for (MachineBasicBlock &MBB : MF) {74if (MBB.isEHContTarget()) {75MF.addEHContTarget(MBB.getEHContSymbol());76EHContGuardTargetsFound++;77Result = true;78}79}8081return Result;82}838485