Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/FuncletLayout.cpp
Line
Count
Source
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"
14
#include "llvm/CodeGen/MachineFunction.h"
15
#include "llvm/CodeGen/MachineFunctionPass.h"
16
#include "llvm/CodeGen/Passes.h"
17
using namespace llvm;
18
19
#define DEBUG_TYPE "funclet-layout"
20
21
namespace {
22
class FuncletLayout : public MachineFunctionPass {
23
public:
24
  static char ID; // Pass identification, replacement for typeid
25
32.9k
  FuncletLayout() : MachineFunctionPass(ID) {
26
32.9k
    initializeFuncletLayoutPass(*PassRegistry::getPassRegistry());
27
32.9k
  }
28
29
  bool runOnMachineFunction(MachineFunction &F) override;
30
32.6k
  MachineFunctionProperties getRequiredProperties() const override {
31
32.6k
    return MachineFunctionProperties().set(
32
32.6k
        MachineFunctionProperties::Property::NoVRegs);
33
32.6k
  }
34
};
35
}
36
37
char FuncletLayout::ID = 0;
38
char &llvm::FuncletLayoutID = FuncletLayout::ID;
39
INITIALIZE_PASS(FuncletLayout, DEBUG_TYPE,
40
                "Contiguously Lay Out Funclets", false, false)
41
42
464k
bool FuncletLayout::runOnMachineFunction(MachineFunction &F) {
43
464k
  // Even though this gets information from getEHScopeMembership(), this pass is
44
464k
  // only necessary for funclet-based EH personalities, in which these EH scopes
45
464k
  // are outlined at the end.
46
464k
  DenseMap<const MachineBasicBlock *, int> FuncletMembership =
47
464k
      getEHScopeMembership(F);
48
464k
  if (FuncletMembership.empty())
49
464k
    return false;
50
78
51
564
  
F.sort([&](MachineBasicBlock &X, MachineBasicBlock &Y) 78
{
52
564
    auto FuncletX = FuncletMembership.find(&X);
53
564
    auto FuncletY = FuncletMembership.find(&Y);
54
564
    assert(FuncletX != FuncletMembership.end());
55
564
    assert(FuncletY != FuncletMembership.end());
56
564
    return FuncletX->second < FuncletY->second;
57
564
  });
58
78
59
78
  // Conservatively assume we changed something.
60
78
  return true;
61
78
}