[LLVMdev] getting started with IR needing GC

Gordon Henriksen gordonhenriksen at mac.com
Tue Apr 29 09:43:35 PDT 2008

On 2008-04-29, at 01:51, Jonathan S. Shapiro wrote:

> Gordon: assume, for a moment, that I'm willing to go the extra  
> several miles to do this type if thing in my GC implementation. How  
> might I go about getting per-call-site register typings, register  
> save locations, and return-pc information extracted for use by this  
> hypothetical sophisticated walker?

There are two complementary interfaces here, which mesh neatly into  
the existing collection of GC algorithms exposed by Collector.

The first is liveness analysis, for stack roots as well as register  
maps. The Collector API is set up for this, although it is not yet  

The second is register maps (which of course are necessarily liveness  
accurate). The Collector API is not presently set up for this, but I  
expect the API additions would be rather simple:

  MyCollector() {
+  // Please don't spill roots to stack slots at safe points.
+  RegisterRoots = true;

  void MyCollector::finishAssembly(std::ostream &OS, AsmPrinter &AP,
                                   const TargetAsmInfo &TAI) {
    // Iterate functions.
    for (iterator I = begin(), E = end(); I != E; ++I) {
      // Iterate safe points.
      for (CollectorMetadata::iterator PI = MD.begin(),
                                       PE = MD.end(); PI != PE; ++PI) {
        // Live stack roots.
        for (CollectorMetadata::live_iterator LI = MD.live_begin(PI),
                                              LE = MD.live_end(PI);
                                              LI != LE; ++LI) {
          // Print its offset within the stack frame.
          AP.EOL("stack offset");
+      for (CollectorMetadata::reg_iterator RI = MD.reg_begin(PI),
+                                           RE = MD.reg_end(PI);
+                                           RI != RE; ++RI) {
+        int TargetRegNum = RI->Register;
+        Constant *RootMetadata = RI->Metadata;
+      }

Both of these require a more sophisticated SelectionDAG representation  
of GC pointers. I'm still mulling this representation over, but I  
think the derived pointer problem could be solved simultaneously.

That done, I think liveness w/ register roots would be the first  
feature to be enabled.

Next, liveness w/o register roots. (This is simply liveness with  
register roots, where each root is forcibly spilled.)

— Gordon

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080429/bbe81426/attachment.html>

More information about the llvm-dev mailing list