I am again calling for help from LLVM developers ;) For my DSP backend, at the lowering stage and also at the AsmPrinter stage, I need to know if a GlobalAddress is a code or a data address. So I tried at the lowering stage to use: GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op); const GlobalValue *GV = GSDN->getGlobal(); GV->hasSection() and GV->getSection() But the section is not set at this stage (hasSection = false) And at the AsmPrinter stage: const GlobalValue *GV = MO.getGlobal(); SectionKind sectionKind = Mang->getSymbol(GV)->getSection().getKind(); But again the section does not seem to be set (sectionKind.isInSection() false) Do you know a way to tell if a global address corresponds to data or code ? I have to process differently text and data address... Thank you ! Damien -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110318/ac2258e0/attachment.html>
I reply to myself... I didn't go in the right direction in my previous email. There is an easy way to tell if a GlobalValue corresponds to data or code: const GlobalValue *GV; if(Function::classof(GV)) ... // process the global value as a function else ... // process the global value as data Damien On Fri, Mar 18, 2011 at 3:16 PM, Damien Vincent <damien.llvm at gmail.com>wrote:> > I am again calling for help from LLVM developers ;) > > For my DSP backend, at the lowering stage and also at the AsmPrinter stage, > I need to know if a GlobalAddress is a code or a data address. > > So I tried at the lowering stage to use: > GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op); > const GlobalValue *GV = GSDN->getGlobal(); > GV->hasSection() and GV->getSection() > But the section is not set at this stage (hasSection = false) > > And at the AsmPrinter stage: > const GlobalValue *GV = MO.getGlobal(); > SectionKind sectionKind = Mang->getSymbol(GV)->getSection().getKind(); > But again the section does not seem to be set (sectionKind.isInSection() > false) > > Do you know a way to tell if a global address corresponds to data or code ? > I have to process differently text and data address... > > Thank you ! > > Damien > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110321/d0bfa164/attachment.html>
On 3/21/11 2:00 PM, Damien Vincent wrote:> I reply to myself... I didn't go in the right direction in my previous > email. > > There is an easy way to tell if a GlobalValue corresponds to data or code: > const GlobalValue *GV; > if(Function::classof(GV)) > ... // process the global value as a function > else > ... // process the global value as data > > DamienYou should be able to use isa<Function>(GV) to determine if GV is a function. You may have to put in an additional check to see if GV is a GlobalAlias and to determine if the GlobalAlias is an alias for a function: if (GlobalAlias * GA = dyn_cast<GlobalAlias>(GV)) { ... Check to see if GA is an alias for a function } I recommend looking at the doxygen documentation on llvm.org to learn the class hierarchy relationships between GlobalValue, GlobalVariable, GlobalAlias, and Function. You should also read the Programmer's Guide to get familiar with the isa<>() and dyn_cast<>() functions if you are not familiar with them already. -- John T.> > > > > On Fri, Mar 18, 2011 at 3:16 PM, Damien Vincent <damien.llvm at gmail.com > <mailto:damien.llvm at gmail.com>> wrote: > > > I am again calling for help from LLVM developers ;) > > For my DSP backend, at the lowering stage and also at the > AsmPrinter stage, I need to know if a GlobalAddress is a code or a > data address. > > So I tried at the lowering stage to use: > GlobalAddressSDNode *GSDN = cast<GlobalAddressSDNode>(Op); > const GlobalValue *GV = GSDN->getGlobal(); > GV->hasSection() and GV->getSection() > But the section is not set at this stage (hasSection = false) > > And at the AsmPrinter stage: > const GlobalValue *GV = MO.getGlobal(); > SectionKind sectionKind = Mang->getSymbol(GV)->getSection().getKind(); > But again the section does not seem to be set > (sectionKind.isInSection() = false) > > Do you know a way to tell if a global address corresponds to data > or code ? I have to process differently text and data address... > > Thank you ! > > Damien > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110321/8227224c/attachment.html>