Added a size field to the stack map record to handle subregister spills.
[oota-llvm.git] / include / llvm / CodeGen / StackMaps.h
1 //===------------------- StackMaps.h - StackMaps ----------------*- 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 #ifndef LLVM_STACKMAPS
11 #define LLVM_STACKMAPS
12
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/CodeGen/MachineInstr.h"
15 #include <map>
16 #include <vector>
17
18 namespace llvm {
19
20 class AsmPrinter;
21 class MCExpr;
22
23 class StackMaps {
24 public:
25   struct Location {
26     enum LocationType { Unprocessed, Register, Direct, Indirect, Constant,
27                         ConstantIndex };
28     LocationType LocType;
29     unsigned Size;
30     unsigned Reg;
31     int64_t Offset;
32     Location() : LocType(Unprocessed), Size(0), Reg(0), Offset(0) {}
33     Location(LocationType LocType, unsigned Size, unsigned Reg, int64_t Offset)
34       : LocType(LocType), Size(Size), Reg(Reg), Offset(Offset) {}
35   };
36
37   // Typedef a function pointer for functions that parse sequences of operands
38   // and return a Location, plus a new "next" operand iterator.
39   typedef std::pair<Location, MachineInstr::const_mop_iterator>
40     (*OperandParser)(MachineInstr::const_mop_iterator,
41                      MachineInstr::const_mop_iterator, const TargetMachine&);
42
43   // OpTypes are used to encode information about the following logical
44   // operand (which may consist of several MachineOperands) for the
45   // OpParser.
46   typedef enum { DirectMemRefOp, IndirectMemRefOp, ConstantOp } OpType;
47
48   StackMaps(AsmPrinter &AP, OperandParser OpParser)
49     : AP(AP), OpParser(OpParser) {}
50
51   /// This should be called by the MC lowering code _immediately_ before
52   /// lowering the MI to an MCInst. It records where the operands for the
53   /// instruction are stored, and outputs a label to record the offset of
54   /// the call from the start of the text section. In special cases (e.g. AnyReg
55   /// calling convention) the return register is also recorded if requested.
56   void recordStackMap(const MachineInstr &MI, uint32_t ID,
57                       MachineInstr::const_mop_iterator MOI,
58                       MachineInstr::const_mop_iterator MOE,
59                       bool recordResult = false);
60
61   /// If there is any stack map data, create a stack map section and serialize
62   /// the map info into it. This clears the stack map data structures
63   /// afterwards.
64   void serializeToStackMapSection();
65
66 private:
67
68   typedef SmallVector<Location, 8> LocationVec;
69
70   struct CallsiteInfo {
71     const MCExpr *CSOffsetExpr;
72     unsigned ID;
73     LocationVec Locations;
74     CallsiteInfo() : CSOffsetExpr(0), ID(0) {}
75     CallsiteInfo(const MCExpr *CSOffsetExpr, unsigned ID,
76                  LocationVec Locations)
77       : CSOffsetExpr(CSOffsetExpr), ID(ID), Locations(Locations) {}
78   };
79
80   typedef std::vector<CallsiteInfo> CallsiteInfoList;
81
82   struct ConstantPool {
83   private:
84     typedef std::map<int64_t, size_t> ConstantsMap;
85     std::vector<int64_t> ConstantsList;
86     ConstantsMap ConstantIndexes;
87
88   public:
89     size_t getNumConstants() const { return ConstantsList.size(); }
90     int64_t getConstant(size_t Idx) const { return ConstantsList[Idx]; }
91     size_t getConstantIndex(int64_t ConstVal) {
92       size_t NextIdx = ConstantsList.size();
93       ConstantsMap::const_iterator I =
94         ConstantIndexes.insert(ConstantIndexes.end(),
95                                std::make_pair(ConstVal, NextIdx));
96       if (I->second == NextIdx)
97         ConstantsList.push_back(ConstVal);
98       return I->second;
99     }
100   };
101
102   AsmPrinter &AP;
103   OperandParser OpParser;
104   CallsiteInfoList CSInfos;
105   ConstantPool ConstPool;
106 };
107
108 }
109
110 #endif // LLVM_STACKMAPS