Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions llvm/lib/CodeGen/AsmPrinter/OxCamlGCPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ static unsigned mapLLVMDwarfRegToOxCamlIndex(unsigned DwarfRegNum) {
}
}

static uint64_t stackOffsetOfID(uint64_t ID) {
return ID & ((1ull << 16) - 1) & ~(1ull);
}

static uint64_t allocSizeOfID(uint64_t ID) {
return ID >> 16;
}

static bool IDHasAlloc(uint64_t ID) {
return ID & 1ull;
}

static const int allocMask = 2;

bool OxCamlGCMetadataPrinter::emitStackMaps(Module &M, StackMaps &SM, AsmPrinter &AP) {
MCStreamer &OS = *AP.OutStreamer;
unsigned PtrSize = M.getDataLayout().getPointerSize(); // Can only be 8 for now
Expand Down Expand Up @@ -173,10 +187,16 @@ bool OxCamlGCMetadataPrinter::emitStackMaps(Module &M, StackMaps &SM, AsmPrinter

// frame_data
uint64_t FrameSize = CSI.CSFunctionInfo.StaticStackSize;
if (CSI.ID != StatepointDirectives::DefaultStatepointID)
FrameSize += CSI.ID; // Stack offset from OxCaml
FrameSize += PtrSize; // Return address

if (CSI.ID != StatepointDirectives::DefaultStatepointID) {
// Alloc bit
if (IDHasAlloc(CSI.ID)) FrameSize |= allocMask;

// Stack offset from OxCaml
FrameSize += stackOffsetOfID(CSI.ID);
}

if (FrameSize >= 1 << 16)
report_fatal_error("Long frames not supported for OxCaml GC: FrameSize = "
+ Twine(FrameSize));
Expand Down Expand Up @@ -238,6 +258,11 @@ bool OxCamlGCMetadataPrinter::emitStackMaps(Module &M, StackMaps &SM, AsmPrinter
OS.emitInt16(EncodedReg);
}

if (IDHasAlloc(CSI.ID)) {
OS.emitInt8(1);
OS.emitInt8(allocSizeOfID(CSI.ID));
}

OS.emitValueToAlignment(Align(PtrSize));
}

Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3087,6 +3087,11 @@ bool RewriteStatepointsForGC::runOnFunction(Function &F, DominatorTree &DT,
"Don't expect any other calls here!");
return false;
}

// `musttail` calls wrapped in statepoints fail to verify due to
// the intrinsic using variadic arguments.
if (Call->isMustTailCall()) return false;

return true;
}
return false;
Expand Down