Skip to content

Commit 22a513a

Browse files
author
Yonghong Song
committed
Set TrivialAutoVarInitMaxSize to 8
This is to prevent auto init for large data structures, e.g. for xdp prog, iphdr or tcphdr they all more than 8 bytes. If auto init is not really needed, auto init might cause performance regression for those programs.
1 parent e0d1f90 commit 22a513a

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

clang/include/clang/Basic/LangOptions.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,13 @@ class LangOptions : public LangOptionsBase {
653653
void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
654654
#include "clang/Basic/LangOptions.def"
655655

656+
unsigned getTrivialAutoVarInitMaxSize() const {
657+
return TrivialAutoVarInitMaxSize;
658+
}
659+
void setTrivialAutoVarInitMaxSize(unsigned max_size) {
660+
TrivialAutoVarInitMaxSize = max_size;
661+
}
662+
656663
/// Are we compiling a module?
657664
bool isCompilingModule() const {
658665
return getCompilingModule() != CMK_None;

clang/lib/Basic/Targets/BPF.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,12 @@ void BPFTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
9393
TargetInfo::adjust(Diags, Opts);
9494

9595
if (Opts.getTrivialAutoVarInit() ==
96-
LangOptions::TrivialAutoVarInitKind::Uninitialized)
96+
LangOptions::TrivialAutoVarInitKind::Uninitialized) {
9797
Opts.setTrivialAutoVarInit(LangOptions::TrivialAutoVarInitKind::Zero);
98+
// Set the maximum auto init size to be 8 to avoid potential regression
99+
// e.g. for xdp programs where ip/tcp header size is more than 8.
100+
Opts.setTrivialAutoVarInitMaxSize(8);
101+
}
98102
}
99103

100104
llvm::SmallVector<Builtin::InfosShard>

clang/test/CodeGen/bpf-auto-var-init.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ int foo1() {
77
}
88
// CHECK: ret i32 0
99

10-
int foo2() {
11-
int val[4];
12-
return val[2];
13-
}
14-
// CHECK: ret i32 0
15-
1610
struct val_t {
1711
int val;
1812
};

0 commit comments

Comments
 (0)