[prev in list] [next in list] [prev in thread] [next in thread] 

List:       llvm-dev
Subject:    Re: [LLVMdev] how to get TargetData?
From:       Victor Zverovich <victor.zverovich () googlemail ! com>
Date:       2010-05-28 18:39:30
Message-ID: AANLkTikFz1wvgY4ZSkPKnoH6exSO9QYPTy3-PQe9v_Aa () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Thanks a lot, Zonr. I will give it a try.

Victor

On 28 May 2010 19:06, Zonr Chang <zonr.xchg@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@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@cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>>
>

[Attachment #5 (text/html)]

Thanks a lot, Zonr. I will give it a try.<div><br></div><div>Victor<br><br><div \
class="gmail_quote">On 28 May 2010 19:06, Zonr Chang <span dir="ltr">&lt;<a \
href="mailto:zonr.xchg@gmail.com">zonr.xchg@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex;"><div>For those targets supported by LLVM, you can get their \
TargetData by creating TargetMachine first (take X86 as example):</div>

<div><div><br></div><div>==== BEGIN CODE SNIPPET ====</div><div><div>    const \
std::string TripleStr = &quot;i686-unknown-linux&quot;; // hard coded for \
example</div>


<div>    const std::string FeatureStr = &quot;&quot;; // hard coded for \
example</div><div>    std::string Err;</div><div>    const Target* T;</div><div>    \
TargetMachine* TM = NULL;</div><div>    const TargetData* TD;</div>




<div><br></div><div>    // Or just call InitializeAllTargetInfos() and \
InitializeAllTargets() for all targets enabled by your LLVM build.</div><div>    \
LLVMInitializeX86TargetInfo();</div><div>    LLVMInitializeX86Target();</div>




<div><br></div><div>    T = TargetRegistry::lookupTarget(TripleStr, Err);</div><div>  \
if(!Err.empty())</div><div>        // error handling</div><div><br></div><div>    // \
Create TargetMachine</div><div>    TM = T-&gt;createTargetMachine(TripleStr, \
FeatureStr);</div>




<div>    if(TM == NULL)</div><div>        // error handling</div><div><br></div><div> \
// TD is what you want.</div><div>    TD = \
TM-&gt;getTargetData();</div><div><br></div><div>    [...]</div><div><br></div><div>  \
// Free TM</div>




<div>    delete TM;</div><div>==== END CODE SNIPPET ====</div><div><br></div><div>For \
your case, you should be able to find TripleStr and FeatureStr in \
somewhere.</div><div><br></div><div>And also there&#39;s a constructor in TargetData \
(<a href="http://llvm.org/doxygen/classllvm_1_1TargetData.html#a0d7acb06af9665b54fc74480e2c6c707" \
target="_blank">http://llvm.org/doxygen/classllvm_1_1TargetData.html#a0d7acb06af9665b54fc74480e2c6c707</a>) \
takeing a string &quot;TargetDescription&quot;. The string specifies the data layout \
of a target and its format is described here <a \
href="http://llvm.org/docs/LangRef.html#datalayout" \
target="_blank">http://llvm.org/docs/LangRef.html#datalayout</a>. 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.</div>




<div><br></div><div>Hope this will be helpful to \
you.</div><div><br></div><div>Zonr</div><div><br></div></div><div><div><div><div><br><div \
class="gmail_quote"><div><div></div><div class="h5">On Fri, May 28, 2010 at 11:27 PM, \
Victor Zverovich <span dir="ltr">&lt;<a href="mailto:victor.zverovich@googlemail.com" \
target="_blank">victor.zverovich@googlemail.com</a>&gt;</span> wrote:<br>




</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px \
#ccc solid;padding-left:1ex"><div><div></div><div class="h5">Dear \
all<div><br></div><div>I am trying to get the size of an LLVM pointer type.</div>

<div>getPrimitiveSizeInBits() returns 0 for it and the documentation for isSized() \
suggest to use TargetData.</div>




<div>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.</div><div>What is \
the right way to do it?</div><div><br></div><div>





Best regards,</div>
<div>Victor</div><font color="#888888"><div><br></div>
</font><br></div></div>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         \
<a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br> <a \
href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" \
target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br> \
<br></blockquote></div><br></div></div></div></div></div> \
</blockquote></div><br></div>



_______________________________________________
LLVM Developers mailing list
LLVMdev@cs.uiuc.edu         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic