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,
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) {}
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&);
43 // OpTypes are used to encode information about the following logical
44 // operand (which may consist of several MachineOperands) for the
46 typedef enum { DirectMemRefOp, IndirectMemRefOp, ConstantOp } OpType;
48 StackMaps(AsmPrinter &AP, OperandParser OpParser)
49 : AP(AP), OpParser(OpParser) {}
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);
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
64 void serializeToStackMapSection();
68 typedef SmallVector<Location, 8> LocationVec;
71 const MCExpr *CSOffsetExpr;
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) {}
80 typedef std::vector<CallsiteInfo> CallsiteInfoList;
84 typedef std::map<int64_t, size_t> ConstantsMap;
85 std::vector<int64_t> ConstantsList;
86 ConstantsMap ConstantIndexes;
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);
103 OperandParser OpParser;
104 CallsiteInfoList CSInfos;
105 ConstantPool ConstPool;
110 #endif // LLVM_STACKMAPS