<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Mar 27, 2014 at 10:46 AM, Jingyue Wu <span dir="ltr"><<a href="mailto:jingyue@google.com" target="_blank">jingyue@google.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>+    if (BufSize == 0) {                                                              </div><div>+      // If no arguments, pass a null pointer as the second argument to vprintf.</div>

<div>+      BufferPtr = ConstantInt::get(Int32Ty, 0);                                    </div>
<div>+    } else {                                                                       </div><div>+      // Create the buffer to hold all the arguments. Align it to the preferred </div><div>+      // alignment of the first object going into the buffer. Note: if BufSize ></div>


<div>+      // 0, we know there's at least one object so getArgOperand(1) is safe.       </div><div>+      unsigned AlignOfFirst =                                                      </div><div>+          DL->getPrefTypeAlignment(Call->getArgOperand(1)->getType());             </div>


<div>Does aligning the first argument ensures aligning other arguments? Consider 2       </div><div>arguments, 1st 4-aligned, and 2nd 8-aligned. If the base of alloca is not a         </div><div>multiple of 8, we can guarantee 2nd argument 8-aligned. For example, if the         </div>


<div>base is 36, the address of 2nd argument is 36 + 8 which is not a multiple of 8.  </div><div>                                                                                    </div><div>Is this alignment mandatory? Looks like getPrefTypeAlignment gives "preferred       </div>


<div>type ailgnment". OK to use it here?                  </div></div></blockquote><div><br></div><div>I'm pretty sure it's mandatory, because I'm then giving the preferred alignment of each object to the StoreInst. Without this, NVPTX assumes unaligned stores and breaks all objects up to single bytes, issuing sequences of shifts-and-bytestores.</div>

<div><br></div><div>So what we can do is compute the maximal alignment among objects that go into the buffer and use that to align the buffer itself. This should guarantee that each individual object is properly aligned.</div>

<div><br></div><div>Justin - does this LGTY? Is there a constant maximal alignment we can obtain for NVPTX to simplify this?</div><div><br></div><div>Eli</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div dir="ltr"><div>                               </div><div>+      BufferPtr = new AllocaInst(Type::getInt8Ty(M.getContext()),                  </div><div>+                                 ConstantInt::get(Int32Ty, BufSize),               </div>


<div>+                                 AlignOfFirst,                                     </div><div>+                                 "buf_for_vprintf_args", Call);                    </div><div><br></div></div>

<div class="HOEnZb"><div class="h5">
<div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Mar 26, 2014 at 9:51 AM, Eli Bendersky <span dir="ltr"><<a href="mailto:eliben@google.com" target="_blank">eliben@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


<div dir="ltr">Hello,<div><br></div><div>This patch implements lowering of the printf call to the vprintf syscall in the NVPTX backend. It is implemented as a target-specific IR pass that runs before codegen. The pass builds the required data structure from the varargs to pass to the vprintf calls.</div>




<div><br></div><div>Tests (IR to IR, and IR to PTX) included.</div><div><br></div><div>PTAL,</div><div>Eli</div><div><br></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>