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