[LLVMdev] Writing an address space re-numbering pass?

Dan Liew dan at su-root.co.uk
Fri May 16 06:41:36 PDT 2014


Hi,

I'm trying to figure how to write a Module pass that globally
renumbers address space numbers e.g.
>From -> To

0 -> 1
1 -> 3
2 -> 2
3 -> 4
4 -> 999

I see that the address space number is a property that belongs to
Types[1] and that types are immutable, so I'm not sure how to
correctly implement this. But if it is I'd greatly appreciate advise
on how to do this.

- What do I need to iterate over? I couldn't see an obvious way to
iterate over Types belonging to a module, so do I just need to iterate
over "everything" (i.e. Functions, globals, aliases and instructions)
and somehow iterate over the types that they use? Doing it in the way
I just described (if it's even possible) sounds like a disaster
because types are uniqued so I would likely visit the same type
multiple times and might accidently change the types address space
again. I could use a SmallPtrSet to make sure I don't visit a type
more than once but the fact I would need to do this hints to me that
this is probably the wrong approach.

- How can I change the address space number associated with a Type?
Looking at the implementation it seems that ``getAddressSpace()`` just
returns ``getSubclassData()`` and it also looks like I can use
``setSubClassData()`` to set this. What is "Subclass" data for? If I
try to set the address space number this way it seems like a
**massive** hack which is already broken if Subclass data is used for
other things inside LLVM.

Just in case someone asks, I can't change the frontend that produces
the Module so I need a way of changing the address space numbers in a
pre-existing LLVM module.

[1] http://llvm.org/docs/doxygen/html/classllvm_1_1Type.html

Thanks,
-- 
Dan Liew



More information about the llvm-dev mailing list