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 | |
| 19 | #include "WebAssemblyRegisterInfo.h" |
| 20 | #include "llvm/CodeGen/MachineFunction.h" |
| 21 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| 22 | |
| 23 | namespace llvm { |
| 24 | |
| 25 | /// This class is derived from MachineFunctionInfo and contains private |
| 26 | /// WebAssembly-specific information for each MachineFunction. |
| 27 | class WebAssemblyFunctionInfo final : public MachineFunctionInfo { |
| 28 | MachineFunction &MF; |
| 29 | |
Dan Gohman | 754cd11 | 2015-11-11 01:33:02 +0000 | [diff] [blame] | 30 | std::vector<MVT> Params; |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 31 | |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 32 | /// A mapping from CodeGen vreg index to WebAssembly register number. |
| 33 | std::vector<unsigned> WARegs; |
| 34 | |
Dan Gohman | 1462faa | 2015-11-16 16:18:28 +0000 | [diff] [blame] | 35 | /// A mapping from CodeGen vreg index to a boolean value indicating whether |
| 36 | /// the given register is considered to be "stackified", meaning it has been |
| 37 | /// determined or made to meet the stack requirements: |
| 38 | /// - single use (per path) |
| 39 | /// - single def (per path) |
Dan Gohman | 53d1399 | 2015-12-02 18:08:49 +0000 | [diff] [blame^] | 40 | /// - defined and used in LIFO order with other stack registers |
Dan Gohman | 1462faa | 2015-11-16 16:18:28 +0000 | [diff] [blame] | 41 | BitVector VRegStackified; |
| 42 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 43 | public: |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 44 | explicit WebAssemblyFunctionInfo(MachineFunction &MF) : MF(MF) {} |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 45 | ~WebAssemblyFunctionInfo() override; |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 46 | |
Dan Gohman | 754cd11 | 2015-11-11 01:33:02 +0000 | [diff] [blame] | 47 | void addParam(MVT VT) { Params.push_back(VT); } |
| 48 | const std::vector<MVT> &getParams() const { return Params; } |
| 49 | |
Dan Gohman | 058fce5 | 2015-11-13 00:21:05 +0000 | [diff] [blame] | 50 | static const unsigned UnusedReg = -1u; |
| 51 | |
Dan Gohman | 1462faa | 2015-11-16 16:18:28 +0000 | [diff] [blame] | 52 | void stackifyVReg(unsigned VReg) { |
| 53 | if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size()) |
| 54 | VRegStackified.resize(TargetRegisterInfo::virtReg2Index(VReg) + 1); |
| 55 | VRegStackified.set(TargetRegisterInfo::virtReg2Index(VReg)); |
| 56 | } |
| 57 | bool isVRegStackified(unsigned VReg) const { |
| 58 | if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size()) |
| 59 | return false; |
| 60 | return VRegStackified.test(TargetRegisterInfo::virtReg2Index(VReg)); |
| 61 | } |
| 62 | |
Dan Gohman | 058fce5 | 2015-11-13 00:21:05 +0000 | [diff] [blame] | 63 | void initWARegs(); |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 64 | void setWAReg(unsigned VReg, unsigned WAReg) { |
Dan Gohman | 058fce5 | 2015-11-13 00:21:05 +0000 | [diff] [blame] | 65 | assert(WAReg != UnusedReg); |
Dan Gohman | 80e34e0 | 2015-11-25 21:13:02 +0000 | [diff] [blame] | 66 | assert(TargetRegisterInfo::virtReg2Index(VReg) < WARegs.size()); |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 67 | WARegs[TargetRegisterInfo::virtReg2Index(VReg)] = WAReg; |
| 68 | } |
| 69 | unsigned getWAReg(unsigned VReg) const { |
Dan Gohman | 80e34e0 | 2015-11-25 21:13:02 +0000 | [diff] [blame] | 70 | assert(TargetRegisterInfo::virtReg2Index(VReg) < WARegs.size()); |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 71 | return WARegs[TargetRegisterInfo::virtReg2Index(VReg)]; |
| 72 | } |
Dan Gohman | 80e34e0 | 2015-11-25 21:13:02 +0000 | [diff] [blame] | 73 | // If new virtual registers are created after initWARegs has been called, |
| 74 | // this function can be used to add WebAssembly register mappings for them. |
| 75 | void addWAReg(unsigned VReg, unsigned WAReg) { |
| 76 | assert(VReg = WARegs.size()); |
| 77 | WARegs.push_back(WAReg); |
| 78 | } |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | } // end namespace llvm |
| 82 | |
| 83 | #endif |