All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dibyendu Majumdar <mobile@majumdar.org.uk>
To: Christopher Li <sparse@chrisli.org>
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>,
	Linux-Sparse <linux-sparse@vger.kernel.org>
Subject: Re: [PATCH 07/13] llvm: fix output OP_ADD mixed with pointers
Date: Mon, 6 Mar 2017 15:32:05 +0000	[thread overview]
Message-ID: <CACXZuxfX0TiYGJDewbRW9Tr3-nzqiBrdOK0K+mO0qqwyGCrjSQ@mail.gmail.com> (raw)
In-Reply-To: <CANeU7Qk6xjhNPVZWxTB4iOavH5=bha+a_utz7+PJuSTo1WKgOg@mail.gmail.com>

Hi Chris,

On 6 March 2017 at 15:16, Christopher Li <sparse@chrisli.org> wrote:
> On Sun, Mar 5, 2017 at 7:20 PM, Luc Van Oostenryck
> <luc.vanoostenryck@gmail.com> wrote:
>> In sparse, pointer arithmetic and accessing the field
>> of a structure or an array is simply done via OP_ADD,
>> the offset being calculated at evaluation time.
>> On the other hand, LLVM allows addition only on two
>> integers and pointer arithmetic/member access is done
>> via 'getelementptr'.
>>
>> sparse-llvm didn't took this in account which resulted
>> in type error in 'add' instructions.
>>
>> Fix this by catching addition involving pointer and issuing
>> a getelementptr' instruction for these.
>
> I have one related question. In the case of anonymous
> structure or union, how to you figure out which series of
> GEP it needs to be? I think sparse already lost the element
> pointer index information. You can construct it back by looking
> at the bit offset. But if there is union then the element point can
> have multiple path to reach to the same bit offset. I don't
> know how to deal with that.

Sparse-llvm appears to bypass the normal struct GEP in LLVM. It
basically casts everything to char *, uses GEP to obtain a pointer to
member, and then casts it back to member type. So this should work for
structs and unions.

>
>>
>> Originally-by: Dibyendu Majumdar <mobile@majumdar.org.uk>
>> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
>> ---
>>  sparse-llvm.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/sparse-llvm.c b/sparse-llvm.c
>> index 27cc1b88c..ee374b217 100644
>> --- a/sparse-llvm.c
>> +++ b/sparse-llvm.c
>> @@ -472,6 +472,10 @@ static void output_op_binary(struct function *fn, struct instruction *insn)
>>         case OP_ADD:
>>                 if (symbol_is_fp_type(insn->type))
>>                         target = LLVMBuildFAdd(fn->builder, lhs, rhs, target_name);
>> +               else if (LLVMGetTypeKind(LLVMTypeOf(lhs)) == LLVMPointerTypeKind)
>> +                       target = LLVMBuildGEP(fn->builder, lhs, &rhs, 1, "");
>> +               else if (LLVMGetTypeKind(LLVMTypeOf(rhs)) == LLVMPointerTypeKind)
>> +                       target = LLVMBuildGEP(fn->builder, rhs, &lhs, 1, "");
>
> It seems that you only have one level of indices. Also the OP_ADD use the member
> offset of the struct. I am not sure how it map into GEP indices.
> Correct me if I am
> wrong, it seems to me you use the member offset as element indices. I
> think it need
> to get a mapping between offset to indices.
>

This case is more about handing pointer arithmetic correctly. Here GEP
is being used as array element access and not for struct member
access.

Hope this is helpful.

Regards
Dibyendu

  reply	other threads:[~2017-03-06 15:33 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-05 11:20 [WIP 00/13] LLVM fixes Luc Van Oostenryck
2017-03-05 11:20 ` [PATCH 01/13] llvm: add a helper to convert an integer to a ValueRef Luc Van Oostenryck
2017-03-05 11:20 ` [PATCH 02/13] llvm: fix translation of PSEUDO_VALs into a ValueRefs Luc Van Oostenryck
2017-03-07 15:11   ` Christopher Li
2017-03-07 16:18     ` Luc Van Oostenryck
2017-03-07 22:48       ` Christopher Li
2017-03-05 11:20 ` [PATCH 03/13] llvm: fix output_op_store() which modify its operand Luc Van Oostenryck
2017-03-05 11:20 ` [PATCH 04/13] llvm: fix output_op_[ptr]cast() Luc Van Oostenryck
2017-03-05 11:20 ` [PATCH 05/13] add get_nth1_arg() Luc Van Oostenryck
2017-03-06 14:40   ` Christopher Li
2017-03-06 16:52     ` Luc Van Oostenryck
2017-03-05 11:20 ` [PATCH 06/13] llvm: fix type of literal integer passed as arguments Luc Van Oostenryck
2017-03-06 14:56   ` Christopher Li
2017-03-07 15:33   ` Christopher Li
2017-03-07 16:21     ` Luc Van Oostenryck
2017-03-07 19:41     ` Dibyendu Majumdar
2017-03-10 16:08       ` Dibyendu Majumdar
2017-03-10 17:47         ` Luc Van Oostenryck
2017-03-05 11:20 ` [PATCH 07/13] llvm: fix output OP_ADD mixed with pointers Luc Van Oostenryck
2017-03-06 15:16   ` Christopher Li
2017-03-06 15:32     ` Dibyendu Majumdar [this message]
2017-03-06 16:22       ` Christopher Li
2017-03-06 16:43         ` Luc Van Oostenryck
2017-03-06 17:06           ` Dibyendu Majumdar
2017-03-06 19:50             ` Luc Van Oostenryck
2017-03-06 17:07           ` Christopher Li
2017-03-06 19:52             ` Luc Van Oostenryck
2017-03-06 21:15             ` [PATCH v2] " Luc Van Oostenryck
2017-03-06 18:17           ` [PATCH 07/13] " Linus Torvalds
2017-03-06 20:09             ` Luc Van Oostenryck
2017-03-05 11:20 ` [PATCH 08/13] llvm: add support for OP_NEG Luc Van Oostenryck
2017-03-05 11:20 ` [PATCH 09/13] give a type to OP_PHISOURCE Luc Van Oostenryck
2017-03-05 11:20 ` [PATCH 10/13] give a type to OP_SEL, always Luc Van Oostenryck
2017-03-05 11:20 ` [PATCH 11/13] llvm: remove unneeded arg 'module' Luc Van Oostenryck
2017-03-05 11:20 ` [PATCH 12/13] llvm: remove unneeded arg 'fn' Luc Van Oostenryck
2017-03-05 11:20 ` [PATCH 13/13] llvm: fix: do not mix pointers and floats when doing compares Luc Van Oostenryck
2017-03-06  1:47 ` [WIP 00/13] LLVM fixes Christopher Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACXZuxfX0TiYGJDewbRW9Tr3-nzqiBrdOK0K+mO0qqwyGCrjSQ@mail.gmail.com \
    --to=mobile@majumdar.org.uk \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.com \
    --cc=sparse@chrisli.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.