Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/CodeGen/MachineFunctionPass.cpp
Line
Count
Source
1
//===-- MachineFunctionPass.cpp -------------------------------------------===//
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 the definitions of the MachineFunctionPass members.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#include "llvm/CodeGen/MachineFunctionPass.h"
14
#include "llvm/Analysis/AliasAnalysis.h"
15
#include "llvm/Analysis/BasicAliasAnalysis.h"
16
#include "llvm/Analysis/DominanceFrontier.h"
17
#include "llvm/Analysis/GlobalsModRef.h"
18
#include "llvm/Analysis/IVUsers.h"
19
#include "llvm/Analysis/LoopInfo.h"
20
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
21
#include "llvm/Analysis/ScalarEvolution.h"
22
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
23
#include "llvm/CodeGen/MachineFunction.h"
24
#include "llvm/CodeGen/MachineModuleInfo.h"
25
#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
26
#include "llvm/CodeGen/Passes.h"
27
#include "llvm/IR/Dominators.h"
28
#include "llvm/IR/Function.h"
29
30
using namespace llvm;
31
using namespace ore;
32
33
Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O,
34
289
                                             const std::string &Banner) const {
35
289
  return createMachineFunctionPrinterPass(O, Banner);
36
289
}
37
38
52.2M
bool MachineFunctionPass::runOnFunction(Function &F) {
39
52.2M
  // Do not codegen any 'available_externally' functions at all, they have
40
52.2M
  // definitions outside the translation unit.
41
52.2M
  if (F.hasAvailableExternallyLinkage())
42
2.16k
    return false;
43
52.2M
44
52.2M
  MachineModuleInfo &MMI = getAnalysis<MachineModuleInfo>();
45
52.2M
  MachineFunction &MF = MMI.getOrCreateMachineFunction(F);
46
52.2M
47
52.2M
  MachineFunctionProperties &MFProps = MF.getProperties();
48
52.2M
49
#ifndef NDEBUG
50
  if (!MFProps.verifyRequiredProperties(RequiredProperties)) {
51
    errs() << "MachineFunctionProperties required by " << getPassName()
52
           << " pass are not met by function " << F.getName() << ".\n"
53
           << "Required properties: ";
54
    RequiredProperties.print(errs());
55
    errs() << "\nCurrent properties: ";
56
    MFProps.print(errs());
57
    errs() << "\n";
58
    llvm_unreachable("MachineFunctionProperties check failed");
59
  }
60
#endif
61
  // Collect the MI count of the function before the pass.
62
52.2M
  unsigned CountBefore, CountAfter;
63
52.2M
64
52.2M
  // Check if the user asked for size remarks.
65
52.2M
  bool ShouldEmitSizeRemarks =
66
52.2M
      F.getParent()->shouldEmitInstrCountChangedRemark();
67
52.2M
68
52.2M
  // If we want size remarks, collect the number of MachineInstrs in our
69
52.2M
  // MachineFunction before the pass runs.
70
52.2M
  if (ShouldEmitSizeRemarks)
71
110
    CountBefore = MF.getInstructionCount();
72
52.2M
73
52.2M
  bool RV = runOnMachineFunction(MF);
74
52.2M
75
52.2M
  if (ShouldEmitSizeRemarks) {
76
110
    // We wanted size remarks. Check if there was a change to the number of
77
110
    // MachineInstrs in the module. Emit a remark if there was a change.
78
110
    CountAfter = MF.getInstructionCount();
79
110
    if (CountBefore != CountAfter) {
80
3
      MachineOptimizationRemarkEmitter MORE(MF, nullptr);
81
3
      MORE.emit([&]() {
82
3
        int64_t Delta = static_cast<int64_t>(CountAfter) -
83
3
                        static_cast<int64_t>(CountBefore);
84
3
        MachineOptimizationRemarkAnalysis R("size-info", "FunctionMISizeChange",
85
3
                                            MF.getFunction().getSubprogram(),
86
3
                                            &MF.front());
87
3
        R << NV("Pass", getPassName())
88
3
          << ": Function: " << NV("Function", F.getName()) << ": "
89
3
          << "MI Instruction count changed from "
90
3
          << NV("MIInstrsBefore", CountBefore) << " to "
91
3
          << NV("MIInstrsAfter", CountAfter)
92
3
          << "; Delta: " << NV("Delta", Delta);
93
3
        return R;
94
3
      });
95
3
    }
96
110
  }
97
52.2M
98
52.2M
  MFProps.set(SetProperties);
99
52.2M
  MFProps.reset(ClearedProperties);
100
52.2M
  return RV;
101
52.2M
}
102
103
3.66M
void MachineFunctionPass::getAnalysisUsage(AnalysisUsage &AU) const {
104
3.66M
  AU.addRequired<MachineModuleInfo>();
105
3.66M
  AU.addPreserved<MachineModuleInfo>();
106
3.66M
107
3.66M
  // MachineFunctionPass preserves all LLVM IR passes, but there's no
108
3.66M
  // high-level way to express this. Instead, just list a bunch of
109
3.66M
  // passes explicitly. This does not include setPreservesCFG,
110
3.66M
  // because CodeGen overloads that to mean preserving the MachineBasicBlock
111
3.66M
  // CFG in addition to the LLVM IR CFG.
112
3.66M
  AU.addPreserved<BasicAAWrapperPass>();
113
3.66M
  AU.addPreserved<DominanceFrontierWrapperPass>();
114
3.66M
  AU.addPreserved<DominatorTreeWrapperPass>();
115
3.66M
  AU.addPreserved<AAResultsWrapperPass>();
116
3.66M
  AU.addPreserved<GlobalsAAWrapperPass>();
117
3.66M
  AU.addPreserved<IVUsersWrapperPass>();
118
3.66M
  AU.addPreserved<LoopInfoWrapperPass>();
119
3.66M
  AU.addPreserved<MemoryDependenceWrapperPass>();
120
3.66M
  AU.addPreserved<ScalarEvolutionWrapperPass>();
121
3.66M
  AU.addPreserved<SCEVAAWrapperPass>();
122
3.66M
123
3.66M
  FunctionPass::getAnalysisUsage(AU);
124
3.66M
}