~StackMapShadowTracker();
void startFunction(MachineFunction &MF);
void count(MCInst &Inst, const MCSubtargetInfo &STI);
+
+ // Called to signal the start of a shadow of RequiredSize bytes.
void reset(unsigned RequiredSize) {
RequiredShadowSize = RequiredSize;
CurrentShadowSize = 0;
- Count = true;
+ InShadow = true;
}
+
+ // Called before every stackmap/patchpoint, and at the end of basic blocks,
+ // to emit any necessary padding-NOPs.
void emitShadowPadding(MCStreamer &OutStreamer, const MCSubtargetInfo &STI);
private:
TargetMachine &TM;
std::unique_ptr<MCCodeEmitter> CodeEmitter;
- bool Count;
+ bool InShadow;
+
+ // RequiredShadowSize holds the length of the shadow specified in the most
+ // recently encountered STACKMAP instruction.
+ // CurrentShadowSize counts the number of bytes encoded since the most
+ // recently encountered STACKMAP, stopping when that number is greater than
+ // or equal to RequiredShadowSize.
unsigned RequiredShadowSize, CurrentShadowSize;
};
namespace llvm {
X86AsmPrinter::StackMapShadowTracker::StackMapShadowTracker(TargetMachine &TM)
- : TM(TM), Count(false), RequiredShadowSize(0), CurrentShadowSize(0) {}
+ : TM(TM), InShadow(false), RequiredShadowSize(0), CurrentShadowSize(0) {}
X86AsmPrinter::StackMapShadowTracker::~StackMapShadowTracker() {}
void X86AsmPrinter::StackMapShadowTracker::count(MCInst &Inst,
const MCSubtargetInfo &STI) {
- if (Count) {
+ if (InShadow) {
SmallString<256> Code;
SmallVector<MCFixup, 4> Fixups;
raw_svector_ostream VecOS(Code);
VecOS.flush();
CurrentShadowSize += Code.size();
if (CurrentShadowSize >= RequiredShadowSize)
- Count = false; // The shadow is big enough. Stop counting.
+ InShadow = false; // The shadow is big enough. Stop counting.
}
}
void X86AsmPrinter::StackMapShadowTracker::emitShadowPadding(
MCStreamer &OutStreamer, const MCSubtargetInfo &STI) {
- if (Count && CurrentShadowSize < RequiredShadowSize)
+ if (InShadow && CurrentShadowSize < RequiredShadowSize) {
+ InShadow = false;
EmitNops(OutStreamer, RequiredShadowSize - CurrentShadowSize,
TM.getSubtarget<X86Subtarget>().is64Bit(), STI);
- Count = false;
+ }
}
void X86AsmPrinter::EmitAndCountInstruction(MCInst &Inst) {