[all-commits] [llvm/llvm-project] ced0d1: [BPF] support 128bit int explicitly in layout spec
yonghong-song via All-commits
all-commits at lists.llvm.org
Sat Mar 28 11:52:50 PDT 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: ced0d1f42b39bd93b350b2597ce6587d107c26a7
https://github.com/llvm/llvm-project/commit/ced0d1f42b39bd93b350b2597ce6587d107c26a7
Author: Yonghong Song <yhs at fb.com>
Date: 2020-03-28 (Sat, 28 Mar 2020)
Changed paths:
M clang/lib/Basic/Targets/BPF.h
M clang/test/CodeGen/target-data.c
M llvm/lib/Target/BPF/BPFTargetMachine.cpp
A llvm/test/CodeGen/BPF/i128.ll
Log Message:
-----------
[BPF] support 128bit int explicitly in layout spec
Currently, bpf does not specify 128bit alignment in its
layout spec. So for a structure like
struct ipv6_key_t {
unsigned pid;
unsigned __int128 saddr;
unsigned short lport;
};
clang will generate IR type
%struct.ipv6_key_t = type { i32, [12 x i8], i128, i16, [14 x i8] }
Additional padding is to ensure later IR->MIR can generate correct
stack layout with target layout spec.
But it is common practice for a tracing program to be
first compiled with target flag (e.g., x86_64 or aarch64) through
clang to generate IR and then go through llc to generate bpf
byte code. Tracing program often refers to kernel internal
data structures which needs to be compiled with non-bpf target.
But such a compilation model may cause a problem on aarch64.
The bcc issue https://github.com/iovisor/bcc/issues/2827
reported such a problem.
For the above structure, since aarch64 has "i128:128" in its
layout string, the generated IR will have
%struct.ipv6_key_t = type { i32, i128, i16 }
Since bpf does not have "i128:128" in its spec string,
the selectionDAG assumes alignment 8 for i128 and
computes the stack storage size for the above is 32 bytes,
which leads incorrect code later.
The x86_64 does not have this issue as it does not have
"i128:128" in its layout spec as it does permits i128 to
be alignmented at 8 bytes at stack. Its IR type looks like
%struct.ipv6_key_t = type { i32, [12 x i8], i128, i16, [14 x i8] }
The fix here is add i128 support in layout spec, the same as
aarch64. The only downside is we may have less optimal stack
allocation in certain cases since we require 16byte alignment
for i128 instead of 8. But this is probably fine as i128 is
not used widely and in most cases users should already
have proper alignment.
Differential Revision: https://reviews.llvm.org/D76587
More information about the All-commits
mailing list