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 | 2726b88 | 2016-10-06 22:29:32 +0000 | [diff] [blame^] | 30 | std::vector<MVT> Results; |
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 | |
Derek Schuff | 27501e2 | 2016-02-10 19:51:04 +0000 | [diff] [blame] | 43 | // A virtual register holding the pointer to the vararg buffer for vararg |
| 44 | // functions. It is created and set in TLI::LowerFormalArguments and read by |
| 45 | // TLI::LowerVASTART |
| 46 | unsigned VarargVreg = -1U; |
| 47 | |
| 48 | public: |
Dan Gohman | 0cfb5f8 | 2016-05-10 04:24:02 +0000 | [diff] [blame] | 49 | explicit WebAssemblyFunctionInfo(MachineFunction &MF) : MF(MF) {} |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 50 | ~WebAssemblyFunctionInfo() override; |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 51 | |
Dan Gohman | 754cd11 | 2015-11-11 01:33:02 +0000 | [diff] [blame] | 52 | void addParam(MVT VT) { Params.push_back(VT); } |
| 53 | const std::vector<MVT> &getParams() const { return Params; } |
| 54 | |
Dan Gohman | 2726b88 | 2016-10-06 22:29:32 +0000 | [diff] [blame^] | 55 | void addResult(MVT VT) { Results.push_back(VT); } |
| 56 | const std::vector<MVT> &getResults() const { return Results; } |
| 57 | |
Derek Schuff | 27501e2 | 2016-02-10 19:51:04 +0000 | [diff] [blame] | 58 | unsigned getVarargBufferVreg() const { |
| 59 | assert(VarargVreg != -1U && "Vararg vreg hasn't been set"); |
| 60 | return VarargVreg; |
| 61 | } |
| 62 | void setVarargBufferVreg(unsigned Reg) { VarargVreg = Reg; } |
| 63 | |
Dan Gohman | 058fce5 | 2015-11-13 00:21:05 +0000 | [diff] [blame] | 64 | static const unsigned UnusedReg = -1u; |
| 65 | |
Dan Gohman | 1462faa | 2015-11-16 16:18:28 +0000 | [diff] [blame] | 66 | void stackifyVReg(unsigned VReg) { |
| 67 | if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size()) |
| 68 | VRegStackified.resize(TargetRegisterInfo::virtReg2Index(VReg) + 1); |
| 69 | VRegStackified.set(TargetRegisterInfo::virtReg2Index(VReg)); |
| 70 | } |
| 71 | bool isVRegStackified(unsigned VReg) const { |
| 72 | if (TargetRegisterInfo::virtReg2Index(VReg) >= VRegStackified.size()) |
| 73 | return false; |
| 74 | return VRegStackified.test(TargetRegisterInfo::virtReg2Index(VReg)); |
| 75 | } |
| 76 | |
Dan Gohman | 058fce5 | 2015-11-13 00:21:05 +0000 | [diff] [blame] | 77 | void initWARegs(); |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 78 | void setWAReg(unsigned VReg, unsigned WAReg) { |
Dan Gohman | 058fce5 | 2015-11-13 00:21:05 +0000 | [diff] [blame] | 79 | assert(WAReg != UnusedReg); |
Dan Gohman | 80e34e0 | 2015-11-25 21:13:02 +0000 | [diff] [blame] | 80 | assert(TargetRegisterInfo::virtReg2Index(VReg) < WARegs.size()); |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 81 | WARegs[TargetRegisterInfo::virtReg2Index(VReg)] = WAReg; |
| 82 | } |
Derek Schuff | 9769deb | 2015-12-11 23:49:46 +0000 | [diff] [blame] | 83 | unsigned getWAReg(unsigned Reg) const { |
Dan Gohman | 0cfb5f8 | 2016-05-10 04:24:02 +0000 | [diff] [blame] | 84 | assert(TargetRegisterInfo::virtReg2Index(Reg) < WARegs.size()); |
| 85 | return WARegs[TargetRegisterInfo::virtReg2Index(Reg)]; |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 86 | } |
Dan Gohman | b7c2400 | 2016-05-21 00:21:56 +0000 | [diff] [blame] | 87 | |
| 88 | // For a given stackified WAReg, return the id number to print with push/pop. |
| 89 | static unsigned getWARegStackId(unsigned Reg) { |
| 90 | assert(Reg & INT32_MIN); |
| 91 | return Reg & INT32_MAX; |
| 92 | } |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
Dan Gohman | 2726b88 | 2016-10-06 22:29:32 +0000 | [diff] [blame^] | 95 | void ComputeLegalValueVTs(const Function &F, const TargetMachine &TM, |
| 96 | Type *Ty, SmallVectorImpl<MVT> &ValueVTs); |
| 97 | |
| 98 | void ComputeSignatureVTs(const Function &F, const TargetMachine &TM, |
| 99 | SmallVectorImpl<MVT> &Params, |
| 100 | SmallVectorImpl<MVT> &Results); |
| 101 | |
Dan Gohman | 10e730a | 2015-06-29 23:51:55 +0000 | [diff] [blame] | 102 | } // end namespace llvm |
| 103 | |
| 104 | #endif |