<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>+      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="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>