Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/FinalizeISel.cpp
Line
Count
Source
1
//===-- llvm/CodeGen/FinalizeISel.cpp ---------------------------*- C++ -*-===//
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 pass expands Pseudo-instructions produced by ISel, fixes register
10
/// reservations and may do machine frame information adjustments.
11
/// The pseudo instructions are used to allow the expansion to contain control
12
/// flow, such as a conditional move implemented with a conditional branch and a
13
/// phi, or an atomic operation implemented with a loop.
14
//
15
//===----------------------------------------------------------------------===//
16
17
#include "llvm/CodeGen/MachineFunction.h"
18
#include "llvm/CodeGen/MachineFunctionPass.h"
19
#include "llvm/CodeGen/Passes.h"
20
#include "llvm/CodeGen/TargetLowering.h"
21
#include "llvm/CodeGen/TargetSubtargetInfo.h"
22
#include "llvm/Support/Debug.h"
23
using namespace llvm;
24
25
#define DEBUG_TYPE "finalize-isel"
26
27
namespace {
28
  class FinalizeISel : public MachineFunctionPass {
29
  public:
30
    static char ID; // Pass identification, replacement for typeid
31
36.3k
    FinalizeISel() : MachineFunctionPass(ID) {}
32
33
  private:
34
    bool runOnMachineFunction(MachineFunction &MF) override;
35
36
36.0k
    void getAnalysisUsage(AnalysisUsage &AU) const override {
37
36.0k
      MachineFunctionPass::getAnalysisUsage(AU);
38
36.0k
    }
39
  };
40
} // end anonymous namespace
41
42
char FinalizeISel::ID = 0;
43
char &llvm::FinalizeISelID = FinalizeISel::ID;
44
INITIALIZE_PASS(FinalizeISel, DEBUG_TYPE,
45
                "Finalize ISel and expand pseudo-instructions", false, false)
46
47
498k
bool FinalizeISel::runOnMachineFunction(MachineFunction &MF) {
48
498k
  bool Changed = false;
49
498k
  const TargetLowering *TLI = MF.getSubtarget().getTargetLowering();
50
498k
51
498k
  // Iterate through each instruction in the function, looking for pseudos.
52
3.12M
  for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; 
++I2.62M
) {
53
2.62M
    MachineBasicBlock *MBB = &*I;
54
2.62M
    for (MachineBasicBlock::iterator MBBI = MBB->begin(), MBBE = MBB->end();
55
27.8M
         MBBI != MBBE; ) {
56
25.2M
      MachineInstr &MI = *MBBI++;
57
25.2M
58
25.2M
      // If MI is a pseudo, expand it.
59
25.2M
      if (MI.usesCustomInsertionHook()) {
60
32.2k
        Changed = true;
61
32.2k
        MachineBasicBlock *NewMBB = TLI->EmitInstrWithCustomInserter(MI, MBB);
62
32.2k
        // The expansion may involve new basic blocks.
63
32.2k
        if (NewMBB != MBB) {
64
5.67k
          MBB = NewMBB;
65
5.67k
          I = NewMBB->getIterator();
66
5.67k
          MBBI = NewMBB->begin();
67
5.67k
          MBBE = NewMBB->end();
68
5.67k
        }
69
32.2k
      }
70
25.2M
    }
71
2.62M
  }
72
498k
73
498k
  TLI->finalizeLowering(MF);
74
498k
75
498k
  return Changed;
76
498k
}