@@ -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+ 
143157bool  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
0 commit comments