blob: c5702ce11adfc04a689a3a0bccc9f842d9ed1a82 [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
Derek Schuff9769deb2015-12-11 23:49:46 +000019#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
Dan Gohman10e730a2015-06-29 23:51:55 +000020#include "llvm/CodeGen/MachineRegisterInfo.h"
21
22namespace llvm {
23
24/// This class is derived from MachineFunctionInfo and contains private
25/// WebAssembly-specific information for each MachineFunction.
26class WebAssemblyFunctionInfo final : public MachineFunctionInfo {
27 MachineFunction &MF;
28
Dan Gohman754cd112015-11-11 01:33:02 +000029 std::vector<MVT> Params;
Dan Gohman2726b882016-10-06 22:29:32 +000030 std::vector<MVT> Results;
Dan Gohman3acb1872016-10-24 23:27:49 +000031 std::vector<MVT> Locals;
Dan Gohmane51c0582015-10-06 00:27:55 +000032
Dan Gohmancf4748f2015-11-12 17:04:33 +000033 /// A mapping from CodeGen vreg index to WebAssembly register number.
34 std::vector<unsigned> WARegs;
35
Dan Gohman1462faa2015-11-16 16:18:28 +000036 /// A mapping from CodeGen vreg index to a boolean value indicating whether
37 /// the given register is considered to be "stackified", meaning it has been
38 /// determined or made to meet the stack requirements:
39 /// - single use (per path)
40 /// - single def (per path)
Dan Gohman53d13992015-12-02 18:08:49 +000041 /// - defined and used in LIFO order with other stack registers
Dan Gohman1462faa2015-11-16 16:18:28 +000042 BitVector VRegStackified;
43
Derek Schuff27501e22016-02-10 19:51:04 +000044 // A virtual register holding the pointer to the vararg buffer for vararg
45 // functions. It is created and set in TLI::LowerFormalArguments and read by
46 // TLI::LowerVASTART
47 unsigned VarargVreg = -1U;
48
49 public:
Dan Gohman0cfb5f82016-05-10 04:24:02 +000050 explicit WebAssemblyFunctionInfo(MachineFunction &MF) : MF(MF) {}
Dan Gohman10e730a2015-06-29 23:51:55 +000051 ~WebAssemblyFunctionInfo() override;
Dan Gohmane51c0582015-10-06 00:27:55 +000052
Dan Gohman754cd112015-11-11 01:33:02 +000053 void addParam(MVT VT) { Params.push_back(VT); }
54 const std::vector<MVT> &getParams() const { return Params; }
55
Dan Gohman2726b882016-10-06 22:29:32 +000056 void addResult(MVT VT) { Results.push_back(VT); }
57 const std::vector<MVT> &getResults() const { return Results; }
58
Dan Gohman3acb1872016-10-24 23:27:49 +000059 void addLocal(MVT VT) { Locals.push_back(VT); }
60 const std::vector<MVT> &getLocals() const { return Locals; }
61
Derek Schuff27501e22016-02-10 19:51:04 +000062 unsigned getVarargBufferVreg() const {
63 assert(VarargVreg != -1U && "Vararg vreg hasn't been set");
64 return VarargVreg;
65 }
66 void setVarargBufferVreg(unsigned Reg) { VarargVreg = Reg; }
67
Dan Gohman058fce52015-11-13 00:21:05 +000068 static const unsigned UnusedReg = -1u;
69
Dan Gohman1462faa2015-11-16 16:18:28 +000070 void stackifyVReg(unsigned VReg) {
Dan Gohman4fc4e422016-10-24 19:49:43 +000071 assert(MF.getRegInfo().getUniqueVRegDef(VReg));
Dan Gohman1462faa2015-11-16 16:18:28 +000072 if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size())
73 VRegStackified.resize(TargetRegisterInfo::virtReg2Index(VReg) + 1);
74 VRegStackified.set(TargetRegisterInfo::virtReg2Index(VReg));
75 }
76 bool isVRegStackified(unsigned VReg) const {
77 if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size())
78 return false;
79 return VRegStackified.test(TargetRegisterInfo::virtReg2Index(VReg));
80 }
81
Dan Gohman058fce52015-11-13 00:21:05 +000082 void initWARegs();
Dan Gohmancf4748f2015-11-12 17:04:33 +000083 void setWAReg(unsigned VReg, unsigned WAReg) {
Dan Gohman058fce52015-11-13 00:21:05 +000084 assert(WAReg != UnusedReg);
Dan Gohman80e34e02015-11-25 21:13:02 +000085 assert(TargetRegisterInfo::virtReg2Index(VReg) < WARegs.size());
Dan Gohmancf4748f2015-11-12 17:04:33 +000086 WARegs[TargetRegisterInfo::virtReg2Index(VReg)] = WAReg;
87 }
Derek Schuff9769deb2015-12-11 23:49:46 +000088 unsigned getWAReg(unsigned Reg) const {
Dan Gohman0cfb5f82016-05-10 04:24:02 +000089 assert(TargetRegisterInfo::virtReg2Index(Reg) < WARegs.size());
90 return WARegs[TargetRegisterInfo::virtReg2Index(Reg)];
Dan Gohmancf4748f2015-11-12 17:04:33 +000091 }
Dan Gohmanb7c24002016-05-21 00:21:56 +000092
93 // For a given stackified WAReg, return the id number to print with push/pop.
94 static unsigned getWARegStackId(unsigned Reg) {
95 assert(Reg & INT32_MIN);
96 return Reg & INT32_MAX;
97 }
Dan Gohman10e730a2015-06-29 23:51:55 +000098};
99
Dan Gohman2726b882016-10-06 22:29:32 +0000100void ComputeLegalValueVTs(const Function &F, const TargetMachine &TM,
101 Type *Ty, SmallVectorImpl<MVT> &ValueVTs);
102
103void ComputeSignatureVTs(const Function &F, const TargetMachine &TM,
104 SmallVectorImpl<MVT> &Params,
105 SmallVectorImpl<MVT> &Results);
106
Dan Gohman10e730a2015-06-29 23:51:55 +0000107} // end namespace llvm
108
109#endif