blob: 5d077932df3f325c3d287ed51aeafb88c5409a8a [file] [log] [blame]
Andrew Trick153ebe62013-10-31 22:11:56 +00001//===---------------------------- StackMaps.cpp ---------------------------===//
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#define DEBUG_TYPE "stackmaps"
11
12#include "llvm/CodeGen/StackMaps.h"
Andrew Trick153ebe62013-10-31 22:11:56 +000013#include "llvm/CodeGen/AsmPrinter.h"
Juergen Ributzkafb4d6482014-01-30 18:58:27 +000014#include "llvm/CodeGen/MachineFunction.h"
15#include "llvm/CodeGen/MachineFrameInfo.h"
Andrew Trick153ebe62013-10-31 22:11:56 +000016#include "llvm/CodeGen/MachineInstr.h"
Lang Hames39609992013-11-29 03:07:54 +000017#include "llvm/IR/DataLayout.h"
Andrew Trick153ebe62013-10-31 22:11:56 +000018#include "llvm/MC/MCContext.h"
19#include "llvm/MC/MCExpr.h"
Lang Hames8a065702013-11-08 22:30:52 +000020#include "llvm/MC/MCObjectFileInfo.h"
Andrew Trick153ebe62013-10-31 22:11:56 +000021#include "llvm/MC/MCSectionMachO.h"
22#include "llvm/MC/MCStreamer.h"
23#include "llvm/Support/Debug.h"
24#include "llvm/Support/raw_ostream.h"
Andrew Trick153ebe62013-10-31 22:11:56 +000025#include "llvm/Target/TargetMachine.h"
Chandler Carruth8a8cd2b2014-01-07 11:48:04 +000026#include "llvm/Target/TargetOpcodes.h"
Andrew Trick153ebe62013-10-31 22:11:56 +000027#include "llvm/Target/TargetRegisterInfo.h"
Andrew Trick153ebe62013-10-31 22:11:56 +000028#include <iterator>
29
30using namespace llvm;
31
Juergen Ributzkac26b68a2013-12-14 23:06:19 +000032PatchPointOpers::PatchPointOpers(const MachineInstr *MI)
33 : MI(MI),
34 HasDef(MI->getOperand(0).isReg() && MI->getOperand(0).isDef() &&
35 !MI->getOperand(0).isImplicit()),
36 IsAnyReg(MI->getOperand(getMetaIdx(CCPos)).getImm() == CallingConv::AnyReg)
37{
Andrew Trickd4e3dc62013-11-19 03:29:56 +000038#ifndef NDEBUG
Andrew Trickd4e3dc62013-11-19 03:29:56 +000039 unsigned CheckStartIdx = 0, e = MI->getNumOperands();
40 while (CheckStartIdx < e && MI->getOperand(CheckStartIdx).isReg() &&
41 MI->getOperand(CheckStartIdx).isDef() &&
42 !MI->getOperand(CheckStartIdx).isImplicit())
43 ++CheckStartIdx;
44
45 assert(getMetaIdx() == CheckStartIdx &&
Alp Tokercb402912014-01-24 17:20:08 +000046 "Unexpected additional definition in Patchpoint intrinsic.");
Andrew Trickd4e3dc62013-11-19 03:29:56 +000047#endif
48}
49
50unsigned PatchPointOpers::getNextScratchIdx(unsigned StartIdx) const {
51 if (!StartIdx)
52 StartIdx = getVarIdx();
53
54 // Find the next scratch register (implicit def and early clobber)
55 unsigned ScratchIdx = StartIdx, e = MI->getNumOperands();
56 while (ScratchIdx < e &&
57 !(MI->getOperand(ScratchIdx).isReg() &&
58 MI->getOperand(ScratchIdx).isDef() &&
59 MI->getOperand(ScratchIdx).isImplicit() &&
60 MI->getOperand(ScratchIdx).isEarlyClobber()))
61 ++ScratchIdx;
62
63 assert(ScratchIdx != e && "No scratch register available");
64 return ScratchIdx;
65}
66
Juergen Ributzkac26b68a2013-12-14 23:06:19 +000067MachineInstr::const_mop_iterator
Lang Hames39609992013-11-29 03:07:54 +000068StackMaps::parseOperand(MachineInstr::const_mop_iterator MOI,
Juergen Ributzkac26b68a2013-12-14 23:06:19 +000069 MachineInstr::const_mop_iterator MOE,
70 LocationVec &Locs, LiveOutVec &LiveOuts) const {
71 if (MOI->isImm()) {
72 switch (MOI->getImm()) {
73 default: llvm_unreachable("Unrecognized operand type.");
74 case StackMaps::DirectMemRefOp: {
75 unsigned Size = AP.TM.getDataLayout()->getPointerSizeInBits();
76 assert((Size % 8) == 0 && "Need pointer size in bytes.");
77 Size /= 8;
78 unsigned Reg = (++MOI)->getReg();
79 int64_t Imm = (++MOI)->getImm();
80 Locs.push_back(Location(StackMaps::Location::Direct, Size, Reg, Imm));
81 break;
Lang Hames39609992013-11-29 03:07:54 +000082 }
Juergen Ributzkac26b68a2013-12-14 23:06:19 +000083 case StackMaps::IndirectMemRefOp: {
84 int64_t Size = (++MOI)->getImm();
85 assert(Size > 0 && "Need a valid size for indirect memory locations.");
86 unsigned Reg = (++MOI)->getReg();
87 int64_t Imm = (++MOI)->getImm();
88 Locs.push_back(Location(StackMaps::Location::Indirect, Size, Reg, Imm));
89 break;
90 }
91 case StackMaps::ConstantOp: {
92 ++MOI;
93 assert(MOI->isImm() && "Expected constant operand.");
94 int64_t Imm = MOI->getImm();
95 Locs.push_back(Location(Location::Constant, sizeof(int64_t), 0, Imm));
96 break;
97 }
98 }
99 return ++MOI;
Lang Hames39609992013-11-29 03:07:54 +0000100 }
101
Juergen Ributzkac26b68a2013-12-14 23:06:19 +0000102 // The physical register number will ultimately be encoded as a DWARF regno.
103 // The stack map also records the size of a spill slot that can hold the
104 // register content. (The runtime can track the actual size of the data type
105 // if it needs to.)
106 if (MOI->isReg()) {
107 // Skip implicit registers (this includes our scratch registers)
108 if (MOI->isImplicit())
109 return ++MOI;
Juergen Ributzkae8294752013-12-14 06:53:06 +0000110
Juergen Ributzkac26b68a2013-12-14 23:06:19 +0000111 assert(TargetRegisterInfo::isPhysicalRegister(MOI->getReg()) &&
112 "Virtreg operands should have been rewritten before now.");
113 const TargetRegisterClass *RC =
114 AP.TM.getRegisterInfo()->getMinimalPhysRegClass(MOI->getReg());
115 assert(!MOI->getSubReg() && "Physical subreg still around.");
116 Locs.push_back(
117 Location(Location::Register, RC->getSize(), MOI->getReg(), 0));
118 return ++MOI;
119 }
120
121 if (MOI->isRegLiveOut())
122 LiveOuts = parseRegisterLiveOutMask(MOI->getRegLiveOut());
123
124 return ++MOI;
Lang Hames39609992013-11-29 03:07:54 +0000125}
126
Juergen Ributzkae8294752013-12-14 06:53:06 +0000127/// Go up the super-register chain until we hit a valid dwarf register number.
Juergen Ributzka73a7fcc2014-02-10 23:30:26 +0000128static unsigned getDwarfRegNum(unsigned Reg, const TargetRegisterInfo *TRI) {
129 int RegNo = TRI->getDwarfRegNum(Reg, false);
130 for (MCSuperRegIterator SR(Reg, TRI); SR.isValid() && RegNo < 0; ++SR)
Juergen Ributzkae8294752013-12-14 06:53:06 +0000131 RegNo = TRI->getDwarfRegNum(*SR, false);
132
133 assert(RegNo >= 0 && "Invalid Dwarf register number.");
Juergen Ributzka73a7fcc2014-02-10 23:30:26 +0000134 return (unsigned) RegNo;
Juergen Ributzkae8294752013-12-14 06:53:06 +0000135}
136
137/// Create a live-out register record for the given register Reg.
138StackMaps::LiveOutReg
Juergen Ributzka73a7fcc2014-02-10 23:30:26 +0000139StackMaps::createLiveOutReg(unsigned Reg, const TargetRegisterInfo *TRI) const {
140 unsigned RegNo = getDwarfRegNum(Reg, TRI);
Juergen Ributzkae8294752013-12-14 06:53:06 +0000141 unsigned Size = TRI->getMinimalPhysRegClass(Reg)->getSize();
142 return LiveOutReg(Reg, RegNo, Size);
143}
144
145/// Parse the register live-out mask and return a vector of live-out registers
146/// that need to be recorded in the stackmap.
147StackMaps::LiveOutVec
148StackMaps::parseRegisterLiveOutMask(const uint32_t *Mask) const {
149 assert(Mask && "No register mask specified");
150 const TargetRegisterInfo *TRI = AP.TM.getRegisterInfo();
Juergen Ributzkae8294752013-12-14 06:53:06 +0000151 LiveOutVec LiveOuts;
152
153 // Create a LiveOutReg for each bit that is set in the register mask.
154 for (unsigned Reg = 0, NumRegs = TRI->getNumRegs(); Reg != NumRegs; ++Reg)
155 if ((Mask[Reg / 32] >> Reg % 32) & 1)
Juergen Ributzka73a7fcc2014-02-10 23:30:26 +0000156 LiveOuts.push_back(createLiveOutReg(Reg, TRI));
Juergen Ributzkae8294752013-12-14 06:53:06 +0000157
158 // We don't need to keep track of a register if its super-register is already
159 // in the list. Merge entries that refer to the same dwarf register and use
160 // the maximum size that needs to be spilled.
161 std::sort(LiveOuts.begin(), LiveOuts.end());
162 for (LiveOutVec::iterator I = LiveOuts.begin(), E = LiveOuts.end();
163 I != E; ++I) {
164 for (LiveOutVec::iterator II = next(I); II != E; ++II) {
165 if (I->RegNo != II->RegNo) {
166 // Skip all the now invalid entries.
167 I = --II;
168 break;
169 }
170 I->Size = std::max(I->Size, II->Size);
171 if (TRI->isSuperRegister(I->Reg, II->Reg))
172 I->Reg = II->Reg;
173 II->MarkInvalid();
174 }
175 }
176 LiveOuts.erase(std::remove_if(LiveOuts.begin(), LiveOuts.end(),
177 LiveOutReg::IsInvalid), LiveOuts.end());
178 return LiveOuts;
179}
180
Andrew Tricke8cba372013-12-13 18:37:10 +0000181void StackMaps::recordStackMapOpers(const MachineInstr &MI, uint64_t ID,
Andrew Trickd4e3dc62013-11-19 03:29:56 +0000182 MachineInstr::const_mop_iterator MOI,
183 MachineInstr::const_mop_iterator MOE,
184 bool recordResult) {
Andrew Trick153ebe62013-10-31 22:11:56 +0000185
186 MCContext &OutContext = AP.OutStreamer.getContext();
187 MCSymbol *MILabel = OutContext.CreateTempSymbol();
188 AP.OutStreamer.EmitLabel(MILabel);
189
Juergen Ributzkae8294752013-12-14 06:53:06 +0000190 LocationVec Locations;
191 LiveOutVec LiveOuts;
Andrew Trick153ebe62013-10-31 22:11:56 +0000192
Juergen Ributzka9969d3e2013-11-08 23:28:16 +0000193 if (recordResult) {
Juergen Ributzkac26b68a2013-12-14 23:06:19 +0000194 assert(PatchPointOpers(&MI).hasDef() && "Stackmap has no return value.");
195 parseOperand(MI.operands_begin(), llvm::next(MI.operands_begin()),
196 Locations, LiveOuts);
Juergen Ributzka9969d3e2013-11-08 23:28:16 +0000197 }
198
Juergen Ributzkac26b68a2013-12-14 23:06:19 +0000199 // Parse operands.
Andrew Trick153ebe62013-10-31 22:11:56 +0000200 while (MOI != MOE) {
Juergen Ributzkac26b68a2013-12-14 23:06:19 +0000201 MOI = parseOperand(MOI, MOE, Locations, LiveOuts);
202 }
Andrew Trick153ebe62013-10-31 22:11:56 +0000203
Juergen Ributzkac26b68a2013-12-14 23:06:19 +0000204 // Move large constants into the constant pool.
205 for (LocationVec::iterator I = Locations.begin(), E = Locations.end();
206 I != E; ++I) {
Andrew Trick32e1be72014-01-09 00:22:31 +0000207 // Constants are encoded as sign-extended integers.
208 // -1 is directly encoded as .long 0xFFFFFFFF with no constant pool.
209 if (I->LocType == Location::Constant &&
210 ((I->Offset + (int64_t(1)<<31)) >> 32) != 0) {
Juergen Ributzkac26b68a2013-12-14 23:06:19 +0000211 I->LocType = Location::ConstantIndex;
212 I->Offset = ConstPool.getConstantIndex(I->Offset);
Andrew Trick153ebe62013-10-31 22:11:56 +0000213 }
Andrew Trick153ebe62013-10-31 22:11:56 +0000214 }
215
Juergen Ributzkafb4d6482014-01-30 18:58:27 +0000216 // Create an expression to calculate the offset of the callsite from function
217 // entry.
Andrew Trick153ebe62013-10-31 22:11:56 +0000218 const MCExpr *CSOffsetExpr = MCBinaryExpr::CreateSub(
219 MCSymbolRefExpr::Create(MILabel, OutContext),
220 MCSymbolRefExpr::Create(AP.CurrentFnSym, OutContext),
221 OutContext);
222
Juergen Ributzkae8294752013-12-14 06:53:06 +0000223 CSInfos.push_back(CallsiteInfo(CSOffsetExpr, ID, Locations, LiveOuts));
Juergen Ributzkafb4d6482014-01-30 18:58:27 +0000224
225 // Record the stack size of the current function.
226 const MachineFrameInfo *MFI = AP.MF->getFrameInfo();
227 FnStackSize[AP.CurrentFnSym] =
228 MFI->hasVarSizedObjects() ? ~0U : MFI->getStackSize();
Andrew Trick153ebe62013-10-31 22:11:56 +0000229}
230
Andrew Trickd4e3dc62013-11-19 03:29:56 +0000231void StackMaps::recordStackMap(const MachineInstr &MI) {
Juergen Ributzkae8294752013-12-14 06:53:06 +0000232 assert(MI.getOpcode() == TargetOpcode::STACKMAP && "expected stackmap");
Andrew Trickd4e3dc62013-11-19 03:29:56 +0000233
234 int64_t ID = MI.getOperand(0).getImm();
Andrew Trickd4e3dc62013-11-19 03:29:56 +0000235 recordStackMapOpers(MI, ID, llvm::next(MI.operands_begin(), 2),
Juergen Ributzkac26b68a2013-12-14 23:06:19 +0000236 MI.operands_end());
Andrew Trickd4e3dc62013-11-19 03:29:56 +0000237}
238
239void StackMaps::recordPatchPoint(const MachineInstr &MI) {
Juergen Ributzkae8294752013-12-14 06:53:06 +0000240 assert(MI.getOpcode() == TargetOpcode::PATCHPOINT && "expected patchpoint");
Andrew Trickd4e3dc62013-11-19 03:29:56 +0000241
242 PatchPointOpers opers(&MI);
243 int64_t ID = opers.getMetaOper(PatchPointOpers::IDPos).getImm();
Andrew Tricke8cba372013-12-13 18:37:10 +0000244
Andrew Trickd4e3dc62013-11-19 03:29:56 +0000245 MachineInstr::const_mop_iterator MOI =
246 llvm::next(MI.operands_begin(), opers.getStackMapStartIdx());
Juergen Ributzkac26b68a2013-12-14 23:06:19 +0000247 recordStackMapOpers(MI, ID, MOI, MI.operands_end(),
Andrew Trickd4e3dc62013-11-19 03:29:56 +0000248 opers.isAnyReg() && opers.hasDef());
249
250#ifndef NDEBUG
251 // verify anyregcc
252 LocationVec &Locations = CSInfos.back().Locations;
253 if (opers.isAnyReg()) {
254 unsigned NArgs = opers.getMetaOper(PatchPointOpers::NArgPos).getImm();
255 for (unsigned i = 0, e = (opers.hasDef() ? NArgs+1 : NArgs); i != e; ++i)
256 assert(Locations[i].LocType == Location::Register &&
257 "anyreg arg must be in reg.");
258 }
259#endif
260}
261
Andrew Trick153ebe62013-10-31 22:11:56 +0000262/// serializeToStackMapSection conceptually populates the following fields:
263///
264/// uint32 : Reserved (header)
Juergen Ributzkafb4d6482014-01-30 18:58:27 +0000265/// uint32 : NumFunctions
266/// StkSizeRecord[NumFunctions] {
267/// uint32 : Function Offset
268/// uint32 : Stack Size
269/// }
Andrew Trick153ebe62013-10-31 22:11:56 +0000270/// uint32 : NumConstants
271/// int64 : Constants[NumConstants]
272/// uint32 : NumRecords
273/// StkMapRecord[NumRecords] {
Andrew Tricke8cba372013-12-13 18:37:10 +0000274/// uint64 : PatchPoint ID
Andrew Trick153ebe62013-10-31 22:11:56 +0000275/// uint32 : Instruction Offset
276/// uint16 : Reserved (record flags)
277/// uint16 : NumLocations
278/// Location[NumLocations] {
279/// uint8 : Register | Direct | Indirect | Constant | ConstantIndex
Andrew Trick10d5be42013-11-17 01:36:23 +0000280/// uint8 : Size in Bytes
Andrew Trick153ebe62013-10-31 22:11:56 +0000281/// uint16 : Dwarf RegNum
282/// int32 : Offset
283/// }
Juergen Ributzkae8294752013-12-14 06:53:06 +0000284/// uint16 : NumLiveOuts
285/// LiveOuts[NumLiveOuts]
286/// uint16 : Dwarf RegNum
287/// uint8 : Reserved
288/// uint8 : Size in Bytes
Andrew Trick153ebe62013-10-31 22:11:56 +0000289/// }
290///
291/// Location Encoding, Type, Value:
292/// 0x1, Register, Reg (value in register)
293/// 0x2, Direct, Reg + Offset (frame index)
294/// 0x3, Indirect, [Reg + Offset] (spilled value)
295/// 0x4, Constant, Offset (small constant)
296/// 0x5, ConstIndex, Constants[Offset] (large constant)
297///
298void StackMaps::serializeToStackMapSection() {
299 // Bail out if there's no stack map data.
300 if (CSInfos.empty())
301 return;
302
303 MCContext &OutContext = AP.OutStreamer.getContext();
304 const TargetRegisterInfo *TRI = AP.TM.getRegisterInfo();
305
306 // Create the section.
307 const MCSection *StackMapSection =
Lang Hames8a065702013-11-08 22:30:52 +0000308 OutContext.getObjectFileInfo()->getStackMapSection();
Andrew Trick153ebe62013-10-31 22:11:56 +0000309 AP.OutStreamer.SwitchSection(StackMapSection);
310
311 // Emit a dummy symbol to force section inclusion.
312 AP.OutStreamer.EmitLabel(
313 OutContext.GetOrCreateSymbol(Twine("__LLVM_StackMaps")));
314
315 // Serialize data.
316 const char *WSMP = "Stack Maps: ";
Andrew Trickc21d86f2013-10-31 22:42:20 +0000317 (void)WSMP;
Andrew Trick153ebe62013-10-31 22:11:56 +0000318
319 DEBUG(dbgs() << "********** Stack Map Output **********\n");
320
321 // Header.
322 AP.OutStreamer.EmitIntValue(0, 4);
323
Juergen Ributzkafb4d6482014-01-30 18:58:27 +0000324 // Num functions.
325 AP.OutStreamer.EmitIntValue(FnStackSize.size(), 4);
326
327 // Stack size entries.
328 for (FnStackSizeMap::iterator I = FnStackSize.begin(), E = FnStackSize.end();
329 I != E; ++I) {
330 AP.OutStreamer.EmitSymbolValue(I->first, 4);
331 AP.OutStreamer.EmitIntValue(I->second, 4);
332 }
333
Andrew Trick153ebe62013-10-31 22:11:56 +0000334 // Num constants.
335 AP.OutStreamer.EmitIntValue(ConstPool.getNumConstants(), 4);
336
337 // Constant pool entries.
338 for (unsigned i = 0; i < ConstPool.getNumConstants(); ++i)
339 AP.OutStreamer.EmitIntValue(ConstPool.getConstant(i), 8);
340
341 DEBUG(dbgs() << WSMP << "#callsites = " << CSInfos.size() << "\n");
342 AP.OutStreamer.EmitIntValue(CSInfos.size(), 4);
343
344 for (CallsiteInfoList::const_iterator CSII = CSInfos.begin(),
345 CSIE = CSInfos.end();
346 CSII != CSIE; ++CSII) {
347
Andrew Tricke8cba372013-12-13 18:37:10 +0000348 uint64_t CallsiteID = CSII->ID;
Andrew Trick153ebe62013-10-31 22:11:56 +0000349 const LocationVec &CSLocs = CSII->Locations;
Juergen Ributzkae8294752013-12-14 06:53:06 +0000350 const LiveOutVec &LiveOuts = CSII->LiveOuts;
Andrew Trick153ebe62013-10-31 22:11:56 +0000351
352 DEBUG(dbgs() << WSMP << "callsite " << CallsiteID << "\n");
353
354 // Verify stack map entry. It's better to communicate a problem to the
355 // runtime than crash in case of in-process compilation. Currently, we do
356 // simple overflow checks, but we may eventually communicate other
357 // compilation errors this way.
Juergen Ributzkae8294752013-12-14 06:53:06 +0000358 if (CSLocs.size() > UINT16_MAX || LiveOuts.size() > UINT16_MAX) {
359 AP.OutStreamer.EmitIntValue(UINT64_MAX, 8); // Invalid ID.
Andrew Trick153ebe62013-10-31 22:11:56 +0000360 AP.OutStreamer.EmitValue(CSII->CSOffsetExpr, 4);
361 AP.OutStreamer.EmitIntValue(0, 2); // Reserved.
362 AP.OutStreamer.EmitIntValue(0, 2); // 0 locations.
Juergen Ributzkae8294752013-12-14 06:53:06 +0000363 AP.OutStreamer.EmitIntValue(0, 2); // 0 live-out registers.
Andrew Trick153ebe62013-10-31 22:11:56 +0000364 continue;
365 }
366
Andrew Tricke8cba372013-12-13 18:37:10 +0000367 AP.OutStreamer.EmitIntValue(CallsiteID, 8);
Andrew Trick153ebe62013-10-31 22:11:56 +0000368 AP.OutStreamer.EmitValue(CSII->CSOffsetExpr, 4);
369
370 // Reserved for flags.
371 AP.OutStreamer.EmitIntValue(0, 2);
372
373 DEBUG(dbgs() << WSMP << " has " << CSLocs.size() << " locations\n");
374
375 AP.OutStreamer.EmitIntValue(CSLocs.size(), 2);
376
377 unsigned operIdx = 0;
378 for (LocationVec::const_iterator LocI = CSLocs.begin(), LocE = CSLocs.end();
379 LocI != LocE; ++LocI, ++operIdx) {
380 const Location &Loc = *LocI;
Lang Hamesfde8e4b2013-11-27 20:10:16 +0000381 unsigned RegNo = 0;
382 int Offset = Loc.Offset;
383 if(Loc.Reg) {
Juergen Ributzka73a7fcc2014-02-10 23:30:26 +0000384 RegNo = getDwarfRegNum(Loc.Reg, TRI);
385
Lang Hamesfde8e4b2013-11-27 20:10:16 +0000386 // If this is a register location, put the subregister byte offset in
387 // the location offset.
388 if (Loc.LocType == Location::Register) {
389 assert(!Loc.Offset && "Register location should have zero offset");
Juergen Ributzka73a7fcc2014-02-10 23:30:26 +0000390 unsigned LLVMRegNo = TRI->getLLVMRegNum(RegNo, false);
391 unsigned SubRegIdx = TRI->getSubRegIndex(LLVMRegNo, Loc.Reg);
Lang Hamesfde8e4b2013-11-27 20:10:16 +0000392 if (SubRegIdx)
Juergen Ributzka73a7fcc2014-02-10 23:30:26 +0000393 Offset = TRI->getSubRegIdxOffset(SubRegIdx);
Lang Hamesfde8e4b2013-11-27 20:10:16 +0000394 }
395 }
396 else {
397 assert(Loc.LocType != Location::Register &&
398 "Missing location register");
399 }
400
Andrew Trick153ebe62013-10-31 22:11:56 +0000401 DEBUG(
402 dbgs() << WSMP << " Loc " << operIdx << ": ";
403 switch (Loc.LocType) {
404 case Location::Unprocessed:
405 dbgs() << "<Unprocessed operand>";
406 break;
407 case Location::Register:
Juergen Ributzka73a7fcc2014-02-10 23:30:26 +0000408 dbgs() << "Register " << TRI->getName(Loc.Reg);
Andrew Trick153ebe62013-10-31 22:11:56 +0000409 break;
410 case Location::Direct:
Juergen Ributzka73a7fcc2014-02-10 23:30:26 +0000411 dbgs() << "Direct " << TRI->getName(Loc.Reg);
Andrew Trick153ebe62013-10-31 22:11:56 +0000412 if (Loc.Offset)
413 dbgs() << " + " << Loc.Offset;
414 break;
415 case Location::Indirect:
Juergen Ributzka73a7fcc2014-02-10 23:30:26 +0000416 dbgs() << "Indirect " << TRI->getName(Loc.Reg)
Andrew Trick153ebe62013-10-31 22:11:56 +0000417 << " + " << Loc.Offset;
418 break;
419 case Location::Constant:
420 dbgs() << "Constant " << Loc.Offset;
421 break;
422 case Location::ConstantIndex:
423 dbgs() << "Constant Index " << Loc.Offset;
424 break;
425 }
Lang Hamesfde8e4b2013-11-27 20:10:16 +0000426 dbgs() << " [encoding: .byte " << Loc.LocType
427 << ", .byte " << Loc.Size
428 << ", .short " << RegNo
429 << ", .int " << Offset << "]\n";
Andrew Trick153ebe62013-10-31 22:11:56 +0000430 );
431
Andrew Trick153ebe62013-10-31 22:11:56 +0000432 AP.OutStreamer.EmitIntValue(Loc.LocType, 1);
Andrew Trick10d5be42013-11-17 01:36:23 +0000433 AP.OutStreamer.EmitIntValue(Loc.Size, 1);
Andrew Trick153ebe62013-10-31 22:11:56 +0000434 AP.OutStreamer.EmitIntValue(RegNo, 2);
Andrew Trick10d5be42013-11-17 01:36:23 +0000435 AP.OutStreamer.EmitIntValue(Offset, 4);
Andrew Trick153ebe62013-10-31 22:11:56 +0000436 }
Juergen Ributzkae8294752013-12-14 06:53:06 +0000437
438 DEBUG(dbgs() << WSMP << " has " << LiveOuts.size()
439 << " live-out registers\n");
440
441 AP.OutStreamer.EmitIntValue(LiveOuts.size(), 2);
442
443 operIdx = 0;
444 for (LiveOutVec::const_iterator LI = LiveOuts.begin(), LE = LiveOuts.end();
445 LI != LE; ++LI, ++operIdx) {
446 DEBUG(dbgs() << WSMP << " LO " << operIdx << ": "
Juergen Ributzka73a7fcc2014-02-10 23:30:26 +0000447 << TRI->getName(LI->Reg)
Juergen Ributzkae8294752013-12-14 06:53:06 +0000448 << " [encoding: .short " << LI->RegNo
449 << ", .byte 0, .byte " << LI->Size << "]\n");
450
451 AP.OutStreamer.EmitIntValue(LI->RegNo, 2);
452 AP.OutStreamer.EmitIntValue(0, 1);
453 AP.OutStreamer.EmitIntValue(LI->Size, 1);
454 }
Andrew Trick153ebe62013-10-31 22:11:56 +0000455 }
456
457 AP.OutStreamer.AddBlankLine();
458
459 CSInfos.clear();
460}