annotate lib/Target/WebAssembly/WebAssemblyMachineFunctionInfo.h @ 128:c347d3398279 default tip

fix
author mir3636
date Wed, 06 Dec 2017 14:37:17 +0900
parents 803732b1fca8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 // WebAssemblyMachineFunctionInfo.h-WebAssembly machine function info-*- C++ -*-
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 //
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 //
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 //
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 ///
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 /// \file
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 /// \brief This file declares WebAssembly-specific per-machine-function
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 /// information.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 ///
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 //===----------------------------------------------------------------------===//
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 #ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYMACHINEFUNCTIONINFO_H
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 #define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLYMACHINEFUNCTIONINFO_H
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
19 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #include "llvm/CodeGen/MachineRegisterInfo.h"
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 namespace llvm {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 /// This class is derived from MachineFunctionInfo and contains private
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 /// WebAssembly-specific information for each MachineFunction.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 class WebAssemblyFunctionInfo final : public MachineFunctionInfo {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 MachineFunction &MF;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
29 std::vector<MVT> Params;
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
30 std::vector<MVT> Results;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
31 std::vector<MVT> Locals;
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
32
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
33 /// A mapping from CodeGen vreg index to WebAssembly register number.
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
34 std::vector<unsigned> WARegs;
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
35
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
36 /// A mapping from CodeGen vreg index to a boolean value indicating whether
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
37 /// the given register is considered to be "stackified", meaning it has been
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
38 /// determined or made to meet the stack requirements:
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
39 /// - single use (per path)
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
40 /// - single def (per path)
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
41 /// - defined and used in LIFO order with other stack registers
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
42 BitVector VRegStackified;
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
43
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
44 // A virtual register holding the pointer to the vararg buffer for vararg
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
45 // functions. It is created and set in TLI::LowerFormalArguments and read by
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
46 // TLI::LowerVASTART
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
47 unsigned VarargVreg = -1U;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
49 // A virtual register holding the base pointer for functions that have
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
50 // overaligned values on the user stack.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
51 unsigned BasePtrVreg = -1U;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
52
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
53 public:
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
54 explicit WebAssemblyFunctionInfo(MachineFunction &MF) : MF(MF) {}
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 ~WebAssemblyFunctionInfo() override;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
57 void addParam(MVT VT) { Params.push_back(VT); }
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
58 const std::vector<MVT> &getParams() const { return Params; }
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
59
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
60 void addResult(MVT VT) { Results.push_back(VT); }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
61 const std::vector<MVT> &getResults() const { return Results; }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
62
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
63 void setNumLocals(size_t NumLocals) { Locals.resize(NumLocals, MVT::i32); }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
64 void setLocal(size_t i, MVT VT) { Locals[i] = VT; }
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
65 void addLocal(MVT VT) { Locals.push_back(VT); }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
66 const std::vector<MVT> &getLocals() const { return Locals; }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
67
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
68 unsigned getVarargBufferVreg() const {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
69 assert(VarargVreg != -1U && "Vararg vreg hasn't been set");
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
70 return VarargVreg;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
71 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
72 void setVarargBufferVreg(unsigned Reg) { VarargVreg = Reg; }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
73
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
74 unsigned getBasePointerVreg() const {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
75 assert(BasePtrVreg != -1U && "Base ptr vreg hasn't been set");
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
76 return BasePtrVreg;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
77 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
78 void setBasePointerVreg(unsigned Reg) { BasePtrVreg = Reg; }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
79
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
80 static const unsigned UnusedReg = -1u;
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
81
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
82 void stackifyVReg(unsigned VReg) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
83 assert(MF.getRegInfo().getUniqueVRegDef(VReg));
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
84 if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size())
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
85 VRegStackified.resize(TargetRegisterInfo::virtReg2Index(VReg) + 1);
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
86 VRegStackified.set(TargetRegisterInfo::virtReg2Index(VReg));
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
87 }
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
88 bool isVRegStackified(unsigned VReg) const {
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
89 if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size())
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
90 return false;
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
91 return VRegStackified.test(TargetRegisterInfo::virtReg2Index(VReg));
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
92 }
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
93
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
94 void initWARegs();
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
95 void setWAReg(unsigned VReg, unsigned WAReg) {
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
96 assert(WAReg != UnusedReg);
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
97 assert(TargetRegisterInfo::virtReg2Index(VReg) < WARegs.size());
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
98 WARegs[TargetRegisterInfo::virtReg2Index(VReg)] = WAReg;
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
99 }
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
100 unsigned getWAReg(unsigned Reg) const {
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
101 assert(TargetRegisterInfo::virtReg2Index(Reg) < WARegs.size());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
102 return WARegs[TargetRegisterInfo::virtReg2Index(Reg)];
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
103 }
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
104
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
105 // For a given stackified WAReg, return the id number to print with push/pop.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
106 static unsigned getWARegStackId(unsigned Reg) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
107 assert(Reg & INT32_MIN);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
108 return Reg & INT32_MAX;
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
109 }
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 };
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
112 void ComputeLegalValueVTs(const Function &F, const TargetMachine &TM,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
113 Type *Ty, SmallVectorImpl<MVT> &ValueVTs);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
114
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
115 void ComputeSignatureVTs(const Function &F, const TargetMachine &TM,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
116 SmallVectorImpl<MVT> &Params,
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
117 SmallVectorImpl<MVT> &Results);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
118
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 } // end namespace llvm
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 #endif