Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/SystemZ/SystemZPostRewrite.cpp
Line
Count
Source (jump to first uncovered line)
1
//==---- SystemZPostRewrite.cpp - Select pseudos after RegAlloc ---*- 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 file contains a pass that is run immediately after VirtRegRewriter
10
// but before MachineCopyPropagation. The purpose is to lower pseudos to
11
// target instructions before any later pass might substitute a register for
12
// another.
13
//
14
//===----------------------------------------------------------------------===//
15
16
#include "SystemZ.h"
17
#include "SystemZInstrInfo.h"
18
#include "SystemZSubtarget.h"
19
#include "llvm/ADT/Statistic.h"
20
#include "llvm/CodeGen/MachineFunctionPass.h"
21
#include "llvm/CodeGen/MachineInstrBuilder.h"
22
using namespace llvm;
23
24
9.12k
#define SYSTEMZ_POSTREWRITE_NAME "SystemZ Post Rewrite pass"
25
26
#define DEBUG_TYPE "systemz-postrewrite"
27
STATISTIC(MemFoldCopies, "Number of copies inserted before folded mem ops.");
28
29
namespace llvm {
30
  void initializeSystemZPostRewritePass(PassRegistry&);
31
}
32
33
namespace {
34
35
class SystemZPostRewrite : public MachineFunctionPass {
36
public:
37
  static char ID;
38
1.01k
  SystemZPostRewrite() : MachineFunctionPass(ID) {
39
1.01k
    initializeSystemZPostRewritePass(*PassRegistry::getPassRegistry());
40
1.01k
  }
41
42
  const SystemZInstrInfo *TII;
43
44
  bool runOnMachineFunction(MachineFunction &Fn) override;
45
46
9.12k
  StringRef getPassName() const override { return SYSTEMZ_POSTREWRITE_NAME; }
47
48
1.00k
  void getAnalysisUsage(AnalysisUsage &AU) const override {
49
1.00k
    AU.setPreservesAll();
50
1.00k
    MachineFunctionPass::getAnalysisUsage(AU);
51
1.00k
  }
52
53
private:
54
  bool selectMI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
55
                MachineBasicBlock::iterator &NextMBBI);
56
  bool selectMBB(MachineBasicBlock &MBB);
57
};
58
59
char SystemZPostRewrite::ID = 0;
60
61
} // end anonymous namespace
62
63
INITIALIZE_PASS(SystemZPostRewrite, "systemz-post-rewrite",
64
                SYSTEMZ_POSTREWRITE_NAME, false, false)
65
66
/// Returns an instance of the Post Rewrite pass.
67
1.01k
FunctionPass *llvm::createSystemZPostRewritePass(SystemZTargetMachine &TM) {
68
1.01k
  return new SystemZPostRewrite();
69
1.01k
}
70
71
/// If MBBI references a pseudo instruction that should be selected here,
72
/// do it and return true.  Otherwise return false.
73
bool SystemZPostRewrite::selectMI(MachineBasicBlock &MBB,
74
                                MachineBasicBlock::iterator MBBI,
75
59.5k
                                MachineBasicBlock::iterator &NextMBBI) {
76
59.5k
  MachineInstr &MI = *MBBI;
77
59.5k
  unsigned Opcode = MI.getOpcode();
78
59.5k
79
59.5k
  // Note: If this could be done during regalloc in foldMemoryOperandImpl()
80
59.5k
  // while also updating the LiveIntervals, there would be no need for the
81
59.5k
  // MemFoldPseudo to begin with.
82
59.5k
  int TargetMemOpcode = SystemZ::getTargetMemOpcode(Opcode);
83
59.5k
  if (TargetMemOpcode != -1) {
84
21
    MI.setDesc(TII->get(TargetMemOpcode));
85
21
    MI.tieOperands(0, 1);
86
21
    unsigned DstReg = MI.getOperand(0).getReg();
87
21
    MachineOperand &SrcMO = MI.getOperand(1);
88
21
    if (DstReg != SrcMO.getReg()) {
89
0
      BuildMI(MBB, &MI, MI.getDebugLoc(), TII->get(SystemZ::COPY), DstReg)
90
0
        .addReg(SrcMO.getReg());
91
0
      SrcMO.setReg(DstReg);
92
0
      MemFoldCopies++;
93
0
    }
94
21
    return true;
95
21
  }
96
59.4k
97
59.4k
  return false;
98
59.4k
}
99
100
/// Iterate over the instructions in basic block MBB and select any
101
/// pseudo instructions.  Return true if anything was modified.
102
12.1k
bool SystemZPostRewrite::selectMBB(MachineBasicBlock &MBB) {
103
12.1k
  bool Modified = false;
104
12.1k
105
12.1k
  MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
106
71.6k
  while (MBBI != E) {
107
59.5k
    MachineBasicBlock::iterator NMBBI = std::next(MBBI);
108
59.5k
    Modified |= selectMI(MBB, MBBI, NMBBI);
109
59.5k
    MBBI = NMBBI;
110
59.5k
  }
111
12.1k
112
12.1k
  return Modified;
113
12.1k
}
114
115
8.11k
bool SystemZPostRewrite::runOnMachineFunction(MachineFunction &MF) {
116
8.11k
  TII = static_cast<const SystemZInstrInfo *>(MF.getSubtarget().getInstrInfo());
117
8.11k
118
8.11k
  bool Modified = false;
119
8.11k
  for (auto &MBB : MF)
120
12.1k
    Modified |= selectMBB(MBB);
121
8.11k
122
8.11k
  return Modified;
123
8.11k
}
124