[LLVMdev] CollectorRegistry
Gordon Henriksen
gordonhenriksen at me.com
Wed Jul 23 08:30:06 PDT 2008
On 2008-07-23, at 08:58, Simon Ask Ulsnes wrote:
> I am attempting to write a garbage collector for LLVM, and the tiny
> example in the docs at http://llvm.org/releases/2.3/docs/GarbageCollection.html
> gives this line:
>
> CollectorRegistry::Add<MyCollector>
> X("mygc", "My bespoke garbage collector.");
>
> My question is now: Am I supposed to instantiate my collector
> manually, and tell LLVM about it, or can the Registry instantiate
> it, and it that case, how to go about that? I haven't been able to
> deduce a way to get a pointer to my collector from the doxygen docs
> or the header files, so I hope that you can help me here. :-)
Hi Simon,
The compiler framework will instantiate and call into your Collector
subclass automatically as required. The CollectorRegistry::Add<>
instance advertises your class to the framework so it can do this.
Your Collector class needs to have a default constructor in order to
insantiate the Add<> template.
The framework decides which Collector to use based upon the 'gc'
attribute of a function:
define void @f() gc "mygc" {
...
}
This string must correspond to the first argument to the
CollectorRegistry::Add<> constructor.
The second argument to the constructor is, I think, "purely
informational" for collectors. For the related TargetMachineRegistry,
the second argument appears in --help output.
Hope that helps,
Gordon
More information about the llvm-dev
mailing list