Path: blob/main/contrib/llvm-project/llvm/lib/CodeGen/FuncletLayout.cpp
35233 views
//===-- FuncletLayout.cpp - Contiguously lay out funclets -----------------===//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// This file implements basic block placement transformations which result in9// funclets being contiguous.10//11//===----------------------------------------------------------------------===//12#include "llvm/CodeGen/Analysis.h"13#include "llvm/CodeGen/MachineFunction.h"14#include "llvm/CodeGen/MachineFunctionPass.h"15#include "llvm/CodeGen/Passes.h"16#include "llvm/InitializePasses.h"17using namespace llvm;1819#define DEBUG_TYPE "funclet-layout"2021namespace {22class FuncletLayout : public MachineFunctionPass {23public:24static char ID; // Pass identification, replacement for typeid25FuncletLayout() : MachineFunctionPass(ID) {26initializeFuncletLayoutPass(*PassRegistry::getPassRegistry());27}2829bool runOnMachineFunction(MachineFunction &F) override;30MachineFunctionProperties getRequiredProperties() const override {31return MachineFunctionProperties().set(32MachineFunctionProperties::Property::NoVRegs);33}34};35}3637char FuncletLayout::ID = 0;38char &llvm::FuncletLayoutID = FuncletLayout::ID;39INITIALIZE_PASS(FuncletLayout, DEBUG_TYPE,40"Contiguously Lay Out Funclets", false, false)4142bool FuncletLayout::runOnMachineFunction(MachineFunction &F) {43// Even though this gets information from getEHScopeMembership(), this pass is44// only necessary for funclet-based EH personalities, in which these EH scopes45// are outlined at the end.46DenseMap<const MachineBasicBlock *, int> FuncletMembership =47getEHScopeMembership(F);48if (FuncletMembership.empty())49return false;5051F.sort([&](MachineBasicBlock &X, MachineBasicBlock &Y) {52auto FuncletX = FuncletMembership.find(&X);53auto FuncletY = FuncletMembership.find(&Y);54assert(FuncletX != FuncletMembership.end());55assert(FuncletY != FuncletMembership.end());56return FuncletX->second < FuncletY->second;57});5859// Conservatively assume we changed something.60return true;61}626364