[PATCH] Add a jumptable attribute and support for creating jump-instruction tables

Rafael EspĂ­ndola rafael.espindola at gmail.com
Wed May 21 12:01:01 PDT 2014


> Not quite. The jumptable code creates a declaration (but not a
> definition) that will later be satisfied by generated assembly in
> AsmPrinter. It then goes and replaces all address-taken uses of the
> function symbol with the declaration. So, the problem happens when
> there's a statement like
>
> @falias = alias i32 ()* @f
>
> where @f has the jumptable attribute and is being replaced with a
> declared but not defined function, say @f_JT. Ideally, I'd just be
> able to replace @f with @f_JT, but since there's no definition for
> @f_JT, the GlobalAlias code balks, for good reasons, as you explained.
>
> It happens that this declaration in this case is going to resolve into
> a real symbol in the same asm file, but there's no way the code can
> tell that.

This seems like a representation issue. Can't you create a fake global
variable (like llvm.used for example) that during codegen gets
converted in the same way the declaration is currently?

> So, instead, part of my pass looks for GlobalAliases to find ones that
> need to be treated in the same way as the jumptable functions they
> alias. I don't have a problem with adding this little bit of extra
> code to handle aliases correctly, but I'm happy to change it if
> there's a better way to do it.
>
>>
>> When you say that replaceUsesOfWithOnConstant doesn't work with
>> aliases you mean that you cannot pass an alias as the From argument?
>> That should be just an oversight, I don't think there is any
>> fundamental reason why that would not work. What is the issues that
>> you are seeing?
>
> No, that case works fine, and I do it extensively in this version of
> the code; that's how I replace the GlobalAliases to jumptable
> Functions that I find. The thing that doesn't work is calling
>
> C->replaceUsesOfWithOnConstant(GV, V, U)
>
> when C is a GlobalAlias. I've just looked at the code, though, and it
> looks like this is a red herring: you can replace alias targets with
> other calls, so it doesn't matter. In the end, the thing that prevents
> me from making this replacement is having the replacement function be
> a declaration and not a defined function.

I don't think replaceUsesOfWithOnConstant is supposed to be used with
any GlobalValue. Those are handled by replaceAllUsesWith.

Cheers,
Rafael



More information about the llvm-commits mailing list