35 bool emitFPOEndPrologue(
SMLoc L)
override;
36 bool emitFPOEndProc(
SMLoc L)
override;
38 bool emitFPOPushReg(
unsigned Reg,
SMLoc L)
override;
39 bool emitFPOStackAlloc(
unsigned StackAlloc,
SMLoc L)
override;
40 bool emitFPOStackAlign(
unsigned Align,
SMLoc L)
override;
41 bool emitFPOSetFrame(
unsigned Reg,
SMLoc L)
override;
45 struct FPOInstruction {
61 unsigned ParamsSize = 0;
72 std::unique_ptr<FPOData> CurFPOData;
74 bool haveOpenFPOData() {
return !!CurFPOData; }
78 bool checkInFPOPrologue(
SMLoc L);
82 MCContext &getContext() {
return getStreamer().getContext(); }
89 bool emitFPOEndPrologue(
SMLoc L)
override;
90 bool emitFPOEndProc(
SMLoc L)
override;
92 bool emitFPOPushReg(
unsigned Reg,
SMLoc L)
override;
93 bool emitFPOStackAlloc(
unsigned StackAlloc,
SMLoc L)
override;
94 bool emitFPOStackAlign(
unsigned Align,
SMLoc L)
override;
95 bool emitFPOSetFrame(
unsigned Reg,
SMLoc L)
override;
100 unsigned ParamsSize,
SMLoc L) {
101 OS <<
"\t.cv_fpo_proc\t";
102 ProcSym->
print(OS, getStreamer().getContext().getAsmInfo());
103 OS <<
' ' << ParamsSize <<
'\n';
107 bool X86WinCOFFAsmTargetStreamer::emitFPOEndPrologue(
SMLoc L) {
108 OS <<
"\t.cv_fpo_endprologue\n";
112 bool X86WinCOFFAsmTargetStreamer::emitFPOEndProc(
SMLoc L) {
113 OS <<
"\t.cv_fpo_endproc\n";
117 bool X86WinCOFFAsmTargetStreamer::emitFPOData(
const MCSymbol *ProcSym,
119 OS <<
"\t.cv_fpo_data\t";
120 ProcSym->
print(OS, getStreamer().getContext().getAsmInfo());
125 bool X86WinCOFFAsmTargetStreamer::emitFPOPushReg(
unsigned Reg,
SMLoc L) {
126 OS <<
"\t.cv_fpo_pushreg\t";
127 InstPrinter.printRegName(OS, Reg);
132 bool X86WinCOFFAsmTargetStreamer::emitFPOStackAlloc(
unsigned StackAlloc,
134 OS <<
"\t.cv_fpo_stackalloc\t" << StackAlloc <<
'\n';
138 bool X86WinCOFFAsmTargetStreamer::emitFPOStackAlign(
unsigned Align,
SMLoc L) {
139 OS <<
"\t.cv_fpo_stackalign\t" << Align <<
'\n';
143 bool X86WinCOFFAsmTargetStreamer::emitFPOSetFrame(
unsigned Reg,
SMLoc L) {
144 OS <<
"\t.cv_fpo_setframe\t";
145 InstPrinter.printRegName(OS, Reg);
150 bool X86WinCOFFTargetStreamer::checkInFPOPrologue(
SMLoc L) {
151 if (!haveOpenFPOData() || CurFPOData->PrologueEnd) {
152 getContext().reportError(
154 "directive must appear between .cv_fpo_proc and .cv_fpo_endprologue");
160 MCSymbol *X86WinCOFFTargetStreamer::emitFPOLabel() {
161 MCSymbol *
Label = getContext().createTempSymbol(
"cfi",
true);
162 getStreamer().EmitLabel(Label);
166 bool X86WinCOFFTargetStreamer::emitFPOProc(
const MCSymbol *ProcSym,
167 unsigned ParamsSize,
SMLoc L) {
168 if (haveOpenFPOData()) {
169 getContext().reportError(
170 L,
"opening new .cv_fpo_proc before closing previous frame");
173 CurFPOData = std::make_unique<FPOData>();
174 CurFPOData->Function = ProcSym;
175 CurFPOData->Begin = emitFPOLabel();
176 CurFPOData->ParamsSize = ParamsSize;
180 bool X86WinCOFFTargetStreamer::emitFPOEndProc(
SMLoc L) {
181 if (!haveOpenFPOData()) {
182 getContext().reportError(L,
".cv_fpo_endproc must appear after .cv_proc");
185 if (!CurFPOData->PrologueEnd) {
187 if (!CurFPOData->Instructions.empty()) {
188 getContext().reportError(L,
"missing .cv_fpo_endprologue");
189 CurFPOData->Instructions.clear();
194 CurFPOData->PrologueEnd = CurFPOData->Begin;
197 CurFPOData->End = emitFPOLabel();
198 const MCSymbol *Fn = CurFPOData->Function;
199 AllFPOData.insert({Fn, std::move(CurFPOData)});
203 bool X86WinCOFFTargetStreamer::emitFPOSetFrame(
unsigned Reg,
SMLoc L) {
204 if (checkInFPOPrologue(L))
207 Inst.Label = emitFPOLabel();
208 Inst.Op = FPOInstruction::SetFrame;
209 Inst.RegOrOffset =
Reg;
210 CurFPOData->Instructions.push_back(Inst);
214 bool X86WinCOFFTargetStreamer::emitFPOPushReg(
unsigned Reg,
SMLoc L) {
215 if (checkInFPOPrologue(L))
218 Inst.Label = emitFPOLabel();
219 Inst.Op = FPOInstruction::PushReg;
220 Inst.RegOrOffset =
Reg;
221 CurFPOData->Instructions.push_back(Inst);
225 bool X86WinCOFFTargetStreamer::emitFPOStackAlloc(
unsigned StackAlloc,
SMLoc L) {
226 if (checkInFPOPrologue(L))
229 Inst.Label = emitFPOLabel();
230 Inst.Op = FPOInstruction::StackAlloc;
231 Inst.RegOrOffset = StackAlloc;
232 CurFPOData->Instructions.push_back(Inst);
236 bool X86WinCOFFTargetStreamer::emitFPOStackAlign(
unsigned Align,
SMLoc L) {
237 if (checkInFPOPrologue(L))
239 if (!
llvm::any_of(CurFPOData->Instructions, [](
const FPOInstruction &Inst) {
240 return Inst.Op == FPOInstruction::SetFrame;
242 getContext().reportError(
243 L,
"a frame register must be established before aligning the stack");
247 Inst.Label = emitFPOLabel();
248 Inst.Op = FPOInstruction::StackAlign;
249 Inst.RegOrOffset =
Align;
250 CurFPOData->Instructions.push_back(Inst);
254 bool X86WinCOFFTargetStreamer::emitFPOEndPrologue(
SMLoc L) {
255 if (checkInFPOPrologue(L))
257 CurFPOData->PrologueEnd = emitFPOLabel();
262 struct RegSaveOffset {
263 RegSaveOffset(
unsigned Reg,
unsigned Offset) : Reg(Reg), Offset(Offset) {}
269 struct FPOStateMachine {
270 explicit FPOStateMachine(
const FPOData *FPO) : FPO(FPO) {}
272 const FPOData *
FPO =
nullptr;
273 unsigned FrameReg = 0;
274 unsigned FrameRegOff = 0;
275 unsigned CurOffset = 0;
276 unsigned LocalSize = 0;
277 unsigned SavedRegSize = 0;
278 unsigned StackOffsetBeforeAlign = 0;
279 unsigned StackAlign = 0;
302 case X86::EBP: OS <<
"$ebp";
break;
303 case X86::EIP: OS <<
"$eip";
break;
313 unsigned CurFlags = Flags;
314 if (Label == FPO->Begin)
321 assert((StackAlign == 0 || FrameReg != 0) &&
322 "cannot align stack without frame reg");
323 StringRef CFAVar = StackAlign == 0 ?
"$T0" :
"$T1";
327 FuncOS << CFAVar <<
' ' <<
printFPOReg(MRI, FrameReg) <<
' ' << FrameRegOff
335 FuncOS <<
"$T0 " << CFAVar <<
' ' << StackOffsetBeforeAlign <<
" - " 336 << StackAlign <<
" @ = ";
343 FuncOS << CFAVar <<
" .raSearch = ";
347 FuncOS <<
"$eip " << CFAVar <<
" ^ = ";
348 FuncOS <<
"$esp " << CFAVar <<
" 4 + = ";
351 for (RegSaveOffset RO : RegSaveOffsets)
352 FuncOS <<
printFPOReg(MRI, RO.Reg) <<
' ' << CFAVar <<
' ' << RO.Offset
360 unsigned MaxStackSize = 0;
385 bool X86WinCOFFTargetStreamer::emitFPOData(
const MCSymbol *ProcSym,
SMLoc L) {
389 auto I = AllFPOData.find(ProcSym);
390 if (
I == AllFPOData.end()) {
395 const FPOData *FPO =
I->second.get();
396 assert(FPO->Begin && FPO->End && FPO->PrologueEnd &&
"missing FPO label");
411 FPOStateMachine FSM(FPO);
413 FSM.emitFrameDataRecord(OS, FPO->Begin);
414 for (
const FPOInstruction &Inst : FPO->Instructions) {
416 case FPOInstruction::PushReg:
418 FSM.SavedRegSize += 4;
419 FSM.RegSaveOffsets.push_back({Inst.RegOrOffset, FSM.CurOffset});
421 case FPOInstruction::SetFrame:
422 FSM.FrameReg = Inst.RegOrOffset;
423 FSM.FrameRegOff = FSM.CurOffset;
425 case FPOInstruction::StackAlign:
426 FSM.StackOffsetBeforeAlign = FSM.CurOffset;
427 FSM.StackAlign = Inst.RegOrOffset;
429 case FPOInstruction::StackAlloc:
430 FSM.CurOffset += Inst.RegOrOffset;
431 FSM.LocalSize += Inst.RegOrOffset;
437 FSM.emitFrameDataRecord(OS, Inst.Label);
451 return new X86WinCOFFAsmTargetStreamer(S, OS, *InstPrinter);
460 return new X86WinCOFFTargetStreamer(S);
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
This class represents lattice values for constants.
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.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
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.
This struct is a compact representation of a valid (non-zero power of two) alignment.
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.
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.
int getCodeViewRegNum(MCRegister RegNum) const
Map a target register to an equivalent CodeView register number.
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...
StringRef - Represent a constant reference to a string, i.e.
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.