<div dir="ltr"><div><div><div><div><div><div><div>The detailed answer will depend on how you want this type to behave and what the exact semantics both in C and LLVM-IR should be. It is a fair amount of text to even begin to describe this, so I'm not about to write a "complete guide to changing clang to support another type" - that would probably take several days of intense writing [at least for me!]<br><br></div>A trivial model would be to use existing bitwise structs, e.g. <br><br></div>   struct X {<br></div>       int a:1;<br></div>       int b:3; <br>   };<br><br></div>   X x;<br><br></div>   x.a = 1;<br></div><div>   x.b = 5;<br><br></div><div>and simply make the codegen part of Clang and LLVM understand how to generate whatever instructions the target processor has to support this (I have not looked at what clang generates for this, but I'd expect this to be "translatable" to 'bit operatons' in some fashion either way) - one way to solve this may be to introduce llvm intrinsic functions that can then be handled in the machine instruction generaton - and have Clang codegen simply translate x.a = 1; into llvm.something.set_bit(x, 0, 1, 1) [where arguments represent address, bit number, number of bits and value to set]. That is just ONE possible solution, and I'm sure there are a dozen other choices - not saying this is the right or best method, but it seems to me as a plausible scenario.<br><br></div><div>On the other hand, if you really need a new type, you'll be adding code in many places. Here's a patch I found adding the "PipeType" (I work on OpenCL, so I looked through for types added for OpenCL as that's something I know has happened...)<br><a href="https://reviews.llvm.org/D14441">https://reviews.llvm.org/D14441</a><br><br><br></div><div>It is probably not a perfect example, but it will give you some rough idea of what sort of work is involved in adding a new type.<br><div>Conceptually, these things aren't very hard to do, but there's 
typically several places that need to be modified for even a relatively 
simple type addition. If the type then "behaves" different to regular existing types, you'll also<br></div><div>need to implement code to reflect that in the compiler (e.g. "you can't use operator + on a 'bit' would need suitable changes in Sema)<br></div><br><br></div><div>You may then have to add types to LLVM too - I'm not familiar with much of that, so can't really advice much there.<br><br></div><br><div>--<br></div><div>Mats<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 6 July 2017 at 11:35, To be a better me via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p class="MsoNormal"><span style="font-family:Arial;color:rgb(46,48,51);letter-spacing:0pt;font-size:10.5pt">Dear Mr.:</span><span style="font-family:Arial;color:rgb(46,48,51);letter-spacing:0pt;font-size:10.5pt">:</span></p><p class="MsoNormal"><span style="font-family:宋体;font-size:12pt;line-height:1.5;text-indent:31.5pt">   So far,I still have two questions.</span></p><p class="MsoNormal"><span style="font-family:Calibri;font-size:12.0000pt">     For the first question,I am adding the recognition to a new type , so I want to know about LLVM / CLANG running mechanism of identifying the type . For example, when recogning the type , CLANG is own analytical type or call LLVM to resolve the type.So now can you tell me about LLVM and CLANG<font face="Arial">’</font><font face="Calibri">operation mechanism for the identification of the type Or give me some relevant information?</font></span></p><p class="MsoNormal" style="text-indent:0px"><span style="text-indent:31.5pt;font-family:Calibri;font-size:12pt">      For the second question, the new type I am adding is the base type Bit in the microcontroller. I now follow the step to add a new type in the LLVM official website[1] to modify the LLVM source code ,what<font face="Arial">’</font><font face="Calibri">s more,It is compiled successfully. So I wrote a test program in VS2015 to identify the new type I added, but still did not recognize it. I debug the test program, followed the program to run inside, did not go to the LLVM code I added. So I do not know where the problem is in.I also not clear that the code in CLANG is or not needs to be modified.</font></span><span style="text-indent:31.5pt;font-family:Calibri;font-size:12pt"> </span><span style="text-indent:31.5pt;font-family:宋体;font-size:12pt">Can you explain it to me?</span><span style="line-height:1.5;text-indent:31.5pt;font-size:10.5pt;font-family:Arial;color:rgb(46,48,51);letter-spacing:0pt"> </span></p><div style="font-family:'lucida Grande',Verdana,'Microsoft YaHei';line-height:23.8px"><p class="MsoNormal" style="line-height:23.8px"><span style="font-family:Calibri;font-size:12pt">      Thanke you for your guidance.</span><span style="font-family:Calibri;font-size:12pt"><u></u><u></u></span></p><p class="MsoNormal" style="line-height:21px"><span style="font-family:Arial;font-size:10.5pt"></span></p></div><div style="font-family:'lucida Grande',Verdana,'Microsoft YaHei';line-height:23.8px"> sincerely  zhangya</div><p class="MsoNormal" style="text-indent:0px"><span style="line-height:1.5;text-indent:31.5pt;font-size:10.5pt;font-family:Arial;color:rgb(46,48,51);letter-spacing:0pt"><br></span></p><p class="MsoNormal" style="text-indent:0px"><span style="font-family:'lucida Grande',Verdana,'Microsoft YaHei';line-height:23.8px">[1] </span><a href="http://llvm.org/docs/ExtendingLLVM.html#adding-a-fundamental-type" style="outline:none;color:rgb(30,84,148);font-family:'lucida Grande',Verdana,'Microsoft YaHei';line-height:23.8px" target="_blank">http://llvm.org/docs/Extending<wbr>LLVM.html#adding-a-fundamental<wbr>-type</a></p><p class="MsoNormal" style="text-indent:0px"><span style="line-height:1.5;text-indent:31.5pt;font-size:10.5pt;font-family:Arial;color:rgb(46,48,51);letter-spacing:0pt"><br></span></p><br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>