Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- WebAssemblyUtilities.cpp - WebAssembly Utility Functions ----------===//
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 implements several utility functions for WebAssembly.
11
///
12
//===----------------------------------------------------------------------===//
13
14
#include "WebAssemblyUtilities.h"
15
#include "WebAssemblyMachineFunctionInfo.h"
16
#include "llvm/CodeGen/MachineInstr.h"
17
#include "llvm/CodeGen/MachineLoopInfo.h"
18
using namespace llvm;
19
20
const char *const WebAssembly::ClangCallTerminateFn = "__clang_call_terminate";
21
const char *const WebAssembly::CxaBeginCatchFn = "__cxa_begin_catch";
22
const char *const WebAssembly::CxaRethrowFn = "__cxa_rethrow";
23
const char *const WebAssembly::StdTerminateFn = "_ZSt9terminatev";
24
const char *const WebAssembly::PersonalityWrapperFn =
25
    "_Unwind_Wasm_CallPersonality";
26
27
/// Test whether MI is a child of some other node in an expression tree.
28
bool WebAssembly::isChild(const MachineInstr &MI,
29
962
                          const WebAssemblyFunctionInfo &MFI) {
30
962
  if (MI.getNumOperands() == 0)
31
0
    return false;
32
962
  const MachineOperand &MO = MI.getOperand(0);
33
962
  if (!MO.isReg() || 
MO.isImplicit()655
||
!MO.isDef()648
)
34
314
    return false;
35
648
  unsigned Reg = MO.getReg();
36
648
  return TargetRegisterInfo::isVirtualRegister(Reg) &&
37
648
         MFI.isVRegStackified(Reg);
38
648
}
39
40
440
bool WebAssembly::mayThrow(const MachineInstr &MI) {
41
440
  switch (MI.getOpcode()) {
42
440
  case WebAssembly::THROW:
43
11
  case WebAssembly::THROW_S:
44
11
  case WebAssembly::RETHROW:
45
11
  case WebAssembly::RETHROW_S:
46
11
    return true;
47
429
  }
48
429
  if (isCallIndirect(MI.getOpcode()))
49
0
    return true;
50
429
  if (!MI.isCall())
51
347
    return false;
52
82
53
82
  const MachineOperand &MO = MI.getOperand(getCalleeOpNo(MI.getOpcode()));
54
82
  assert(MO.isGlobal());
55
82
  const auto *F = dyn_cast<Function>(MO.getGlobal());
56
82
  if (!F)
57
0
    return true;
58
82
  if (F->doesNotThrow())
59
3
    return false;
60
79
  // These functions never throw
61
79
  if (F->getName() == CxaBeginCatchFn || 
F->getName() == PersonalityWrapperFn78
||
62
79
      
F->getName() == ClangCallTerminateFn78
||
F->getName() == StdTerminateFn78
)
63
1
    return false;
64
78
65
78
  // TODO Can we exclude call instructions that are marked as 'nounwind' in the
66
78
  // original LLVm IR? (Even when the callee may throw)
67
78
  return true;
68
78
}