Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/PHIEliminationUtils.cpp
Line
Count
Source
1
//===-- PHIEliminationUtils.cpp - Helper functions for PHI elimination ----===//
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
#include "PHIEliminationUtils.h"
10
#include "llvm/ADT/SmallPtrSet.h"
11
#include "llvm/CodeGen/MachineBasicBlock.h"
12
#include "llvm/CodeGen/MachineFunction.h"
13
#include "llvm/CodeGen/MachineRegisterInfo.h"
14
using namespace llvm;
15
16
// findCopyInsertPoint - Find a safe place in MBB to insert a copy from SrcReg
17
// when following the CFG edge to SuccMBB. This needs to be after any def of
18
// SrcReg, but before any subsequent point where control flow might jump out of
19
// the basic block.
20
MachineBasicBlock::iterator
21
llvm::findPHICopyInsertPoint(MachineBasicBlock* MBB, MachineBasicBlock* SuccMBB,
22
1.52M
                             unsigned SrcReg) {
23
1.52M
  // Handle the trivial case trivially.
24
1.52M
  if (MBB->empty())
25
46.1k
    return MBB->begin();
26
1.47M
27
1.47M
  // Usually, we just want to insert the copy before the first terminator
28
1.47M
  // instruction. However, for the edge going to a landing pad, we must insert
29
1.47M
  // the copy before the call/invoke instruction.
30
1.47M
  if (!SuccMBB->isEHPad())
31
1.47M
    return MBB->getFirstTerminator();
32
621
33
621
  // Discover any defs/uses in this basic block.
34
621
  SmallPtrSet<MachineInstr*, 8> DefUsesInMBB;
35
621
  MachineRegisterInfo& MRI = MBB->getParent()->getRegInfo();
36
2.74k
  for (MachineInstr &RI : MRI.reg_instructions(SrcReg)) {
37
2.74k
    if (RI.getParent() == MBB)
38
481
      DefUsesInMBB.insert(&RI);
39
2.74k
  }
40
621
41
621
  MachineBasicBlock::iterator InsertPoint;
42
621
  if (DefUsesInMBB.empty()) {
43
202
    // No defs.  Insert the copy at the start of the basic block.
44
202
    InsertPoint = MBB->begin();
45
419
  } else if (DefUsesInMBB.size() == 1) {
46
385
    // Insert the copy immediately after the def/use.
47
385
    InsertPoint = *DefUsesInMBB.begin();
48
385
    ++InsertPoint;
49
385
  } else {
50
34
    // Insert the copy immediately after the last def/use.
51
34
    InsertPoint = MBB->end();
52
301
    while (!DefUsesInMBB.count(&*--InsertPoint)) 
{}267
53
34
    ++InsertPoint;
54
34
  }
55
621
56
621
  // Make sure the copy goes after any phi nodes but before
57
621
  // any debug nodes.
58
621
  return MBB->SkipPHIsAndLabels(InsertPoint);
59
621
}