1 //===------------------- StackMaps.h - StackMaps ----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_STACKMAPS
11 #define LLVM_STACKMAPS
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/CodeGen/MachineInstr.h"
26 enum LocationType { Unprocessed, Register, Direct, Indirect, Constant,
31 Location() : LocType(Unprocessed), Reg(0), Offset(0) {}
32 Location(LocationType LocType, unsigned Reg, int64_t Offset)
33 : LocType(LocType), Reg(Reg), Offset(Offset) {}
36 // Typedef a function pointer for functions that parse sequences of operands
37 // and return a Location, plus a new "next" operand iterator.
38 typedef std::pair<Location, MachineInstr::const_mop_iterator>
39 (*OperandParser)(MachineInstr::const_mop_iterator,
40 MachineInstr::const_mop_iterator);
42 // OpTypes are used to encode information about the following logical
43 // operand (which may consist of several MachineOperands) for the
45 typedef enum { DirectMemRefOp, IndirectMemRefOp, ConstantOp } OpType;
47 StackMaps(AsmPrinter &AP, OperandParser OpParser)
48 : AP(AP), OpParser(OpParser) {}
50 /// This should be called by the MC lowering code _immediately_ before
51 /// lowering the MI to an MCInst. It records where the operands for the
52 /// instruction are stored, and outputs a label to record the offset of
53 /// the call from the start of the text section. In special cases (e.g. AnyReg
54 /// calling convention) the return register is also recorded if requested.
55 void recordStackMap(const MachineInstr &MI, uint32_t ID,
56 MachineInstr::const_mop_iterator MOI,
57 MachineInstr::const_mop_iterator MOE,
58 bool recordResult = false);
60 /// If there is any stack map data, create a stack map section and serialize
61 /// the map info into it. This clears the stack map data structures
63 void serializeToStackMapSection();
67 typedef SmallVector<Location, 8> LocationVec;
70 const MCExpr *CSOffsetExpr;
72 LocationVec Locations;
73 CallsiteInfo() : CSOffsetExpr(0), ID(0) {}
74 CallsiteInfo(const MCExpr *CSOffsetExpr, unsigned ID,
75 LocationVec Locations)
76 : CSOffsetExpr(CSOffsetExpr), ID(ID), Locations(Locations) {}
79 typedef std::vector<CallsiteInfo> CallsiteInfoList;
83 typedef std::map<int64_t, size_t> ConstantsMap;
84 std::vector<int64_t> ConstantsList;
85 ConstantsMap ConstantIndexes;
88 size_t getNumConstants() const { return ConstantsList.size(); }
89 int64_t getConstant(size_t Idx) const { return ConstantsList[Idx]; }
90 size_t getConstantIndex(int64_t ConstVal) {
91 size_t NextIdx = ConstantsList.size();
92 ConstantsMap::const_iterator I =
93 ConstantIndexes.insert(ConstantIndexes.end(),
94 std::make_pair(ConstVal, NextIdx));
95 if (I->second == NextIdx)
96 ConstantsList.push_back(ConstVal);
102 OperandParser OpParser;
103 CallsiteInfoList CSInfos;
104 ConstantPool ConstPool;
109 #endif // LLVM_STACKMAPS