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;
|
120
|
30 std::vector<MVT> Results;
|
|
31 std::vector<MVT> Locals;
|
100
|
32
|
|
33 /// A mapping from CodeGen vreg index to WebAssembly register number.
|
|
34 std::vector<unsigned> WARegs;
|
|
35
|
|
36 /// 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)
|
|
41 /// - defined and used in LIFO order with other stack registers
|
|
42 BitVector VRegStackified;
|
|
43
|
120
|
44 // 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;
|
95
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
48
|
120
|
49 // A virtual register holding the base pointer for functions that have
|
|
50 // overaligned values on the user stack.
|
|
51 unsigned BasePtrVreg = -1U;
|
|
52
|
|
53 public:
|
|
54 explicit WebAssemblyFunctionInfo(MachineFunction &MF) : MF(MF) {}
|
95
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
55 ~WebAssemblyFunctionInfo() override;
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
56
|
100
|
57 void addParam(MVT VT) { Params.push_back(VT); }
|
|
58 const std::vector<MVT> &getParams() const { return Params; }
|
|
59
|
120
|
60 void addResult(MVT VT) { Results.push_back(VT); }
|
|
61 const std::vector<MVT> &getResults() const { return Results; }
|
|
62
|
121
|
63 void setNumLocals(size_t NumLocals) { Locals.resize(NumLocals, MVT::i32); }
|
|
64 void setLocal(size_t i, MVT VT) { Locals[i] = VT; }
|
120
|
65 void addLocal(MVT VT) { Locals.push_back(VT); }
|
|
66 const std::vector<MVT> &getLocals() const { return Locals; }
|
|
67
|
|
68 unsigned getVarargBufferVreg() const {
|
|
69 assert(VarargVreg != -1U && "Vararg vreg hasn't been set");
|
|
70 return VarargVreg;
|
|
71 }
|
|
72 void setVarargBufferVreg(unsigned Reg) { VarargVreg = Reg; }
|
|
73
|
|
74 unsigned getBasePointerVreg() const {
|
|
75 assert(BasePtrVreg != -1U && "Base ptr vreg hasn't been set");
|
|
76 return BasePtrVreg;
|
|
77 }
|
|
78 void setBasePointerVreg(unsigned Reg) { BasePtrVreg = Reg; }
|
|
79
|
100
|
80 static const unsigned UnusedReg = -1u;
|
|
81
|
|
82 void stackifyVReg(unsigned VReg) {
|
120
|
83 assert(MF.getRegInfo().getUniqueVRegDef(VReg));
|
100
|
84 if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size())
|
|
85 VRegStackified.resize(TargetRegisterInfo::virtReg2Index(VReg) + 1);
|
|
86 VRegStackified.set(TargetRegisterInfo::virtReg2Index(VReg));
|
|
87 }
|
|
88 bool isVRegStackified(unsigned VReg) const {
|
|
89 if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size())
|
|
90 return false;
|
|
91 return VRegStackified.test(TargetRegisterInfo::virtReg2Index(VReg));
|
|
92 }
|
|
93
|
|
94 void initWARegs();
|
|
95 void setWAReg(unsigned VReg, unsigned WAReg) {
|
|
96 assert(WAReg != UnusedReg);
|
|
97 assert(TargetRegisterInfo::virtReg2Index(VReg) < WARegs.size());
|
|
98 WARegs[TargetRegisterInfo::virtReg2Index(VReg)] = WAReg;
|
|
99 }
|
|
100 unsigned getWAReg(unsigned Reg) const {
|
120
|
101 assert(TargetRegisterInfo::virtReg2Index(Reg) < WARegs.size());
|
|
102 return WARegs[TargetRegisterInfo::virtReg2Index(Reg)];
|
100
|
103 }
|
|
104
|
120
|
105 // For a given stackified WAReg, return the id number to print with push/pop.
|
|
106 static unsigned getWARegStackId(unsigned Reg) {
|
|
107 assert(Reg & INT32_MIN);
|
|
108 return Reg & INT32_MAX;
|
100
|
109 }
|
95
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
110 };
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
111
|
120
|
112 void ComputeLegalValueVTs(const Function &F, const TargetMachine &TM,
|
|
113 Type *Ty, SmallVectorImpl<MVT> &ValueVTs);
|
|
114
|
|
115 void ComputeSignatureVTs(const Function &F, const TargetMachine &TM,
|
|
116 SmallVectorImpl<MVT> &Params,
|
|
117 SmallVectorImpl<MVT> &Results);
|
|
118
|
95
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
119 } // end namespace llvm
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
120
|
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff
changeset
|
121 #endif
|