Dear all I am trying to get the size of an LLVM pointer type. getPrimitiveSizeInBits() returns 0 for it and the documentation for isSized() suggest to use TargetData. I figured out from Kaleidoscope example that one can get a pointer to TagetData object through the execution engine but it seems to be an overkill. What is the right way to do it? Best regards, Victor -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100528/495267e7/attachment.html>
Thanks, John. I am writing not an LLVM pass but a compiler backend, so this doesn't work for me. Victor On 28 May 2010 17:35, John Criswell <criswell at illinois.edu> wrote:> Victor Zverovich wrote: > >> Dear all >> >> I am trying to get the size of an LLVM pointer type. >> getPrimitiveSizeInBits() returns 0 for it and the documentation for >> isSized() suggest to use TargetData. >> I figured out from Kaleidoscope example that one can get a pointer to >> TagetData object through the execution engine but it seems to be an >> overkill. >> What is the right way to do it? >> > TargetData is an LLVM pass. If you're writing an LLVM pass, just make > TargetData one of its prerequisite analysis passes in the getAnalysisUsage() > method and use the getAnalysis<TargetData>() function to get a reference to > the TargetData pass within your pass. > > -- John T. > > >> Best regards, >> Victor >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100528/57d4d280/attachment.html>
Victor Zverovich wrote:> Dear all > > I am trying to get the size of an LLVM pointer type. > getPrimitiveSizeInBits() returns 0 for it and the documentation for > isSized() suggest to use TargetData. > I figured out from Kaleidoscope example that one can get a pointer to > TagetData object through the execution engine but it seems to be an > overkill. > What is the right way to do it?TargetData is an LLVM pass. If you're writing an LLVM pass, just make TargetData one of its prerequisite analysis passes in the getAnalysisUsage() method and use the getAnalysis<TargetData>() function to get a reference to the TargetData pass within your pass. -- John T.> > Best regards, > Victor >
For those targets supported by LLVM, you can get their TargetData by creating TargetMachine first (take X86 as example): ==== BEGIN CODE SNIPPET === const std::string TripleStr = "i686-unknown-linux"; // hard coded for example const std::string FeatureStr = ""; // hard coded for example std::string Err; const Target* T; TargetMachine* TM = NULL; const TargetData* TD; // Or just call InitializeAllTargetInfos() and InitializeAllTargets() for all targets enabled by your LLVM build. LLVMInitializeX86TargetInfo(); LLVMInitializeX86Target(); T = TargetRegistry::lookupTarget(TripleStr, Err); if(!Err.empty()) // error handling // Create TargetMachine TM = T->createTargetMachine(TripleStr, FeatureStr); if(TM == NULL) // error handling // TD is what you want. TD = TM->getTargetData(); [...] // Free TM delete TM; ==== END CODE SNIPPET === For your case, you should be able to find TripleStr and FeatureStr in somewhere. And also there's a constructor in TargetData ( http://llvm.org/doxygen/classllvm_1_1TargetData.html#a0d7acb06af9665b54fc74480e2c6c707) takeing a string "TargetDescription". The string specifies the data layout of a target and its format is described here http://llvm.org/docs/LangRef.html#datalayout. Thus, if you are developing a customized target and/or you are really know the data layout specification about your target, you can get a TargetData instance by simply passing the hand-coded data layout string to the constructor of TargetData. Hope this will be helpful to you. Zonr On Fri, May 28, 2010 at 11:27 PM, Victor Zverovich < victor.zverovich at googlemail.com> wrote:> Dear all > > I am trying to get the size of an LLVM pointer type. > getPrimitiveSizeInBits() returns 0 for it and the documentation for > isSized() suggest to use TargetData. > I figured out from Kaleidoscope example that one can get a pointer to > TagetData object through the execution engine but it seems to be an > overkill. > What is the right way to do it? > > Best regards, > Victor > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100529/3e1c41f2/attachment.html>
Thanks a lot, Zonr. I will give it a try. Victor On 28 May 2010 19:06, Zonr Chang <zonr.xchg at gmail.com> wrote:> For those targets supported by LLVM, you can get their TargetData by > creating TargetMachine first (take X86 as example): > > ==== BEGIN CODE SNIPPET ===> const std::string TripleStr = "i686-unknown-linux"; // hard coded for > example > const std::string FeatureStr = ""; // hard coded for example > std::string Err; > const Target* T; > TargetMachine* TM = NULL; > const TargetData* TD; > > // Or just call InitializeAllTargetInfos() and InitializeAllTargets() > for all targets enabled by your LLVM build. > LLVMInitializeX86TargetInfo(); > LLVMInitializeX86Target(); > > T = TargetRegistry::lookupTarget(TripleStr, Err); > if(!Err.empty()) > // error handling > > // Create TargetMachine > TM = T->createTargetMachine(TripleStr, FeatureStr); > if(TM == NULL) > // error handling > > // TD is what you want. > TD = TM->getTargetData(); > > [...] > > // Free TM > delete TM; > ==== END CODE SNIPPET ===> > For your case, you should be able to find TripleStr and FeatureStr in > somewhere. > > And also there's a constructor in TargetData ( > http://llvm.org/doxygen/classllvm_1_1TargetData.html#a0d7acb06af9665b54fc74480e2c6c707) > takeing a string "TargetDescription". The string specifies the data layout > of a target and its format is described here > http://llvm.org/docs/LangRef.html#datalayout. Thus, if you are developing > a customized target and/or you are really know the data layout specification > about your target, you can get a TargetData instance by simply passing > the hand-coded data layout string to the constructor of TargetData. > > Hope this will be helpful to you. > > Zonr > > > On Fri, May 28, 2010 at 11:27 PM, Victor Zverovich < > victor.zverovich at googlemail.com> wrote: > >> Dear all >> >> I am trying to get the size of an LLVM pointer type. >> getPrimitiveSizeInBits() returns 0 for it and the documentation for >> isSized() suggest to use TargetData. >> I figured out from Kaleidoscope example that one can get a pointer to >> TagetData object through the execution engine but it seems to be an >> overkill. >> What is the right way to do it? >> >> Best regards, >> Victor >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >> >> >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100528/b0cfb223/attachment.html>