Nick Lewycky | c3890d2 | 2015-07-29 22:32:47 +0000 | [diff] [blame] | 1 | // WebAssemblyMachineFunctionInfo.h-WebAssembly machine function info-*- C++ -*- |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 2 | // |
| 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 Schuff | 9769deb | 2015-12-11 23:49:46 +0000 | [diff] [blame] | 19 | #include "MCTargetDesc/WebAssemblyMCTargetDesc.h" |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 21 | |
| 22 | namespace llvm { |
| 23 | |
| 24 | /// This class is derived from MachineFunctionInfo and contains private |
| 25 | /// WebAssembly-specific information for each MachineFunction. |
| 26 | class WebAssemblyFunctionInfo final : public MachineFunctionInfo { |
| 27 | MachineFunction &MF; |
| 28 | |
Dan Gohman | 754cd11 | 2015-11-11 01:33:02 +0000 | [diff] [blame] | 29 | std::vector<MVT> Params; |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 30 | |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 31 | /// A mapping from CodeGen vreg index to WebAssembly register number. |
| 32 | std::vector<unsigned> WARegs; |
| 33 | |
Dan Gohman | 1462faa | 2015-11-16 16:18:28 +0000 | [diff] [blame] | 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) |
Dan Gohman | 53d1399 | 2015-12-02 18:08:49 +0000 | [diff] [blame] | 39 | /// - defined and used in LIFO order with other stack registers |
Dan Gohman | 1462faa | 2015-11-16 16:18:28 +0000 | [diff] [blame] | 40 | BitVector VRegStackified; |
| 41 | |
Derek Schuff | 27501e2 | 2016-02-10 19:51:04 +0000 | [diff] [blame] | 42 | // A virtual register holding the pointer to the vararg buffer for vararg |
| 43 | // functions. It is created and set in TLI::LowerFormalArguments and read by |
| 44 | // TLI::LowerVASTART |
| 45 | unsigned VarargVreg = -1U; |
| 46 | |
| 47 | public: |
Dan Gohman | 0cfb5f8 | 2016-05-10 04:24:02 +0000 | [diff] [blame] | 48 | explicit WebAssemblyFunctionInfo(MachineFunction &MF) : MF(MF) {} |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 49 | ~WebAssemblyFunctionInfo() override; |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 50 | |
Dan Gohman | 754cd11 | 2015-11-11 01:33:02 +0000 | [diff] [blame] | 51 | void addParam(MVT VT) { Params.push_back(VT); } |
| 52 | const std::vector<MVT> &getParams() const { return Params; } |
| 53 | |
Derek Schuff | 27501e2 | 2016-02-10 19:51:04 +0000 | [diff] [blame] | 54 | unsigned getVarargBufferVreg() const { |
| 55 | assert(VarargVreg != -1U && "Vararg vreg hasn't been set"); |
| 56 | return VarargVreg; |
| 57 | } |
| 58 | void setVarargBufferVreg(unsigned Reg) { VarargVreg = Reg; } |
| 59 | |
Dan Gohman | 058fce5 | 2015-11-13 00:21:05 +0000 | [diff] [blame] | 60 | static const unsigned UnusedReg = -1u; |
| 61 | |
Dan Gohman | 1462faa | 2015-11-16 16:18:28 +0000 | [diff] [blame] | 62 | void stackifyVReg(unsigned VReg) { |
| 63 | if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size()) |
| 64 | VRegStackified.resize(TargetRegisterInfo::virtReg2Index(VReg) + 1); |
| 65 | VRegStackified.set(TargetRegisterInfo::virtReg2Index(VReg)); |
| 66 | } |
| 67 | bool isVRegStackified(unsigned VReg) const { |
| 68 | if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size()) |
| 69 | return false; |
| 70 | return VRegStackified.test(TargetRegisterInfo::virtReg2Index(VReg)); |
| 71 | } |
| 72 | |
Dan Gohman | 058fce5 | 2015-11-13 00:21:05 +0000 | [diff] [blame] | 73 | void initWARegs(); |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 74 | void setWAReg(unsigned VReg, unsigned WAReg) { |
Dan Gohman | 058fce5 | 2015-11-13 00:21:05 +0000 | [diff] [blame] | 75 | assert(WAReg != UnusedReg); |
Dan Gohman | 80e34e0 | 2015-11-25 21:13:02 +0000 | [diff] [blame] | 76 | assert(TargetRegisterInfo::virtReg2Index(VReg) < WARegs.size()); |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 77 | WARegs[TargetRegisterInfo::virtReg2Index(VReg)] = WAReg; |
| 78 | } |
Derek Schuff | 9769deb | 2015-12-11 23:49:46 +0000 | [diff] [blame] | 79 | unsigned getWAReg(unsigned Reg) const { |
Dan Gohman | 0cfb5f8 | 2016-05-10 04:24:02 +0000 | [diff] [blame] | 80 | assert(TargetRegisterInfo::virtReg2Index(Reg) < WARegs.size()); |
| 81 | return WARegs[TargetRegisterInfo::virtReg2Index(Reg)]; |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 82 | } |
Dan Gohman | 80e34e0 | 2015-11-25 21:13:02 +0000 | [diff] [blame] | 83 | // If new virtual registers are created after initWARegs has been called, |
| 84 | // this function can be used to add WebAssembly register mappings for them. |
| 85 | void addWAReg(unsigned VReg, unsigned WAReg) { |
| 86 | assert(VReg = WARegs.size()); |
| 87 | WARegs.push_back(WAReg); |
| 88 | } |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | } // end namespace llvm |
| 92 | |
| 93 | #endif |