PATCH: implement printf call lowering in the NVPTX backend

Eli Bendersky eliben at google.com
Thu Mar 27 13:55:45 PDT 2014


On Thu, Mar 27, 2014 at 10:46 AM, Jingyue Wu <jingyue at google.com> wrote:

> +    if (BufSize == 0) {
>
> +      // If no arguments, pass a null pointer as the second argument to
> vprintf.
> +      BufferPtr = ConstantInt::get(Int32Ty, 0);
>
> +    } else {
>
> +      // Create the buffer to hold all the arguments. Align it to the
> preferred
> +      // alignment of the first object going into the buffer. Note: if
> BufSize >
> +      // 0, we know there's at least one object so getArgOperand(1) is
> safe.
> +      unsigned AlignOfFirst =
>
> +          DL->getPrefTypeAlignment(Call->getArgOperand(1)->getType());
>
> Does aligning the first argument ensures aligning other arguments?
> Consider 2
> arguments, 1st 4-aligned, and 2nd 8-aligned. If the base of alloca is not
> a
> multiple of 8, we can guarantee 2nd argument 8-aligned. For example, if
> the
> base is 36, the address of 2nd argument is 36 + 8 which is not a multiple
> of 8.
>
>
> Is this alignment mandatory? Looks like getPrefTypeAlignment gives
> "preferred
> type ailgnment". OK to use it here?
>

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.

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.

Justin - does this LGTY? Is there a constant maximal alignment we can
obtain for NVPTX to simplify this?

Eli




>
> +      BufferPtr = new AllocaInst(Type::getInt8Ty(M.getContext()),
>
> +                                 ConstantInt::get(Int32Ty, BufSize),
>
> +                                 AlignOfFirst,
>
> +                                 "buf_for_vprintf_args", Call);
>
>
>
>
> On Wed, Mar 26, 2014 at 9:51 AM, Eli Bendersky <eliben at google.com> wrote:
>
>> Hello,
>>
>> 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.
>>
>> Tests (IR to IR, and IR to PTX) included.
>>
>> PTAL,
>> Eli
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140327/23bcc75c/attachment.html>


More information about the llvm-commits mailing list