46struct FPOInstruction {
62 unsigned ParamsSize = 0;
73 std::unique_ptr<FPOData> CurFPOData;
75 bool haveOpenFPOData() {
return !!CurFPOData; }
79 bool checkInFPOPrologue(
SMLoc L);
101 unsigned ParamsSize,
SMLoc L) {
102 OS <<
"\t.cv_fpo_proc\t";
103 ProcSym->print(
OS, getStreamer().getContext().getAsmInfo());
104 OS <<
' ' << ParamsSize <<
'\n';
108bool X86WinCOFFAsmTargetStreamer::emitFPOEndPrologue(
SMLoc L) {
109 OS <<
"\t.cv_fpo_endprologue\n";
113bool X86WinCOFFAsmTargetStreamer::emitFPOEndProc(
SMLoc L) {
114 OS <<
"\t.cv_fpo_endproc\n";
120 OS <<
"\t.cv_fpo_data\t";
121 ProcSym->print(
OS, getStreamer().getContext().getAsmInfo());
126bool X86WinCOFFAsmTargetStreamer::emitFPOPushReg(
unsigned Reg,
SMLoc L) {
127 OS <<
"\t.cv_fpo_pushreg\t";
128 InstPrinter.printRegName(
OS, Reg);
133bool X86WinCOFFAsmTargetStreamer::emitFPOStackAlloc(
unsigned StackAlloc,
135 OS <<
"\t.cv_fpo_stackalloc\t" << StackAlloc <<
'\n';
139bool X86WinCOFFAsmTargetStreamer::emitFPOStackAlign(
unsigned Align,
SMLoc L) {
140 OS <<
"\t.cv_fpo_stackalign\t" <<
Align <<
'\n';
144bool X86WinCOFFAsmTargetStreamer::emitFPOSetFrame(
unsigned Reg,
SMLoc L) {
145 OS <<
"\t.cv_fpo_setframe\t";
146 InstPrinter.printRegName(
OS, Reg);
151bool X86WinCOFFTargetStreamer::checkInFPOPrologue(
SMLoc L) {
152 if (!haveOpenFPOData() || CurFPOData->PrologueEnd) {
153 getContext().reportError(
155 "directive must appear between .cv_fpo_proc and .cv_fpo_endprologue");
161MCSymbol *X86WinCOFFTargetStreamer::emitFPOLabel() {
162 MCSymbol *
Label = getContext().createTempSymbol(
"cfi",
true);
163 getStreamer().emitLabel(Label);
168 unsigned ParamsSize,
SMLoc L) {
169 if (haveOpenFPOData()) {
170 getContext().reportError(
171 L,
"opening new .cv_fpo_proc before closing previous frame");
174 CurFPOData = std::make_unique<FPOData>();
175 CurFPOData->Function =
ProcSym;
176 CurFPOData->Begin = emitFPOLabel();
177 CurFPOData->ParamsSize = ParamsSize;
181bool X86WinCOFFTargetStreamer::emitFPOEndProc(
SMLoc L) {
182 if (!haveOpenFPOData()) {
183 getContext().reportError(L,
".cv_fpo_endproc must appear after .cv_proc");
186 if (!CurFPOData->PrologueEnd) {
188 if (!CurFPOData->Instructions.empty()) {
189 getContext().reportError(L,
"missing .cv_fpo_endprologue");
190 CurFPOData->Instructions.clear();
195 CurFPOData->PrologueEnd = CurFPOData->Begin;
198 CurFPOData->End = emitFPOLabel();
199 const MCSymbol *Fn = CurFPOData->Function;
200 AllFPOData.insert({Fn, std::move(CurFPOData)});
204bool X86WinCOFFTargetStreamer::emitFPOSetFrame(
unsigned Reg,
SMLoc L) {
205 if (checkInFPOPrologue(L))
208 Inst.Label = emitFPOLabel();
209 Inst.Op = FPOInstruction::SetFrame;
210 Inst.RegOrOffset =
Reg;
211 CurFPOData->Instructions.push_back(Inst);
215bool X86WinCOFFTargetStreamer::emitFPOPushReg(
unsigned Reg,
SMLoc L) {
216 if (checkInFPOPrologue(L))
219 Inst.Label = emitFPOLabel();
220 Inst.Op = FPOInstruction::PushReg;
221 Inst.RegOrOffset =
Reg;
222 CurFPOData->Instructions.push_back(Inst);
226bool X86WinCOFFTargetStreamer::emitFPOStackAlloc(
unsigned StackAlloc,
SMLoc L) {
227 if (checkInFPOPrologue(L))
230 Inst.Label = emitFPOLabel();
231 Inst.Op = FPOInstruction::StackAlloc;
232 Inst.RegOrOffset = StackAlloc;
233 CurFPOData->Instructions.push_back(Inst);
237bool X86WinCOFFTargetStreamer::emitFPOStackAlign(
unsigned Align,
SMLoc L) {
238 if (checkInFPOPrologue(L))
240 if (
llvm::none_of(CurFPOData->Instructions, [](
const FPOInstruction &Inst) {
241 return Inst.Op == FPOInstruction::SetFrame;
243 getContext().reportError(
244 L,
"a frame register must be established before aligning the stack");
248 Inst.Label = emitFPOLabel();
249 Inst.Op = FPOInstruction::StackAlign;
250 Inst.RegOrOffset =
Align;
251 CurFPOData->Instructions.push_back(Inst);
255bool X86WinCOFFTargetStreamer::emitFPOEndPrologue(
SMLoc L) {
256 if (checkInFPOPrologue(L))
258 CurFPOData->PrologueEnd = emitFPOLabel();
263struct RegSaveOffset {
270struct FPOStateMachine {
271 explicit FPOStateMachine(
const FPOData *FPO) :
FPO(
FPO) {}
273 const FPOData *
FPO =
nullptr;
274 unsigned FrameReg = 0;
275 unsigned FrameRegOff = 0;
276 unsigned CurOffset = 0;
277 unsigned LocalSize = 0;
278 unsigned SavedRegSize = 0;
279 unsigned StackOffsetBeforeAlign = 0;
280 unsigned StackAlign = 0;
296 case X86::EAX:
OS <<
"$eax";
break;
297 case X86::EBX:
OS <<
"$ebx";
break;
298 case X86::ECX:
OS <<
"$ecx";
break;
299 case X86::EDX:
OS <<
"$edx";
break;
300 case X86::EDI:
OS <<
"$edi";
break;
301 case X86::ESI:
OS <<
"$esi";
break;
302 case X86::ESP:
OS <<
"$esp";
break;
303 case X86::EBP:
OS <<
"$ebp";
break;
304 case X86::EIP:
OS <<
"$eip";
break;
307 OS <<
'$' <<
MRI->getCodeViewRegNum(LLVMReg);
314 unsigned CurFlags =
Flags;
315 if (Label ==
FPO->Begin)
322 assert((StackAlign == 0 || FrameReg != 0) &&
323 "cannot align stack without frame reg");
324 StringRef CFAVar = StackAlign == 0 ?
"$T0" :
"$T1";
328 FuncOS << CFAVar <<
' ' <<
printFPOReg(
MRI, FrameReg) <<
' ' << FrameRegOff
336 FuncOS <<
"$T0 " << CFAVar <<
' ' << StackOffsetBeforeAlign <<
" - "
337 << StackAlign <<
" @ = ";
344 FuncOS << CFAVar <<
" .raSearch = ";
348 FuncOS <<
"$eip " << CFAVar <<
" ^ = ";
349 FuncOS <<
"$esp " << CFAVar <<
" 4 + = ";
352 for (RegSaveOffset RO : RegSaveOffsets)
353 FuncOS <<
printFPOReg(
MRI, RO.Reg) <<
' ' << CFAVar <<
' ' << RO.Offset
361 unsigned MaxStackSize = 0;
374 OS.emitAbsoluteSymbolDiff(Label,
FPO->Begin, 4);
375 OS.emitAbsoluteSymbolDiff(
FPO->End, Label, 4);
376 OS.emitInt32(LocalSize);
377 OS.emitInt32(
FPO->ParamsSize);
378 OS.emitInt32(MaxStackSize);
379 OS.emitInt32(FrameFuncStrTabOff);
380 OS.emitAbsoluteSymbolDiff(
FPO->PrologueEnd, Label, 2);
381 OS.emitInt16(SavedRegSize);
382 OS.emitInt32(CurFlags);
391 if (
I == AllFPOData.end()) {
396 const FPOData *
FPO =
I->second.get();
397 assert(
FPO->Begin &&
FPO->End &&
FPO->PrologueEnd &&
"missing FPO label");
402 OS.emitInt32(
unsigned(DebugSubsectionKind::FrameData));
403 OS.emitAbsoluteSymbolDiff(FrameEnd, FrameBegin, 4);
404 OS.emitLabel(FrameBegin);
412 FPOStateMachine FSM(FPO);
414 FSM.emitFrameDataRecord(
OS,
FPO->Begin);
415 for (
const FPOInstruction &Inst :
FPO->Instructions) {
417 case FPOInstruction::PushReg:
419 FSM.SavedRegSize += 4;
420 FSM.RegSaveOffsets.push_back({Inst.RegOrOffset, FSM.CurOffset});
422 case FPOInstruction::SetFrame:
423 FSM.FrameReg = Inst.RegOrOffset;
424 FSM.FrameRegOff = FSM.CurOffset;
426 case FPOInstruction::StackAlign:
427 FSM.StackOffsetBeforeAlign = FSM.CurOffset;
428 FSM.StackAlign = Inst.RegOrOffset;
430 case FPOInstruction::StackAlloc:
431 FSM.CurOffset += Inst.RegOrOffset;
432 FSM.LocalSize += Inst.RegOrOffset;
438 FSM.emitFrameDataRecord(
OS, Inst.Label);
441 OS.emitValueToAlignment(
Align(4), 0);
442 OS.emitLabel(FrameEnd);
451 return new X86WinCOFFAsmTargetStreamer(S,
OS, *InstPrinter);
460 return new X86WinCOFFTargetStreamer(S);
unsigned const MachineRegisterInfo * MRI
PowerPC Reduce CR logical Operation
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static Printable printFPOReg(const MCRegisterInfo *MRI, unsigned LLVMReg)
Holds state from .cv_file and .cv_loc directives for later emission.
std::pair< StringRef, unsigned > addToStringTable(StringRef S)
Add something to the string table.
This class represents an Operation in the Expression.
Context object for machine code objects.
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
void reportError(SMLoc L, const Twine &Msg)
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Streaming machine code generation interface.
MCContext & getContext() const
Generic base class for all target subtargets.
const Triple & getTargetTriple() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Target specific streamer interface.
MCStreamer & getStreamer()
Simple wrapper around std::function<void(raw_ostream&)>.
Represents a location in source code.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
X86 target streamer implementing x86-only assembly directives.
virtual bool emitFPOPushReg(unsigned Reg, SMLoc L={})
virtual bool emitFPOProc(const MCSymbol *ProcSym, unsigned ParamsSize, SMLoc L={})
virtual bool emitFPOSetFrame(unsigned Reg, SMLoc L={})
virtual bool emitFPOEndPrologue(SMLoc L={})
virtual bool emitFPOData(const MCSymbol *ProcSym, SMLoc L={})
virtual bool emitFPOEndProc(SMLoc L={})
virtual bool emitFPOStackAlign(unsigned Align, SMLoc L={})
virtual bool emitFPOStackAlloc(unsigned StackAlloc, SMLoc L={})
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an SmallVector or SmallString.
Reg
All possible values of the reg field in the ModR/M byte.
This is an optimization pass for GlobalISel generic memory operations.
MCTargetStreamer * createX86ObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
Implements X86-only directives for object files.
MCTargetStreamer * createX86AsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrinter)
Implements X86-only directives for assembly emission.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
This struct is a compact representation of a valid (non-zero power of two) alignment.