Skip to content

Commit c2da327

Browse files
committed
kbuild: Add support for Clang's polyhedral loop optimizer (Polly).
Signed-off-by: Diab Neiroukh <[email protected]>
1 parent df82be5 commit c2da327

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,14 @@ KBUILD_CFLAGS += $(call cc-disable-warning,maybe-uninitialized,)
722722
endif
723723
endif
724724

725+
ifdef CONFIG_POLLY_CLANG
726+
KBUILD_CFLAGS += -mllvm -polly \
727+
-mllvm -polly-vectorizer=stripmine
728+
ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
729+
KBUILD_CFLAGS += -mllvm -polly-run-dce
730+
endif
731+
endif
732+
725733
KBUILD_CFLAGS += $(call cc-ifversion, -lt, 0409, \
726734
$(call cc-disable-warning,maybe-uninitialized,))
727735

arch/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,18 @@ config SHADOW_CALL_STACK_VMAP
587587
provides better stack exhaustion protection, but increases per-thread
588588
memory consumption as a full page is allocated for each shadow stack.
589589

590+
config POLLY_CLANG
591+
bool "Use clang Polly optimizations"
592+
depends on CC_HAS_POLLY
593+
help
594+
This option enables Clang's polyhedral loop optimizer known as Polly.
595+
Polly is able to optimize various loops throughout the kernel for
596+
cache locality. This requires a Clang toolchain compiled with
597+
support for Polly. More information can be found from Polly's
598+
website:
599+
600+
https://polly.llvm.org
601+
590602
config HAVE_ARCH_WITHIN_STACK_FRAMES
591603
bool
592604
help

init/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ config CLANG_VERSION
2929
config CC_HAS_ASM_GOTO
3030
def_bool $(success,$(srctree)/scripts/gcc-goto.sh $(CC))
3131

32+
config CC_HAS_POLLY
33+
depends on CC_IS_CLANG
34+
def_bool $(success,$(srctree)/scripts/clang-polly.sh $(CC))
35+
3236
config TOOLS_SUPPORT_RELR
3337
def_bool $(success,env "CC=$(CC)" "LD=$(LD)" "NM=$(NM)" "OBJCOPY=$(OBJCOPY)" $(srctree)/scripts/tools-support-relr.sh)
3438

scripts/clang-polly.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#! /bin/sh
2+
# SPDX-License-Identifier: GPL-2.0
3+
# Copyright (c) 2021, Diab Neiroukh <[email protected]>
4+
5+
# Get the LLVM library directory from the configuration tool.
6+
pollyLib="$($(dirname $(which $@))/llvm-config --libdir)/LLVMPolly.so"
7+
8+
if [ -f "$pollyLib" ]; then
9+
exit 0
10+
else
11+
exit 1
12+
fi

0 commit comments

Comments
 (0)