Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/WebAssembly/WebAssemblyArgumentMove.cpp
Line
Count
Source
1
//===-- WebAssemblyArgumentMove.cpp - Argument instruction moving ---------===//
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
/// \file
10
/// This file moves ARGUMENT instructions after ScheduleDAG scheduling.
11
///
12
/// Arguments are really live-in registers, however, since we use virtual
13
/// registers and LLVM doesn't support live-in virtual registers, we're
14
/// currently making do with ARGUMENT instructions which are placed at the top
15
/// of the entry block. The trick is to get them to *stay* at the top of the
16
/// entry block.
17
///
18
/// The ARGUMENTS physical register keeps these instructions pinned in place
19
/// during liveness-aware CodeGen passes, however one thing which does not
20
/// respect this is the ScheduleDAG scheduler. This pass is therefore run
21
/// immediately after that.
22
///
23
/// This is all hopefully a temporary solution until we find a better solution
24
/// for describing the live-in nature of arguments.
25
///
26
//===----------------------------------------------------------------------===//
27
28
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
29
#include "WebAssembly.h"
30
#include "WebAssemblyMachineFunctionInfo.h"
31
#include "WebAssemblySubtarget.h"
32
#include "WebAssemblyUtilities.h"
33
#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
34
#include "llvm/CodeGen/MachineRegisterInfo.h"
35
#include "llvm/CodeGen/Passes.h"
36
#include "llvm/Support/Debug.h"
37
#include "llvm/Support/raw_ostream.h"
38
using namespace llvm;
39
40
#define DEBUG_TYPE "wasm-argument-move"
41
42
namespace {
43
class WebAssemblyArgumentMove final : public MachineFunctionPass {
44
public:
45
  static char ID; // Pass identification, replacement for typeid
46
427
  WebAssemblyArgumentMove() : MachineFunctionPass(ID) {}
47
48
4.45k
  StringRef getPassName() const override { return "WebAssembly Argument Move"; }
49
50
427
  void getAnalysisUsage(AnalysisUsage &AU) const override {
51
427
    AU.setPreservesCFG();
52
427
    AU.addPreserved<MachineBlockFrequencyInfo>();
53
427
    AU.addPreservedID(MachineDominatorsID);
54
427
    MachineFunctionPass::getAnalysisUsage(AU);
55
427
  }
56
57
  bool runOnMachineFunction(MachineFunction &MF) override;
58
};
59
} // end anonymous namespace
60
61
char WebAssemblyArgumentMove::ID = 0;
62
INITIALIZE_PASS(WebAssemblyArgumentMove, DEBUG_TYPE,
63
                "Move ARGUMENT instructions for WebAssembly", false, false)
64
65
426
FunctionPass *llvm::createWebAssemblyArgumentMove() {
66
426
  return new WebAssemblyArgumentMove();
67
426
}
68
69
4.45k
bool WebAssemblyArgumentMove::runOnMachineFunction(MachineFunction &MF) {
70
4.45k
  LLVM_DEBUG({
71
4.45k
    dbgs() << "********** Argument Move **********\n"
72
4.45k
           << "********** Function: " << MF.getName() << '\n';
73
4.45k
  });
74
4.45k
75
4.45k
  bool Changed = false;
76
4.45k
  MachineBasicBlock &EntryMBB = MF.front();
77
4.45k
  MachineBasicBlock::iterator InsertPt = EntryMBB.end();
78
4.45k
79
4.45k
  // Look for the first NonArg instruction.
80
10.0k
  for (MachineInstr &MI : EntryMBB) {
81
10.0k
    if (!WebAssembly::isArgument(MI.getOpcode())) {
82
4.44k
      InsertPt = MI;
83
4.44k
      break;
84
4.44k
    }
85
10.0k
  }
86
4.45k
87
4.45k
  // Now move any argument instructions later in the block
88
4.45k
  // to before our first NonArg instruction.
89
120k
  for (MachineInstr &MI : llvm::make_range(InsertPt, EntryMBB.end())) {
90
120k
    if (WebAssembly::isArgument(MI.getOpcode())) {
91
5.41k
      EntryMBB.insert(InsertPt, MI.removeFromParent());
92
5.41k
      Changed = true;
93
5.41k
    }
94
120k
  }
95
4.45k
96
4.45k
  return Changed;
97
4.45k
}