95
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
1 // WebAssemblyMachineFunctionInfo.h-WebAssembly machine function info-*- C++ -*-
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
2 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
3 // The LLVM Compiler Infrastructure
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
4 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
5 // This file is distributed under the University of Illinois Open Source
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
6 // License. See LICENSE.TXT for details.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
7 //
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
8 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
9 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
10 /// \file
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
11 /// \brief This file declares WebAssembly-specific per-machine-function
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
12 /// information.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
13 ///
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
14 //===----------------------------------------------------------------------===//
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
15
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
16 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYMACHINEFUNCTIONINFO_H
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
17 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYMACHINEFUNCTIONINFO_H
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
18
|
100
|
19 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
|
95
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
20 #include "llvm/CodeGen/MachineRegisterInfo.h"
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
21
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
22 namespace llvm {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
23
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
24 /// This class is derived from MachineFunctionInfo and contains private
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
25 /// WebAssembly-specific information for each MachineFunction.
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
26 class WebAssemblyFunctionInfo final : public MachineFunctionInfo {
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
27 MachineFunction &MF;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
28
|
100
|
29 std::vector<MVT> Params;
|
|
30
|
|
31 /// A mapping from CodeGen vreg index to WebAssembly register number.
|
|
32 std::vector<unsigned> WARegs;
|
|
33
|
|
34 /// A mapping from CodeGen vreg index to a boolean value indicating whether
|
|
35 /// the given register is considered to be "stackified", meaning it has been
|
|
36 /// determined or made to meet the stack requirements:
|
|
37 /// - single use (per path)
|
|
38 /// - single def (per path)
|
|
39 /// - defined and used in LIFO order with other stack registers
|
|
40 BitVector VRegStackified;
|
|
41
|
|
42 // One entry for each possible target reg. we expect it to be small.
|
|
43 std::vector<unsigned> PhysRegs;
|
95
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
44
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
45 public:
|
100
|
46 explicit WebAssemblyFunctionInfo(MachineFunction &MF) : MF(MF) {
|
|
47 PhysRegs.resize(WebAssembly::NUM_TARGET_REGS, -1U);
|
|
48 }
|
95
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
49 ~WebAssemblyFunctionInfo() override;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
50
|
100
|
51 void addParam(MVT VT) { Params.push_back(VT); }
|
|
52 const std::vector<MVT> &getParams() const { return Params; }
|
|
53
|
|
54 static const unsigned UnusedReg = -1u;
|
|
55
|
|
56 void stackifyVReg(unsigned VReg) {
|
|
57 if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size())
|
|
58 VRegStackified.resize(TargetRegisterInfo::virtReg2Index(VReg) + 1);
|
|
59 VRegStackified.set(TargetRegisterInfo::virtReg2Index(VReg));
|
|
60 }
|
|
61 void unstackifyVReg(unsigned VReg) {
|
|
62 if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size())
|
|
63 return;
|
|
64 VRegStackified.reset(TargetRegisterInfo::virtReg2Index(VReg));
|
|
65 }
|
|
66 bool isVRegStackified(unsigned VReg) const {
|
|
67 if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size())
|
|
68 return false;
|
|
69 return VRegStackified.test(TargetRegisterInfo::virtReg2Index(VReg));
|
|
70 }
|
|
71
|
|
72 void initWARegs();
|
|
73 void setWAReg(unsigned VReg, unsigned WAReg) {
|
|
74 assert(WAReg != UnusedReg);
|
|
75 assert(TargetRegisterInfo::virtReg2Index(VReg) < WARegs.size());
|
|
76 WARegs[TargetRegisterInfo::virtReg2Index(VReg)] = WAReg;
|
|
77 }
|
|
78 unsigned getWAReg(unsigned Reg) const {
|
|
79 if (TargetRegisterInfo::isVirtualRegister(Reg)) {
|
|
80 assert(TargetRegisterInfo::virtReg2Index(Reg) < WARegs.size());
|
|
81 return WARegs[TargetRegisterInfo::virtReg2Index(Reg)];
|
|
82 }
|
|
83 return PhysRegs[Reg];
|
|
84 }
|
|
85 // If new virtual registers are created after initWARegs has been called,
|
|
86 // this function can be used to add WebAssembly register mappings for them.
|
|
87 void addWAReg(unsigned VReg, unsigned WAReg) {
|
|
88 assert(VReg = WARegs.size());
|
|
89 WARegs.push_back(WAReg);
|
|
90 }
|
|
91
|
|
92 void addPReg(unsigned PReg, unsigned WAReg) {
|
|
93 assert(PReg < WebAssembly::NUM_TARGET_REGS);
|
|
94 assert(WAReg < -1U);
|
|
95 PhysRegs[PReg] = WAReg;
|
|
96 }
|
|
97 const std::vector<unsigned> &getPhysRegs() const { return PhysRegs; }
|
95
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
98 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
99
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
100 } // end namespace llvm
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
101
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
102 #endif
|