36 bool emitFPOEndPrologue(
SMLoc L)
override;
37 bool emitFPOEndProc(
SMLoc L)
override;
39 bool emitFPOPushReg(
unsigned Reg,
SMLoc L)
override;
40 bool emitFPOStackAlloc(
unsigned StackAlloc,
SMLoc L)
override;
41 bool emitFPOSetFrame(
unsigned Reg,
SMLoc L)
override;
45 struct FPOInstruction {
60 unsigned ParamsSize = 0;
71 std::unique_ptr<FPOData> CurFPOData;
73 bool haveOpenFPOData() {
return !!CurFPOData; }
77 bool checkInFPOPrologue(
SMLoc L);
81 MCContext &getContext() {
return getStreamer().getContext(); }
88 bool emitFPOEndPrologue(
SMLoc L)
override;
89 bool emitFPOEndProc(
SMLoc L)
override;
91 bool emitFPOPushReg(
unsigned Reg,
SMLoc L)
override;
92 bool emitFPOStackAlloc(
unsigned StackAlloc,
SMLoc L)
override;
93 bool emitFPOSetFrame(
unsigned Reg,
SMLoc L)
override;
98 unsigned ParamsSize,
SMLoc L) {
99 OS <<
"\t.cv_fpo_proc\t";
100 ProcSym->
print(OS, getStreamer().getContext().getAsmInfo());
101 OS <<
' ' << ParamsSize <<
'\n';
105 bool X86WinCOFFAsmTargetStreamer::emitFPOEndPrologue(
SMLoc L) {
106 OS <<
"\t.cv_fpo_endprologue\n";
110 bool X86WinCOFFAsmTargetStreamer::emitFPOEndProc(
SMLoc L) {
111 OS <<
"\t.cv_fpo_endproc\n";
115 bool X86WinCOFFAsmTargetStreamer::emitFPOData(
const MCSymbol *ProcSym,
117 OS <<
"\t.cv_fpo_data\t";
118 ProcSym->
print(OS, getStreamer().getContext().getAsmInfo());
123 bool X86WinCOFFAsmTargetStreamer::emitFPOPushReg(
unsigned Reg,
SMLoc L) {
124 OS <<
"\t.cv_fpo_pushreg\t";
125 InstPrinter.printRegName(OS, Reg);
130 bool X86WinCOFFAsmTargetStreamer::emitFPOStackAlloc(
unsigned StackAlloc,
132 OS <<
"\t.cv_fpo_stackalloc\t" << StackAlloc <<
'\n';
136 bool X86WinCOFFAsmTargetStreamer::emitFPOSetFrame(
unsigned Reg,
SMLoc L) {
137 OS <<
"\t.cv_fpo_setframe\t";
138 InstPrinter.printRegName(OS, Reg);
143 bool X86WinCOFFTargetStreamer::checkInFPOPrologue(
SMLoc L) {
144 if (!haveOpenFPOData() || CurFPOData->PrologueEnd) {
145 getContext().reportError(
147 "directive must appear between .cv_fpo_proc and .cv_fpo_endprologue");
153 MCSymbol *X86WinCOFFTargetStreamer::emitFPOLabel() {
154 MCSymbol *
Label = getContext().createTempSymbol(
"cfi",
true);
155 getStreamer().EmitLabel(Label);
159 bool X86WinCOFFTargetStreamer::emitFPOProc(
const MCSymbol *ProcSym,
160 unsigned ParamsSize,
SMLoc L) {
161 if (haveOpenFPOData()) {
162 getContext().reportError(
163 L,
"opening new .cv_fpo_proc before closing previous frame");
166 CurFPOData = llvm::make_unique<FPOData>();
167 CurFPOData->Function = ProcSym;
168 CurFPOData->Begin = emitFPOLabel();
169 CurFPOData->ParamsSize = ParamsSize;
173 bool X86WinCOFFTargetStreamer::emitFPOEndProc(
SMLoc L) {
174 if (!haveOpenFPOData()) {
175 getContext().reportError(L,
".cv_fpo_endproc must appear after .cv_proc");
178 if (!CurFPOData->PrologueEnd) {
180 if (!CurFPOData->Instructions.empty()) {
181 getContext().reportError(L,
"missing .cv_fpo_endprologue");
182 CurFPOData->Instructions.clear();
187 CurFPOData->PrologueEnd = CurFPOData->Begin;
190 CurFPOData->End = emitFPOLabel();
191 const MCSymbol *Fn = CurFPOData->Function;
192 AllFPOData.insert({Fn, std::move(CurFPOData)});
196 bool X86WinCOFFTargetStreamer::emitFPOSetFrame(
unsigned Reg,
SMLoc L) {
197 if (checkInFPOPrologue(L))
200 Inst.Label = emitFPOLabel();
201 Inst.Op = FPOInstruction::SetFrame;
202 Inst.RegOrOffset =
Reg;
203 CurFPOData->Instructions.push_back(Inst);
207 bool X86WinCOFFTargetStreamer::emitFPOPushReg(
unsigned Reg,
SMLoc L) {
208 if (checkInFPOPrologue(L))
211 Inst.Label = emitFPOLabel();
212 Inst.Op = FPOInstruction::PushReg;
213 Inst.RegOrOffset =
Reg;
214 CurFPOData->Instructions.push_back(Inst);
218 bool X86WinCOFFTargetStreamer::emitFPOStackAlloc(
unsigned StackAlloc,
SMLoc L) {
219 if (checkInFPOPrologue(L))
222 Inst.Label = emitFPOLabel();
223 Inst.Op = FPOInstruction::StackAlloc;
224 Inst.RegOrOffset = StackAlloc;
225 CurFPOData->Instructions.push_back(Inst);
229 bool X86WinCOFFTargetStreamer::emitFPOEndPrologue(
SMLoc L) {
230 if (checkInFPOPrologue(L))
232 CurFPOData->PrologueEnd = emitFPOLabel();
237 struct RegSaveOffset {
238 RegSaveOffset(
unsigned Reg,
unsigned Offset) : Reg(Reg), Offset(Offset) {}
244 struct FPOStateMachine {
245 explicit FPOStateMachine(
const FPOData *FPO) : FPO(FPO) {}
247 const FPOData *
FPO =
nullptr;
248 unsigned FrameReg = 0;
249 unsigned FrameRegOff = 0;
250 unsigned CurOffset = 0;
251 unsigned LocalSize = 0;
252 unsigned SavedRegSize = 0;
275 case X86::EBP: OS <<
"$ebp";
break;
276 case X86::EIP: OS <<
"$eip";
break;
286 unsigned CurFlags = Flags;
287 if (Label == FPO->Begin)
296 FuncOS <<
"$T0 " <<
printFPOReg(MRI, FrameReg) <<
" " << FrameRegOff
303 FuncOS <<
"$T0 .raSearch = ";
307 FuncOS <<
"$eip $T0 ^ = $esp $T0 4 + = ";
310 for (RegSaveOffset RO : RegSaveOffsets)
311 FuncOS <<
printFPOReg(MRI, RO.Reg) <<
" $T0 " << RO.Offset <<
" - ^ = ";
318 unsigned MaxStackSize = 0;
343 bool X86WinCOFFTargetStreamer::emitFPOData(
const MCSymbol *ProcSym,
SMLoc L) {
347 auto I = AllFPOData.find(ProcSym);
348 if (
I == AllFPOData.end()) {
353 const FPOData *FPO =
I->second.get();
354 assert(FPO->Begin && FPO->End && FPO->PrologueEnd &&
"missing FPO label");
369 FPOStateMachine FSM(FPO);
371 FSM.emitFrameDataRecord(OS, FPO->Begin);
372 for (
const FPOInstruction &Inst : FPO->Instructions) {
374 case FPOInstruction::PushReg:
376 FSM.SavedRegSize += 4;
377 FSM.RegSaveOffsets.push_back({Inst.RegOrOffset, FSM.CurOffset});
379 case FPOInstruction::SetFrame:
380 FSM.FrameReg = Inst.RegOrOffset;
381 FSM.FrameRegOff = FSM.CurOffset;
383 case FPOInstruction::StackAlloc:
384 FSM.CurOffset += Inst.RegOrOffset;
385 FSM.LocalSize += Inst.RegOrOffset;
391 FSM.emitFrameDataRecord(OS, Inst.Label);
405 return new X86WinCOFFAsmTargetStreamer(S, OS, *InstPrinter);
414 return new X86WinCOFFTargetStreamer(S);
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Compute iterated dominance frontiers using a linear time algorithm.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
MCTargetStreamer * createX86ObjectTargetStreamer(MCStreamer &OS, const MCSubtargetInfo &STI)
Implements X86-only directives for object files.
Target specific streamer interface.
std::pair< StringRef, unsigned > addToStringTable(StringRef S)
Add something to the string table.
A raw_ostream that writes to an SmallVector or SmallString.
const Triple & getTargetTriple() const
MCContext & getContext() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Context object for machine code objects.
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Streaming machine code generation interface.
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
unsigned const MachineRegisterInfo * MRI
bool isOSBinFormatCOFF() const
Tests whether the OS uses the COFF binary format.
PowerPC Reduce CR logical Operation
static Printable printFPOReg(const MCRegisterInfo *MRI, unsigned LLVMReg)
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
void reportError(SMLoc L, const Twine &Msg)
MCTargetStreamer * createX86AsmTargetStreamer(MCStreamer &S, formatted_raw_ostream &OS, MCInstPrinter *InstPrint, bool isVerboseAsm)
Implements X86-only directives for assembly emission.
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
StringRef str()
Return a StringRef for the vector contents.
X86 target streamer implementing x86-only assembly directives.
int getCodeViewRegNum(unsigned RegNum) const
Map a target register to an equivalent CodeView register number.
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Generic base class for all target subtargets.
StringRef getName() const
getName - Get the symbol name.
CodeViewContext & getCVContext()
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MCRegisterInfo * getRegisterInfo() const
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
This class implements an extremely fast bulk output stream that can only output to a stream...
Simple wrapper around std::function<void(raw_ostream&)>.
Represents a location in source code.
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Holds state from .cv_file and .cv_loc directives for later emission.