1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[StackMaps] Be explicit about label formation [NFC] (try 2)

Recommit after making the same API change in non-x86 targets.  This has been build for all targets, and tested for effected ones.  Why the difference?  Because my disk filled up when I tried make check for all.

For auto-padding assembler support, we'll need to bundle the label with the instructions (nops or call sequences) so that they don't get separated.  This just rearranges the code to make the upcoming change more obvious.
This commit is contained in:
Philip Reames 2019-12-19 14:03:19 -08:00
parent cda3149bb7
commit fe5f5af18a
6 changed files with 69 additions and 29 deletions

View File

@ -266,13 +266,16 @@ public:
/// Generate a stackmap record for a stackmap instruction. /// Generate a stackmap record for a stackmap instruction.
/// ///
/// MI must be a raw STACKMAP, not a PATCHPOINT. /// MI must be a raw STACKMAP, not a PATCHPOINT.
void recordStackMap(const MachineInstr &MI); void recordStackMap(const MCSymbol &L,
const MachineInstr &MI);
/// Generate a stackmap record for a patchpoint instruction. /// Generate a stackmap record for a patchpoint instruction.
void recordPatchPoint(const MachineInstr &MI); void recordPatchPoint(const MCSymbol &L,
const MachineInstr &MI);
/// Generate a stackmap record for a statepoint instruction. /// Generate a stackmap record for a statepoint instruction.
void recordStatepoint(const MachineInstr &MI); void recordStatepoint(const MCSymbol &L,
const MachineInstr &MI);
/// If there is any stack map data, create a stack map section and serialize /// If there is any stack map data, create a stack map section and serialize
/// the map info into it. This clears the stack map data structures /// the map info into it. This clears the stack map data structures
@ -306,12 +309,15 @@ private:
/// registers that need to be recorded in the stackmap. /// registers that need to be recorded in the stackmap.
LiveOutVec parseRegisterLiveOutMask(const uint32_t *Mask) const; LiveOutVec parseRegisterLiveOutMask(const uint32_t *Mask) const;
/// This should be called by the MC lowering code _immediately_ before /// Record the locations of the operands of the provided instruction in a
/// lowering the MI to an MCInst. It records where the operands for the /// record keyed by the provided label. For instructions w/AnyReg calling
/// instruction are stored, and outputs a label to record the offset of /// convention the return register is also recorded if requested. For
/// the call from the start of the text section. In special cases (e.g. AnyReg /// STACKMAP, and PATCHPOINT the label is expected to immediately *preceed*
/// calling convention) the return register is also recorded if requested. /// lowering of the MI to MCInsts. For STATEPOINT, it expected to
void recordStackMapOpers(const MachineInstr &MI, uint64_t ID, /// immediately *follow*. It's not clear this difference was intentional,
/// but it exists today.
void recordStackMapOpers(const MCSymbol &L,
const MachineInstr &MI, uint64_t ID,
MachineInstr::const_mop_iterator MOI, MachineInstr::const_mop_iterator MOI,
MachineInstr::const_mop_iterator MOE, MachineInstr::const_mop_iterator MOE,
bool recordResult = false); bool recordResult = false);

View File

