[all-commits] [llvm/llvm-project] 4a5aa1: [BPF] Add preserve_access_index attribute for reco...

yonghong-song via All-commits all-commits at lists.llvm.org
Sat Nov 9 08:18:21 PST 2019


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 4a5aa1a7bf8b1714b817ede8e09cd28c0784228a
      https://github.com/llvm/llvm-project/commit/4a5aa1a7bf8b1714b817ede8e09cd28c0784228a
  Author: Yonghong Song <yhs at fb.com>
  Date:   2019-11-09 (Sat, 09 Nov 2019)

  Changed paths:
    M clang/include/clang/Basic/Attr.td
    M clang/include/clang/Basic/AttrDocs.td
    M clang/include/clang/Basic/DiagnosticSemaKinds.td
    M clang/lib/CodeGen/CGExpr.cpp
    M clang/lib/Sema/SemaDeclAttr.cpp
    A clang/test/CodeGen/bpf-attr-preserve-access-index-1.c
    A clang/test/CodeGen/bpf-attr-preserve-access-index-2.c
    A clang/test/CodeGen/bpf-attr-preserve-access-index-3.c
    A clang/test/CodeGen/bpf-attr-preserve-access-index-4.c
    A clang/test/CodeGen/bpf-attr-preserve-access-index-5.c
    A clang/test/CodeGen/bpf-attr-preserve-access-index-6.c
    A clang/test/CodeGen/bpf-attr-preserve-access-index-7.c
    A clang/test/CodeGen/bpf-attr-preserve-access-index-8.c
    A clang/test/Sema/bpf-attr-preserve-access-index.c

  Log Message:
  -----------
  [BPF] Add preserve_access_index attribute for record definition

This patch introduced a new bpf specific attribute which can
be added to struct or union definition. For example,
  struct s { ... } __attribute__((preserve_access_index));
  union u { ... } __attribute__((preserve_access_index));
The goal is to simplify user codes for cases
where preserve access index happens for certain struct/union,
so user does not need to use clang __builtin_preserve_access_index
for every members.

The attribute has no effect if -g is not specified.

When the attribute is specified and -g is specified, any member
access defined by that structure or union, including array subscript
access and inner records, will be preserved through
  __builtin_preserve_{array,struct,union}_access_index()
IR intrinsics, which will enable relocation generation
in bpf backend.

The following is an example to illustrate the usage:
  -bash-4.4$ cat t.c
  #define __reloc__ __attribute__((preserve_access_index))
  struct s1 {
    int c;
  } __reloc__;

  struct s2 {
    union {
      struct s1 b[3];
    };
  } __reloc__;

  struct s3 {
    struct s2 a;
  } __reloc__;

  int test(struct s3 *arg) {
    return arg->a.b[2].c;
  }
  -bash-4.4$ clang -target bpf -g -S -O2 t.c

A relocation with access string "0:0:0:0:2:0" will be generated
representing access offset of arg->a.b[2].c.

forward declaration with attribute is also handled properly such
that the attribute is copied and populated in real record definition.

Differential Revision: https://reviews.llvm.org/D69759




More information about the All-commits mailing list