blob: af4dabb2c6c301ddd57b4460a61afe8e2fb0668a [file] [log] [blame]
Nick Lewyckyc3890d22015-07-29 22:32:47 +00001// WebAssemblyMachineFunctionInfo.h-WebAssembly machine function info-*- C++ -*-
Dan Gohman10e730a2015-06-29 23:51:55 +00002//
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 declares WebAssembly-specific per-machine-function
12/// information.
13///
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYMACHINEFUNCTIONINFO_H
17#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYMACHINEFUNCTIONINFO_H
18
Dan Gohman10e730a2015-06-29 23:51:55 +000019#include "llvm/CodeGen/MachineRegisterInfo.h"
20
21namespace llvm {
22
23/// This class is derived from MachineFunctionInfo and contains private
24/// WebAssembly-specific information for each MachineFunction.
25class WebAssemblyFunctionInfo final : public MachineFunctionInfo {
26 MachineFunction &MF;
27
Dan Gohman754cd112015-11-11 01:33:02 +000028 std::vector<MVT> Params;
Dan Gohmane51c0582015-10-06 00:27:55 +000029
Dan Gohmancf4748f2015-11-12 17:04:33 +000030 /// A mapping from CodeGen vreg index to WebAssembly register number.
31 std::vector<unsigned> WARegs;
32
Dan Gohman1462faa2015-11-16 16:18:28 +000033 /// A mapping from CodeGen vreg index to a boolean value indicating whether
34 /// the given register is considered to be "stackified", meaning it has been
35 /// determined or made to meet the stack requirements:
36 /// - single use (per path)
37 /// - single def (per path)
Dan Gohman53d13992015-12-02 18:08:49 +000038 /// - defined and used in LIFO order with other stack registers
Dan Gohman1462faa2015-11-16 16:18:28 +000039 BitVector VRegStackified;
40
Dan Gohman10e730a2015-06-29 23:51:55 +000041public:
Dan Gohmancf4748f2015-11-12 17:04:33 +000042 explicit WebAssemblyFunctionInfo(MachineFunction &MF) : MF(MF) {}
Dan Gohman10e730a2015-06-29 23:51:55 +000043 ~WebAssemblyFunctionInfo() override;
Dan Gohmane51c0582015-10-06 00:27:55 +000044
Dan Gohman754cd112015-11-11 01:33:02 +000045 void addParam(MVT VT) { Params.push_back(VT); }
46 const std::vector<MVT> &getParams() const { return Params; }
47
Dan Gohman058fce52015-11-13 00:21:05 +000048 static const unsigned UnusedReg = -1u;
49
Dan Gohman1462faa2015-11-16 16:18:28 +000050 void stackifyVReg(unsigned VReg) {
51 if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size())
52 VRegStackified.resize(TargetRegisterInfo::virtReg2Index(VReg) + 1);
53 VRegStackified.set(TargetRegisterInfo::virtReg2Index(VReg));
54 }
55 bool isVRegStackified(unsigned VReg) const {
56 if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size())
57 return false;
58 return VRegStackified.test(TargetRegisterInfo::virtReg2Index(VReg));
59 }
60
Dan Gohman058fce52015-11-13 00:21:05 +000061 void initWARegs();
Dan Gohmancf4748f2015-11-12 17:04:33 +000062 void setWAReg(unsigned VReg, unsigned WAReg) {
Dan Gohman058fce52015-11-13 00:21:05 +000063 assert(WAReg != UnusedReg);
Dan Gohman80e34e02015-11-25 21:13:02 +000064 assert(TargetRegisterInfo::virtReg2Index(VReg) < WARegs.size());
Dan Gohmancf4748f2015-11-12 17:04:33 +000065 WARegs[TargetRegisterInfo::virtReg2Index(VReg)] = WAReg;
66 }
67 unsigned getWAReg(unsigned VReg) const {
Dan Gohman80e34e02015-11-25 21:13:02 +000068 assert(TargetRegisterInfo::virtReg2Index(VReg) < WARegs.size());
Dan Gohmancf4748f2015-11-12 17:04:33 +000069 return WARegs[TargetRegisterInfo::virtReg2Index(VReg)];
70 }
Dan Gohman80e34e02015-11-25 21:13:02 +000071 // If new virtual registers are created after initWARegs has been called,
72 // this function can be used to add WebAssembly register mappings for them.
73 void addWAReg(unsigned VReg, unsigned WAReg) {
74 assert(VReg = WARegs.size());
75 WARegs.push_back(WAReg);
76 }
Dan Gohman10e730a2015-06-29 23:51:55 +000077};
78
79} // end namespace llvm
80
81#endif