Dipanjan Das via llvm-dev
2017-Jun-12 06:12 UTC
[llvm-dev] How to know the sub-class of a Value class?
On 11 June 2017 at 23:06, Jeremy Lakeman <Jeremy.Lakeman at gmail.com> wrote:> http://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast- > templates >I understand isa and dyn-cast let you test the type of an object at run-time by leveraging LLVM's custom implementation of RTTI. However, it doesn't make much sense to test out for all possible sub-classes to get to know what it actually is. If I just want to know sub-class a Value* is, what's the way out (other than testing with isa<>())?> > > On Mon, Jun 12, 2017 at 3:24 PM, Dipanjan Das via llvm-dev < > llvm-dev at lists.llvm.org> wrote: > >> >> As a concrete question, I understand 'Value' class is the parent of many >> concrete sub-classes. Let's say I retrieve a Value* value >> store_inst->getValueOperand(). Unless I know what the sub-type is, how can >> I further use this object? I tried something like this: >> >> ================================================>> >> Value* value = store_inst->getValueOperand() >> errs() << value->getValueID; // Which ID corresponds to which >> sub-class? >> errs() << value->getValueName(); // Prints numeric memory >> addresses >> errs() << *value->getValueName(); // Doesn't compile >> >> ================================================>> >> I have mentioned the issues in each of the cases above. I am not sure if >> the approach is correct or not. Please help me out. >> >> -- >> >> Thanks & Regards, >> Dipanjan >> >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >> >> >-- Thanks & Regards, Dipanjan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170611/c8aa51b1/attachment.html>
Sanjoy Das via llvm-dev
2017-Jun-12 06:20 UTC
[llvm-dev] How to know the sub-class of a Value class?
On Sun, Jun 11, 2017 at 11:12 PM, Dipanjan Das via llvm-dev <llvm-dev at lists.llvm.org> wrote:> > > On 11 June 2017 at 23:06, Jeremy Lakeman <Jeremy.Lakeman at gmail.com> wrote: >> >> >> http://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates > > > I understand isa and dyn-cast let you test the type of an object at run-time > by leveraging LLVM's custom implementation of RTTI. However, it doesn't make > much sense to test out for all possible sub-classes to get to know what it > actually is. If I just want to know sub-class a Value* is, what's the way > out (other than testing with isa<>())?Does this pattern (or some variant of it) solve your problem: https://github.com/llvm-mirror/llvm/blob/master/lib/Analysis/BasicAliasAnalysis.cpp#L232 ? -- Sanjoy
Jeremy Lakeman via llvm-dev
2017-Jun-12 06:25 UTC
[llvm-dev] How to know the sub-class of a Value class?
I'm certainly no expert, but how you use that Value* would depend on what you want to do with it.>From the documentation, it looks like Value->getValueID() is how the RTTIimplementation determines the subclass. So you could switch over the values returned (defined in llvm/IR/Value.def). Or dyn_cast to each of the types you need to deal with. Or use some other helper functions that strip noops like bitcasts for you. On Mon, Jun 12, 2017 at 3:42 PM, Dipanjan Das via llvm-dev < llvm-dev at lists.llvm.org> wrote:> > > On 11 June 2017 at 23:06, Jeremy Lakeman <Jeremy.Lakeman at gmail.com> wrote: > >> http://llvm.org/docs/ProgrammersManual.html#the-isa-cast- >> and-dyn-cast-templates >> > > I understand isa and dyn-cast let you test the type of an object at > run-time by leveraging LLVM's custom implementation of RTTI. However, it > doesn't make much sense to test out for all possible sub-classes to get to > know what it actually is. If I just want to know sub-class a Value* is, > what's the way out (other than testing with isa<>())? > > > >> >> >> On Mon, Jun 12, 2017 at 3:24 PM, Dipanjan Das via llvm-dev < >> llvm-dev at lists.llvm.org> wrote: >> >>> >>> As a concrete question, I understand 'Value' class is the parent of many >>> concrete sub-classes. Let's say I retrieve a Value* value >>> store_inst->getValueOperand(). Unless I know what the sub-type is, how can >>> I further use this object? I tried something like this: >>> >>> ================================================>>> >>> Value* value = store_inst->getValueOperand() >>> errs() << value->getValueID; // Which ID corresponds to which >>> sub-class? >>> errs() << value->getValueName(); // Prints numeric memory >>> addresses >>> errs() << *value->getValueName(); // Doesn't compile >>> >>> ================================================>>> >>> I have mentioned the issues in each of the cases above. I am not sure if >>> the approach is correct or not. Please help me out. >>> >>> -- >>> >>> Thanks & Regards, >>> Dipanjan >>> >>> _______________________________________________ >>> LLVM Developers mailing list >>> llvm-dev at lists.llvm.org >>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >>> >>> >> > > > -- > > Thanks & Regards, > Dipanjan > > _______________________________________________ > 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/20170612/137fe771/attachment.html>
Dipanjan Das via llvm-dev
2017-Jun-12 06:28 UTC
[llvm-dev] How to know the sub-class of a Value class?
On 11 June 2017 at 23:20, Sanjoy Das <sanjoy at playingwithpointers.com> wrote:> >Does this pattern (or some variant of it) solve your problem:> https://github.com/llvm-mirror/llvm/blob/master/lib/ > Analysis/BasicAliasAnalysis.cpp#L232It switches over BinaryOperator->getOpcode(). I don't think it addresses my query. -- Thanks & Regards, Dipanjan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170611/5fe44451/attachment.html>
Dipanjan Das via llvm-dev
2017-Jun-12 06:31 UTC
[llvm-dev] How to know the sub-class of a Value class?
On 11 June 2017 at 23:25, Jeremy Lakeman <Jeremy.Lakeman at gmail.com> wrote:> I'm certainly no expert, but how you use that Value* would depend on what > you want to do with it. > > From the documentation, it looks like Value->getValueID() is how the RTTI > implementation determines the subclass. > So you could switch over the values returned (defined in > llvm/IR/Value.def). >In my <llvm-root>/include/llvm/IR/Value.def, there's no mapping between the numeric ID (as returned by getValueID()) and corresponding sub-class. Thanks & Regards, Dipanjan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170611/bc3f2a07/attachment.html>