[LLVMdev] [proposal] Extensible IR metadata

Jeffrey Yasskin jyasskin at google.com
Fri Sep 11 17:15:56 PDT 2009


On Fri, Sep 11, 2009 at 3:23 PM, David Greene <dag at cray.com> wrote:
> On Friday 11 September 2009 15:20, Jeffrey Yasskin wrote:
>> StaticTypeId is a new class that maps each of its template arguments
>> to a small, unique integer, which may be different in different
>> executions.
>
> How does this work across compilation units?  How about with shared LLVM
> libraries?  These kinds of global unique IDs are notoriously difficult
> to get right.  I'd suggest using a third-party unique-id library.  Boost.UUID
> is one possibility but not the only one.

template<typename T>
class StaticTypeId {
  static int id;
}
extern int NextStaticTypeId;  // Initialized to 0. Possibly an atomic
type instead.
template<typename T> int StaticTypeId<T>::id = NextStaticTypeId++;

This relies on the compiler uniquing static member variables across
translation units, and I've never tested that across shared library
boundaries.  The initializer didn't work with gcc-2 (there was a
workaround), but I believe it works with gcc-4. I've never tested it
with MSVC. We can also use static local variables, which would have a
different set of bugs, but they're very slightly slower to access.

Since there's a registration step, we could also use Pass-style IDs,
and have the registration fill them in, which would avoid uniquing
problems.




More information about the llvm-dev mailing list