LLVM 24.0.0git
FuncletLayout.cpp
Go to the documentation of this file.
1//===-- FuncletLayout.cpp - Contiguously lay out funclets -----------------===//
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// This file implements basic block placement transformations which result in
10// funclets being contiguous.
11//
12//===----------------------------------------------------------------------===//
18#include "llvm/CodeGen/Passes.h"
20using namespace llvm;
21
22#define DEBUG_TYPE "funclet-layout"
23
25 // Even though this gets information from getEHScopeMembership(), this pass is
26 // only necessary for funclet-based EH personalities, in which these EH scopes
27 // are outlined at the end.
30 if (FuncletMembership.empty())
31 return false;
32
34 auto FuncletX = FuncletMembership.find(&X);
35 auto FuncletY = FuncletMembership.find(&Y);
36 assert(FuncletX != FuncletMembership.end());
37 assert(FuncletY != FuncletMembership.end());
38 return FuncletX->second < FuncletY->second;
39 });
40
41 // Conservatively assume we changed something.
42 return true;
43}
44
45namespace {
46class FuncletLayoutLegacy : public MachineFunctionPass {
47public:
48 static char ID; // Pass identification, replacement for typeid
49 FuncletLayoutLegacy() : MachineFunctionPass(ID) {}
50
51 bool runOnMachineFunction(MachineFunction &F) override {
52 return runFuncletLayout(F);
53 }
54 MachineFunctionProperties getRequiredProperties() const override {
55 return MachineFunctionProperties().setNoVRegs();
56 }
57};
58} // namespace
59
60char FuncletLayoutLegacy::ID = 0;
61char &llvm::FuncletLayoutID = FuncletLayoutLegacy::ID;
62INITIALIZE_PASS(FuncletLayoutLegacy, DEBUG_TYPE,
63 "Contiguously Lay Out Funclets", false, false)
64
67 MFPropsModifier _(*this, MF);
68 if (!runFuncletLayout(MF))
70
72}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define X(NUM, ENUM, NAME)
Definition ELF.h:665
static bool runFuncletLayout(MachineFunction &F)
#define DEBUG_TYPE
#define _
#define F(x, y, z)
Definition MD5.cpp:54
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
static TableGen::Emitter::Opt Y("gen-skeleton-entry", EmitSkeleton, "Generate example skeleton entry")
bool empty() const
Definition DenseMap.h:716
iterator find(const_arg_type_t< KeyT > Val)
Definition DenseMap.h:766
iterator end()
Definition DenseMap.h:686
An RAII based helper class to modify MachineFunctionProperties when running pass.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI char & FuncletLayoutID
This pass lays out funclets contiguously.
LLVM_ABI DenseMap< const MachineBasicBlock *, int > getEHScopeMembership(const MachineFunction &MF)
Definition Analysis.cpp:926