[llvm-dev] How to know the sub-class of a Value class?

Jeremy Lakeman via llvm-dev llvm-dev at lists.llvm.org
Mon Jun 12 08:51:56 PDT 2017


Sure you could do that. eg;
https://github.com/llvm-mirror/llvm/blob/e3e43d9d574cf0a829e9a58525372ba0868a3292/lib/IR/Globals.cpp#L85

Or use the enum names;
https://github.com/llvm-mirror/llvm/blob/e3e43d9d574cf0a829e9a58525372ba0868a3292/lib/Transforms/Utils/FunctionComparator.cpp#L248

Like I said, how you determine what you're looking at might change based on
what you want to do with each subclass of Value, which still hasn't been
clarified.

You get better answers if you ask more specific questions and provided more
context. And lately it seems like you've been asking a lot of questions.

Why do you need to know the specific type of a Value * ?
Or, implicit in your question, what types of stored values are you looking
for?
Do you want to look through bitcasts to discover the source Value?
Is this an attempt to get a different answer to your "[llvm-dev] Force
casting a Value*" question?


On Mon, Jun 12, 2017 at 4:05 PM, Joshua Cranmer via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> On 6/12/17 1:34 AM, Joshua Cranmer 🐧 wrote:
>
>> If you're dead set on actually printing the name of the class of a Value,
>> there's no canned method to do that. Something like this code would work
>> (untested):
>> const char *kind_name = nullptr;
>> switch(val->getValueID()) {
>> #define HANDLE_VALUE(name) case Value::name##Val: kind_name = #name;
>> break;
>> default: kind_name = "well this was unexpected";
>> }
>>
>
> Arggh, I'm an idiot. The correct code should be:
> const char *kind_name = nullptr;
> switch(val->getValueID()) {
> #define HANDLE_VALUE(name) case Value::name##Val: kind_name = #name; break;
> #include "llvm/IR/Value.def"
> #undef HANDLE_VALUE
> default: kind_name = "well this was unexpected";
> }
>
> The #include is kinda the most important part in that statement...
>
> --
> Joshua Cranmer
> Thunderbird module owner
> DXR coauthor
>
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170613/e4370bbc/attachment.html>


More information about the llvm-dev mailing list