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; |
| 31 | std::vector<MVT> Results; |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 32 | |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 33 | /// A mapping from CodeGen vreg index to WebAssembly register number. |
| 34 | std::vector<unsigned> WARegs; |
| 35 | |
Dan Gohman | 1462faa | 2015-11-16 16:18:28 +0000 | [diff] [blame^] | 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 FIFO order with other stack registers |
| 42 | BitVector VRegStackified; |
| 43 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 44 | public: |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 45 | explicit WebAssemblyFunctionInfo(MachineFunction &MF) : MF(MF) {} |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 46 | ~WebAssemblyFunctionInfo() override; |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 47 | |
Dan Gohman | 754cd11 | 2015-11-11 01:33:02 +0000 | [diff] [blame] | 48 | void addParam(MVT VT) { Params.push_back(VT); } |
| 49 | const std::vector<MVT> &getParams() const { return Params; } |
| 50 | |
| 51 | void addResult(MVT VT) { Results.push_back(VT); } |
| 52 | const std::vector<MVT> &getResults() const { return Results; } |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 53 | |
Dan Gohman | 058fce5 | 2015-11-13 00:21:05 +0000 | [diff] [blame] | 54 | static const unsigned UnusedReg = -1u; |
| 55 | |
Dan Gohman | 1462faa | 2015-11-16 16:18:28 +0000 | [diff] [blame^] | 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 | bool isVRegStackified(unsigned VReg) const { |
| 62 | if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size()) |
| 63 | return false; |
| 64 | return VRegStackified.test(TargetRegisterInfo::virtReg2Index(VReg)); |
| 65 | } |
| 66 | |
Dan Gohman | 058fce5 | 2015-11-13 00:21:05 +0000 | [diff] [blame] | 67 | void initWARegs(); |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 68 | void setWAReg(unsigned VReg, unsigned WAReg) { |
Dan Gohman | 058fce5 | 2015-11-13 00:21:05 +0000 | [diff] [blame] | 69 | assert(WAReg != UnusedReg); |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 70 | WARegs[TargetRegisterInfo::virtReg2Index(VReg)] = WAReg; |
| 71 | } |
| 72 | unsigned getWAReg(unsigned VReg) const { |
| 73 | return WARegs[TargetRegisterInfo::virtReg2Index(VReg)]; |
| 74 | } |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | } // end namespace llvm |
| 78 | |
| 79 | #endif |