LLVM  13.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 //===----------------------------------------------------------------------===//
13 #include "llvm/CodeGen/Analysis.h"
16 #include "llvm/CodeGen/Passes.h"
17 #include "llvm/InitializePasses.h"
18 using namespace llvm;
19 
20 #define DEBUG_TYPE "funclet-layout"
21 
22 namespace {
23 class FuncletLayout : public MachineFunctionPass {
24 public:
25  static char ID; // Pass identification, replacement for typeid
26  FuncletLayout() : MachineFunctionPass(ID) {
28  }
29 
30  bool runOnMachineFunction(MachineFunction &F) override;
31  MachineFunctionProperties getRequiredProperties() const override {
34  }
35 };
36 }
37 
38 char FuncletLayout::ID = 0;
40 INITIALIZE_PASS(FuncletLayout, DEBUG_TYPE,
41  "Contiguously Lay Out Funclets", false, false)
42 
43 bool FuncletLayout::runOnMachineFunction(MachineFunction &F) {
44  // Even though this gets information from getEHScopeMembership(), this pass is
45  // only necessary for funclet-based EH personalities, in which these EH scopes
46  // are outlined at the end.
49  if (FuncletMembership.empty())
50  return false;
51 
52  F.sort([&](MachineBasicBlock &X, MachineBasicBlock &Y) {
53  auto FuncletX = FuncletMembership.find(&X);
54  auto FuncletY = FuncletMembership.find(&Y);
55  assert(FuncletX != FuncletMembership.end());
56  assert(FuncletY != FuncletMembership.end());
57  return FuncletX->second < FuncletY->second;
58  });
59 
60  // Conservatively assume we changed something.
61  return true;
62 }
llvm
Definition: AllocatorList.h:23
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
llvm::MachineFunctionProperties
Properties which a MachineFunction may have at a given point in time.
Definition: MachineFunction.h:111
F
#define F(x, y, z)
Definition: MD5.cpp:56
INITIALIZE_PASS
INITIALIZE_PASS(FuncletLayout, DEBUG_TYPE, "Contiguously Lay Out Funclets", false, false) bool FuncletLayout
Definition: FuncletLayout.cpp:40
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
llvm::FuncletLayoutID
char & FuncletLayoutID
This pass lays out funclets contiguously.
Definition: FuncletLayout.cpp:39
Y
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
llvm::MachineFunctionProperties::set
MachineFunctionProperties & set(Property P)
Definition: MachineFunction.h:169
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::MachineFunctionProperties::Property::NoVRegs
@ NoVRegs
Passes.h
llvm::DenseMap
Definition: DenseMap.h:714
DEBUG_TYPE
#define DEBUG_TYPE
Definition: FuncletLayout.cpp:20
Analysis.h
MachineFunctionPass.h
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::find
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:150
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::empty
LLVM_NODISCARD bool empty() const
Definition: DenseMap.h:97
llvm::DenseMapBase< DenseMap< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::end
iterator end()
Definition: DenseMap.h:83
llvm::getEHScopeMembership
DenseMap< const MachineBasicBlock *, int > getEHScopeMembership(const MachineFunction &MF)
Definition: Analysis.cpp:737
MachineFunction.h
InitializePasses.h
llvm::initializeFuncletLayoutPass
void initializeFuncletLayoutPass(PassRegistry &)
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38