[LLVMdev] how to get TargetData?

Victor Zverovich victor.zverovich at googlemail.com
Fri May 28 11:39:30 PDT 2010


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>


More information about the llvm-dev mailing list