[WebAssembly] Reapply r252858, with svn add for the new file.
[oota-llvm.git] / lib / Target / WebAssembly / WebAssemblyMachineFunctionInfo.h
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 "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
30   std::vector<MVT> Params;
31   std::vector<MVT> Results;
32
33   /// A mapping from CodeGen vreg index to WebAssembly register number.
34   std::vector<unsigned> WARegs;
35
36 public:
37   explicit WebAssemblyFunctionInfo(MachineFunction &MF) : MF(MF) {}
38   ~WebAssemblyFunctionInfo() override;
39
40   void addParam(MVT VT) { Params.push_back(VT); }
41   const std::vector<MVT> &getParams() const { return Params; }
42
43   void addResult(MVT VT) { Results.push_back(VT); }
44   const std::vector<MVT> &getResults() const { return Results; }
45
46   void initWARegs() {
47     assert(WARegs.empty());
48     WARegs.resize(MF.getRegInfo().getNumVirtRegs(), -1u);
49   }
50   void setWAReg(unsigned VReg, unsigned WAReg) {
51     WARegs[TargetRegisterInfo::virtReg2Index(VReg)] = WAReg;
52   }
53   unsigned getWAReg(unsigned VReg) const {
54     return WARegs[TargetRegisterInfo::virtReg2Index(VReg)];
55   }
56 };
57
58 } // end namespace llvm
59
60 #endif