LLVM  6.0.0svn
WebAssemblyUtilities.cpp
Go to the documentation of this file.
1 //===-- WebAssemblyUtilities.cpp - WebAssembly Utility Functions ----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief This file implements several utility functions for WebAssembly.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #include "WebAssemblyUtilities.h"
19 using namespace llvm;
20 
22  switch (MI.getOpcode()) {
23  case WebAssembly::ARGUMENT_I32:
24  case WebAssembly::ARGUMENT_I64:
25  case WebAssembly::ARGUMENT_F32:
26  case WebAssembly::ARGUMENT_F64:
27  case WebAssembly::ARGUMENT_v16i8:
28  case WebAssembly::ARGUMENT_v8i16:
29  case WebAssembly::ARGUMENT_v4i32:
30  case WebAssembly::ARGUMENT_v4f32:
31  return true;
32  default:
33  return false;
34  }
35 }
36 
38  switch (MI.getOpcode()) {
39  case WebAssembly::COPY_I32:
40  case WebAssembly::COPY_I64:
41  case WebAssembly::COPY_F32:
42  case WebAssembly::COPY_F64:
43  return true;
44  default:
45  return false;
46  }
47 }
48 
50  switch (MI.getOpcode()) {
51  case WebAssembly::TEE_I32:
52  case WebAssembly::TEE_I64:
53  case WebAssembly::TEE_F32:
54  case WebAssembly::TEE_F64:
55  return true;
56  default:
57  return false;
58  }
59 }
60 
61 /// Test whether MI is a child of some other node in an expression tree.
63  const WebAssemblyFunctionInfo &MFI) {
64  if (MI.getNumOperands() == 0)
65  return false;
66  const MachineOperand &MO = MI.getOperand(0);
67  if (!MO.isReg() || MO.isImplicit() || !MO.isDef())
68  return false;
69  unsigned Reg = MO.getReg();
71  MFI.isVRegStackified(Reg);
72 }
73 
75  switch (MI.getOpcode()) {
76  case WebAssembly::CALL_INDIRECT_VOID:
77  case WebAssembly::CALL_INDIRECT_I32:
78  case WebAssembly::CALL_INDIRECT_I64:
79  case WebAssembly::CALL_INDIRECT_F32:
80  case WebAssembly::CALL_INDIRECT_F64:
81  case WebAssembly::CALL_INDIRECT_v16i8:
82  case WebAssembly::CALL_INDIRECT_v8i16:
83  case WebAssembly::CALL_INDIRECT_v4i32:
84  case WebAssembly::CALL_INDIRECT_v4f32:
85  return true;
86  default:
87  return false;
88  }
89 }
90 
92  MachineBasicBlock *Bottom = Loop->getHeader();
93  for (MachineBasicBlock *MBB : Loop->blocks())
94  if (MBB->getNumber() > Bottom->getNumber())
95  Bottom = MBB;
96  return Bottom;
97 }
MachineBasicBlock * LoopBottom(const MachineLoop *Loop)
Return the "bottom" block of a loop.
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
unsigned getReg() const
getReg - Returns the register number.
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
unsigned getNumOperands() const
Access to explicit operands of the instruction.
Definition: MachineInstr.h:294
Reg
All possible values of the reg field in the ModR/M byte.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:291
BlockT * getHeader() const
Definition: LoopInfo.h:100
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
bool isCopy(const MachineInstr &MI)
This file contains the declaration of the WebAssembly-specific utility functions. ...
bool isTee(const MachineInstr &MI)
bool isArgument(const MachineInstr &MI)
MachineOperand class - Representation of each machine instruction operand.
Representation of each machine instruction.
Definition: MachineInstr.h:60
This class is derived from MachineFunctionInfo and contains private WebAssembly-specific information ...
Represents a single loop in the control flow graph.
Definition: LoopInfo.h:439
This file declares WebAssembly-specific per-machine-function information.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
IRTranslator LLVM IR MI
bool isCallIndirect(const MachineInstr &MI)
bool isChild(const MachineInstr &MI, const WebAssemblyFunctionInfo &MFI)
Test whether MI is a child of some other node in an expression tree.
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:296
iterator_range< block_iterator > blocks() const
Definition: LoopInfo.h:156
bool isImplicit() const