@ -294,14 +294,13 @@ StackMaps::parseRegisterLiveOutMask(const uint32_t *Mask) const {
return LiveOuts; return LiveOuts;
} }
void StackMaps::recordStackMapOpers(const MachineInstr &MI, uint64_t ID, void StackMaps::recordStackMapOpers(const MCSymbol &MILabel,
const MachineInstr &MI, uint64_t ID,
MachineInstr::const_mop_iterator MOI, MachineInstr::const_mop_iterator MOI,
MachineInstr::const_mop_iterator MOE, MachineInstr::const_mop_iterator MOE,
bool recordResult) { bool recordResult) {
MCContext &OutContext = AP.OutStreamer->getContext(); MCContext &OutContext = AP.OutStreamer->getContext();
MCSymbol *MILabel = OutContext.createTempSymbol();
AP.OutStreamer->EmitLabel(MILabel);
LocationVec Locations; LocationVec Locations;
LiveOutVec LiveOuts; LiveOutVec LiveOuts;
@ -340,7 +339,7 @@ void StackMaps::recordStackMapOpers(const MachineInstr &MI, uint64_t ID,
// Create an expression to calculate the offset of the callsite from function // Create an expression to calculate the offset of the callsite from function
// entry. // entry.
const MCExpr *CSOffsetExpr = MCBinaryExpr::createSub( const MCExpr *CSOffsetExpr = MCBinaryExpr::createSub(
MCSymbolRefExpr::create(MILabel, OutContext), MCSymbolRefExpr::create(&MILabel, OutContext),
MCSymbolRefExpr::create(AP.CurrentFnSymForSize, OutContext), OutContext); MCSymbolRefExpr::create(AP.CurrentFnSymForSize, OutContext), OutContext);
CSInfos.emplace_back(CSOffsetExpr, ID, std::move(Locations), CSInfos.emplace_back(CSOffsetExpr, ID, std::move(Locations),
@ -360,22 +359,23 @@ void StackMaps::recordStackMapOpers(const MachineInstr &MI, uint64_t ID,
FnInfos.insert(std::make_pair(AP.CurrentFnSym, FunctionInfo(FrameSize))); FnInfos.insert(std::make_pair(AP.CurrentFnSym, FunctionInfo(FrameSize)));
} }
void StackMaps::recordStackMap(const MachineInstr &MI) { void StackMaps::recordStackMap(const MCSymbol &L, const MachineInstr &MI) {
assert(MI.getOpcode() == TargetOpcode::STACKMAP && "expected stackmap"); assert(MI.getOpcode() == TargetOpcode::STACKMAP && "expected stackmap");
StackMapOpers opers(&MI); StackMapOpers opers(&MI);
const int64_t ID = MI.getOperand(PatchPointOpers::IDPos).getImm(); const int64_t ID = MI.getOperand(PatchPointOpers::IDPos).getImm();
recordStackMapOpers(MI, ID, std::next(MI.operands_begin(), opers.getVarIdx()), recordStackMapOpers(L, MI, ID, std::next(MI.operands_begin(),
opers.getVarIdx()),
MI.operands_end()); MI.operands_end());
} }
void StackMaps::recordPatchPoint(const MachineInstr &MI) { void StackMaps::recordPatchPoint(const MCSymbol &L, const MachineInstr &MI) {
assert(MI.getOpcode() == TargetOpcode::PATCHPOINT && "expected patchpoint"); assert(MI.getOpcode() == TargetOpcode::PATCHPOINT && "expected patchpoint");
PatchPointOpers opers(&MI); PatchPointOpers opers(&MI);
const int64_t ID = opers.getID(); const int64_t ID = opers.getID();
auto MOI = std::next(MI.operands_begin(), opers.getStackMapStartIdx()); auto MOI = std::next(MI.operands_begin(), opers.getStackMapStartIdx());
recordStackMapOpers(MI, ID, MOI, MI.operands_end(), recordStackMapOpers(L, MI, ID, MOI, MI.operands_end(),
opers.isAnyReg() && opers.hasDef()); opers.isAnyReg() && opers.hasDef());
#ifndef NDEBUG #ifndef NDEBUG
@ -390,14 +390,14 @@ void StackMaps::recordPatchPoint(const MachineInstr &MI) {
#endif #endif
} }
void StackMaps::recordStatepoint(const MachineInstr &MI) { void StackMaps::recordStatepoint(const MCSymbol &L, const MachineInstr &MI) {
assert(MI.getOpcode() == TargetOpcode::STATEPOINT && "expected statepoint"); assert(MI.getOpcode() == TargetOpcode::STATEPOINT && "expected statepoint");
StatepointOpers opers(&MI); StatepointOpers opers(&MI);
// Record all the deopt and gc operands (they're contiguous and run from the // Record all the deopt and gc operands (they're contiguous and run from the
// initial index to the end of the operand list) // initial index to the end of the operand list)
const unsigned StartIdx = opers.getVarIdx(); const unsigned StartIdx = opers.getVarIdx();
recordStackMapOpers(MI, opers.getID(), MI.operands_begin() + StartIdx, recordStackMapOpers(L, MI, opers.getID(), MI.operands_begin() + StartIdx,
MI.operands_end(), false); MI.operands_end(), false);
} }

View File

@ -854,7 +854,11 @@ void AArch64AsmPrinter::LowerSTACKMAP(MCStreamer &OutStreamer, StackMaps &SM,
const MachineInstr &MI) { const MachineInstr &MI) {
unsigned NumNOPBytes = StackMapOpers(&MI).getNumPatchBytes(); unsigned NumNOPBytes = StackMapOpers(&MI).getNumPatchBytes();
SM.recordStackMap(MI); auto &Ctx = OutStreamer.getContext();
MCSymbol *MILabel = Ctx.createTempSymbol();
OutStreamer.EmitLabel(MILabel);
SM.recordStackMap(*MILabel, MI);
assert(NumNOPBytes % 4 == 0 && "Invalid number of NOP bytes requested!"); assert(NumNOPBytes % 4 == 0 && "Invalid number of NOP bytes requested!");
// Scan ahead to trim the shadow. // Scan ahead to trim the shadow.
@ -880,7 +884,10 @@ void AArch64AsmPrinter::LowerSTACKMAP(MCStreamer &OutStreamer, StackMaps &SM,
// [<def>], <id>, <numBytes>, <target>, <numArgs> // [<def>], <id>, <numBytes>, <target>, <numArgs>
void AArch64AsmPrinter::LowerPATCHPOINT(MCStreamer &OutStreamer, StackMaps &SM, void AArch64AsmPrinter::LowerPATCHPOINT(MCStreamer &OutStreamer, StackMaps &SM,
const MachineInstr &MI) { const MachineInstr &MI) {
SM.recordPatchPoint(MI); auto &Ctx = OutStreamer.getContext();
MCSymbol *MILabel = Ctx.createTempSymbol();
OutStreamer.EmitLabel(MILabel);
SM.recordPatchPoint(*MILabel, MI);
PatchPointOpers Opers(&MI); PatchPointOpers Opers(&MI);

View File

@ -359,8 +359,12 @@ void PPCAsmPrinter::EmitEndOfAsmFile(Module &M) {
void PPCAsmPrinter::LowerSTACKMAP(StackMaps &SM, const MachineInstr &MI) { void PPCAsmPrinter::LowerSTACKMAP(StackMaps &SM, const MachineInstr &MI) {
unsigned NumNOPBytes = MI.getOperand(1).getImm(); unsigned NumNOPBytes = MI.getOperand(1).getImm();
auto &Ctx = OutStreamer->getContext();
MCSymbol *MILabel = Ctx.createTempSymbol();
OutStreamer->EmitLabel(MILabel);
SM.recordStackMap(MI); SM.recordStackMap(*MILabel, MI);
assert(NumNOPBytes % 4 == 0 && "Invalid number of NOP bytes requested!"); assert(NumNOPBytes % 4 == 0 && "Invalid number of NOP bytes requested!");
// Scan ahead to trim the shadow. // Scan ahead to trim the shadow.
@ -385,7 +389,11 @@ void PPCAsmPrinter::LowerSTACKMAP(StackMaps &SM, const MachineInstr &MI) {
// Lower a patchpoint of the form: // Lower a patchpoint of the form:
// [<def>], <id>, <numBytes>, <target>, <numArgs> // [<def>], <id>, <numBytes>, <target>, <numArgs>
void PPCAsmPrinter::LowerPATCHPOINT(StackMaps &SM, const MachineInstr &MI) { void PPCAsmPrinter::LowerPATCHPOINT(StackMaps &SM, const MachineInstr &MI) {
SM.recordPatchPoint(MI); auto &Ctx = OutStreamer->getContext();
MCSymbol *MILabel = Ctx.createTempSymbol();
OutStreamer->EmitLabel(MILabel);
SM.recordPatchPoint(*MILabel, MI);
PatchPointOpers Opers(&MI); PatchPointOpers Opers(&MI);
unsigned EncodedBytes = 0; unsigned EncodedBytes = 0;

View File

@ -583,7 +583,11 @@ void SystemZAsmPrinter::LowerSTACKMAP(const MachineInstr &MI) {
unsigned NumNOPBytes = MI.getOperand(1).getImm(); unsigned NumNOPBytes = MI.getOperand(1).getImm();
SM.recordStackMap(MI); auto &Ctx = OutStreamer->getContext();
MCSymbol *MILabel = Ctx.createTempSymbol();
OutStreamer->EmitLabel(MILabel);
SM.recordStackMap(*MILabel, MI);
assert(NumNOPBytes % 2 == 0 && "Invalid number of NOP bytes requested!"); assert(NumNOPBytes % 2 == 0 && "Invalid number of NOP bytes requested!");
// Scan ahead to trim the shadow. // Scan ahead to trim the shadow.
@ -612,7 +616,11 @@ void SystemZAsmPrinter::LowerSTACKMAP(const MachineInstr &MI) {
// [<def>], <id>, <numBytes>, <target>, <numArgs> // [<def>], <id>, <numBytes>, <target>, <numArgs>
void SystemZAsmPrinter::LowerPATCHPOINT(const MachineInstr &MI, void SystemZAsmPrinter::LowerPATCHPOINT(const MachineInstr &MI,
SystemZMCInstLower &Lower) { SystemZMCInstLower &Lower) {
SM.recordPatchPoint(MI); auto &Ctx = OutStreamer->getContext();
MCSymbol *MILabel = Ctx.createTempSymbol();
OutStreamer->EmitLabel(MILabel);
SM.recordPatchPoint(*MILabel, MI);
PatchPointOpers Opers(&MI); PatchPointOpers Opers(&MI);
unsigned EncodedBytes = 0; unsigned EncodedBytes = 0;

View File

@ -1194,7 +1194,10 @@ void X86AsmPrinter::LowerSTATEPOINT(const MachineInstr &MI,
// Record our statepoint node in the same section used by STACKMAP // Record our statepoint node in the same section used by STACKMAP
// and PATCHPOINT // and PATCHPOINT
SM.recordStatepoint(MI); auto &Ctx = OutStreamer->getContext();
MCSymbol *MILabel = Ctx.createTempSymbol();
OutStreamer->EmitLabel(MILabel);
SM.recordStatepoint(*MILabel, MI);
} }
void X86AsmPrinter::LowerFAULTING_OP(const MachineInstr &FaultingMI, void X86AsmPrinter::LowerFAULTING_OP(const MachineInstr &FaultingMI,
@ -1286,7 +1289,12 @@ void X86AsmPrinter::LowerPATCHABLE_OP(const MachineInstr &MI,
// <id>, <shadowBytes>, ... // <id>, <shadowBytes>, ...
void X86AsmPrinter::LowerSTACKMAP(const MachineInstr &MI) { void X86AsmPrinter::LowerSTACKMAP(const MachineInstr &MI) {
SMShadowTracker.emitShadowPadding(*OutStreamer, getSubtargetInfo()); SMShadowTracker.emitShadowPadding(*OutStreamer, getSubtargetInfo());
SM.recordStackMap(MI);
auto &Ctx = OutStreamer->getContext();
MCSymbol *MILabel = Ctx.createTempSymbol();
OutStreamer->EmitLabel(MILabel);
SM.recordStackMap(*MILabel, MI);
unsigned NumShadowBytes = MI.getOperand(1).getImm(); unsigned NumShadowBytes = MI.getOperand(1).getImm();
SMShadowTracker.reset(NumShadowBytes); SMShadowTracker.reset(NumShadowBytes);
} }
@ -1299,7 +1307,10 @@ void X86AsmPrinter::LowerPATCHPOINT(const MachineInstr &MI,
SMShadowTracker.emitShadowPadding(*OutStreamer, getSubtargetInfo()); SMShadowTracker.emitShadowPadding(*OutStreamer, getSubtargetInfo());
SM.recordPatchPoint(MI); auto &Ctx = OutStreamer->getContext();
MCSymbol *MILabel = Ctx.createTempSymbol();
OutStreamer->EmitLabel(MILabel);
SM.recordPatchPoint(*MILabel, MI);
PatchPointOpers opers(&MI); PatchPointOpers opers(&MI);
unsigned ScratchIdx = opers.getNextScratchIdx(); unsigned ScratchIdx = opers.getNextScratchIdx();