Skip to content

Commit f9a3ade

Browse files
committed
alloc entries in frametables + disable musttail in RS4GC
1 parent 618927c commit f9a3ade

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

llvm/lib/CodeGen/AsmPrinter/OxCamlGCPrinter.cpp

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,20 @@ static unsigned mapLLVMDwarfRegToOxCamlIndex(unsigned DwarfRegNum) {
140140
}
141141
}
142142

143+
static uint64_t stackOffsetOfID(uint64_t ID) {
144+
return ID & ((1ull << 16) - 1) & ~(1ull);
145+
}
146+
147+
static uint64_t allocSizeOfID(uint64_t ID) {
148+
return ID >> 16;
149+
}
150+
151+
static bool IDHasAlloc(uint64_t ID) {
152+
return ID & 1ull;
153+
}
154+
155+
static const int allocMask = 2;
156+
143157
bool OxCamlGCMetadataPrinter::emitStackMaps(Module &M, StackMaps &SM, AsmPrinter &AP) {
144158
MCStreamer &OS = *AP.OutStreamer;
145159
unsigned PtrSize = M.getDataLayout().getPointerSize(); // Can only be 8 for now
@@ -173,10 +187,16 @@ bool OxCamlGCMetadataPrinter::emitStackMaps(Module &M, StackMaps &SM, AsmPrinter
173187

174188
// frame_data
175189
uint64_t FrameSize = CSI.CSFunctionInfo.StaticStackSize;
176-
if (CSI.ID != StatepointDirectives::DefaultStatepointID)
177-
FrameSize += CSI.ID; // Stack offset from OxCaml
178190
FrameSize += PtrSize; // Return address
179191

192+
if (CSI.ID != StatepointDirectives::DefaultStatepointID) {
193+
// Alloc bit
194+
if (IDHasAlloc(CSI.ID)) FrameSize |= allocMask;
195+
196+
// Stack offset from OxCaml
197+
FrameSize += stackOffsetOfID(CSI.ID);
198+
}
199+
180200
if (FrameSize >= 1 << 16)
181201
report_fatal_error("Long frames not supported for OxCaml GC: FrameSize = "
182202
+ Twine(FrameSize));
@@ -238,6 +258,11 @@ bool OxCamlGCMetadataPrinter::emitStackMaps(Module &M, StackMaps &SM, AsmPrinter
238258
OS.emitInt16(EncodedReg);
239259
}
240260

261+
if (IDHasAlloc(CSI.ID)) {
262+
OS.emitInt8(1);
263+
OS.emitInt8(allocSizeOfID(CSI.ID));
264+
}
265+
241266
OS.emitValueToAlignment(Align(PtrSize));
242267
}
243268

llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3087,6 +3087,11 @@ bool RewriteStatepointsForGC::runOnFunction(Function &F, DominatorTree &DT,
30873087
"Don't expect any other calls here!");
30883088
return false;
30893089
}
3090+
3091+
// `musttail` calls wrapped in statepoints fail to verify due to
3092+
// the intrinsic using variadic arguments.
3093+
if (Call->isMustTailCall()) return false;
3094+
30903095
return true;
30913096
}
30923097
return false;

0 commit comments

Comments
 (0)