Hi Reed, <div><br></div><div>I think you can try this:</div><div>1. write C/C++ code that use ptrtoint_i1 (declare ptrtoint_i1 as an external function)</div><div>2. compile it using clang to LLVM IR,</div><div>3. link the compiled IR with the IR for ptrtoint_i1 to executable using llvm-ld or the clang driver. <br></div><div><br></div><div>However, one complication in your case is I doubt there's a mapping from any C/C++ type to i1 (bool is translated to i8). If that's the case, you may need to put a wrapper around ptrtoint_i1, e.g., </div><div>define void @ptrtoint_i8(i8* a, i8* b) {</div><div>  %slot = alloca i1</div><div>  call void @ptrtoint_i1(i8* a, i1* %slot)</div><div>  %value = load i1* %slot</div><div>  %ext_value = zext i1 %value to i8</div><div>  store i8 %ext_value, i8* b</div><div>}</div><div>// not tested :) be careful when you copy and paste</div><div>Then, you can use ptrtoint_i8(char *, char *) in your C/C++ code, and when linked ptrtoint_i1 will show up too. </div><div><br></div><div>Jingyue</div><br><div class="gmail_quote">On Tue Sep 30 2014 at 3:35:14 PM Reed Kotler <<a href="mailto:rkotler@mips.com">rkotler@mips.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">If you can't make an executable test from C or C++ code then how do you<br>
know something works.<br>
<br>
Just by examination of the .s?<br>
<br>
<br>
On 09/30/2014 03:18 PM, Reed Kotler wrote:<br>
> If I wanted to call this function that they generated by hand, from C or<br>
> C+ code, how would that be done?<br>
><br>
> if have seen cases where a real boolean gets generated but it was<br>
> something fairly involved.<br>
><br>
> is a boolean and a char supposed to occupy the same amount of storage?<br>
><br>
> is this prototype going to work in general:<br>
><br>
> void ptrtoint_i1(char *p, bool *q)<br>
><br>
> TIA.<br>
><br>
> Reed<br>
><br>
> On 09/29/2014 03:15 PM, reed kotler wrote:<br>
>> Technically I don't need C/C++ code for it.<br>
>><br>
>> I'm not really very good at writing LLVM assembly code by hand<br>
>> (but I should be - lol ).<br>
>><br>
>> I'm working on fast-isel and I want to have executable tests for all of<br>
>> this<br>
>> and not just make check tests.<br>
>><br>
>> It's easier for me to do that in C/C++ and then save the .ll and morph<br>
>> it into<br>
>> a make check test.<br>
>><br>
>> I'm going through the fast-isel tests for x86 now and adapting them for<br>
>> Mips.<br>
>> (will do the same for AArch64 and other ports).<br>
>><br>
>> I want an executable variant for all of them.<br>
>><br>
>> On 09/29/2014 03:11 PM, Duncan P. N. Exon Smith wrote:<br>
>>>> On Sep 29, 2014, at 2:29 PM, reed kotler <<a href="mailto:rkotler@mips.com" target="_blank">rkotler@mips.com</a>> wrote:<br>
>>>><br>
>>>> Thanks.<br>
>>>><br>
>>>> So what about a fragment like this: (taken from fast-isel.ll in X86 )<br>
>>>><br>
>>>> define void @ptrtoint_i1(i8* %p, i1* %q) nounwind {<br>
>>>>   %t = ptrtoint i8* %p to i1<br>
>>>>   store i1 %t, i1* %q<br>
>>>>   ret void<br>
>>>> }<br>
>>> Intuitively, this looks like:<br>
>>><br>
>>>      void ptrtoint_i1(char *p, bool *q) { *q = (bool)p; }<br>
>>><br>
>>> However, `q` needs to be addressable in C/C++, so it's left as an `i8`.<br>
>>><br>
>>> `git log` suggests this particular testcase evolved incrementally out<br>
>>> of hand-written IR.<br>
>>><br>
>>> Why do you need C/C++ code for it?  Just interested?<br>
>>><br>
>>>> TIA.<br>
>>>><br>
>>>> On 09/29/2014 02:16 PM, Duncan P. N. Exon Smith wrote:<br>
>>>>>> On Sep 29, 2014, at 1:51 PM, reed kotler <<a href="mailto:rkotler@mips.com" target="_blank">rkotler@mips.com</a>> wrote:<br>
>>>>>><br>
>>>>>> What kind of C or C++ code will emit a "ptrtoint" op?<br>
>>>>> This C code:<br>
>>>>><br>
>>>>>      long ptrtoint(void *p) { return (long)p; }<br>
>>>>><br>
>>>>> gives:<br>
>>>>><br>
>>>>>      define i64 @ptrtoint(i8* %p) {<br>
>>>>>        %1 = ptrtoint i8* %p to i64<br>
>>>>>        ret i64 %1<br>
>>>>>      }<br>
>>>>><br>
>>>>><br>
>>>>>> Also, what causes i1 to be emitted?<br>
>>>>> This C++ code:<br>
>>>>><br>
>>>>>      bool i1() { return false; }<br>
>>>>><br>
>>>>> gives:<br>
>>>>><br>
>>>>>      define zeroext i1 @_Z2i1v() {<br>
>>>>>        ret i1 false<br>
>>>>>      }<br>
>>>>><br>
>>>>><br>
>>>>>> Tia.<br>
>>>>>><br>
>>>>>> Reed<br>
>>>>>> ______________________________<u></u>_________________<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/<u></u>mailman/listinfo/llvmdev</a><br>
<br>
______________________________<u></u>_________________<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/<u></u>mailman/listinfo/llvmdev</a><br>
</blockquote></div>