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.
54 void recordStackMap(const MachineInstr &MI, uint32_t ID,
55 MachineInstr::const_mop_iterator MOI,
56 MachineInstr::const_mop_iterator MOE);
58 /// If there is any stack map data, create a stack map section and serialize
59 /// the map info into it. This clears the stack map data structures
61 void serializeToStackMapSection();
65 typedef SmallVector<Location, 8> LocationVec;
68 const MCExpr *CSOffsetExpr;
70 LocationVec Locations;
71 CallsiteInfo() : CSOffsetExpr(0), ID(0) {}
72 CallsiteInfo(const MCExpr *CSOffsetExpr, unsigned ID,
73 LocationVec Locations)
74 : CSOffsetExpr(CSOffsetExpr), ID(ID), Locations(Locations) {}
77 typedef std::vector<CallsiteInfo> CallsiteInfoList;
81 typedef std::map<int64_t, size_t> ConstantsMap;
82 std::vector<int64_t> ConstantsList;
83 ConstantsMap ConstantIndexes;
86 size_t getNumConstants() const { return ConstantsList.size(); }
87 int64_t getConstant(size_t Idx) const { return ConstantsList[Idx]; }
88 size_t getConstantIndex(int64_t ConstVal) {
89 size_t NextIdx = ConstantsList.size();
90 ConstantsMap::const_iterator I =
91 ConstantIndexes.insert(ConstantIndexes.end(),
92 std::make_pair(ConstVal, NextIdx));
93 if (I->second == NextIdx)
94 ConstantsList.push_back(ConstVal);
100 OperandParser OpParser;
101 CallsiteInfoList CSInfos;
102 ConstantPool ConstPool;
107 #endif // LLVM_STACKMAPS