Skip to content

Commit

Permalink
Integrate Polly and make it available via @polly macro
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthiasJReisinger committed May 24, 2016
1 parent a7cf985 commit fd5554e
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ BUILD_LLVM_CLANG := 0
# set to 1 to get lldb (often does not work, no chance with llvm3.2 and earlier)
# see http:https://lldb.llvm.org/build.html for dependencies
BUILD_LLDB := 0
USE_POLLY := 0
# Cross-compile
#XC_HOST := i686-w64-mingw32
Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,7 @@ export
@simd,
@inline,
@noinline,
@polly,

@assert,
@enum,
Expand Down
7 changes: 7 additions & 0 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ macro propagate_inbounds(ex)
end
end

"""
Tells the compiler to apply the polyhedral optimizer Polly to a function.
"""
macro polly(ex)
esc(isa(ex, Expr) ? pushmeta!(ex, :polly) : ex)
end

## some macro utilities ##

find_vars(e) = find_vars(e, [])
Expand Down
13 changes: 10 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,17 @@ SRCS := \
simplevector APInt-C runtime_intrinsics runtime_ccall \
threadgroup threading stackwalk gc gc-debug gc-pages safepoint

LLVMLINK :=

ifeq ($(JULIACODEGEN),LLVM)
SRCS += codegen disasm debuginfo llvm-simdloop llvm-gcroot
FLAGS += -I$(shell $(LLVM_CONFIG_HOST) --includedir)
LLVM_LIBS := all
ifeq ($(USE_POLLY),1)
LLVMLINK += -lPolly -lPollyISL
FLAGS += -I$(shell $(LLVM_CONFIG_HOST) --src-root)/tools/polly/include
FLAGS += -DUSE_POLLY
endif
else
SRCS += anticodegen
LLVM_LIBS := support
Expand All @@ -51,12 +58,12 @@ HEADERS := $(addprefix $(SRCDIR)/,julia.h julia_threads.h julia_internal.h optio
# In LLVM < 3.4, --ldflags includes both options and libraries, so use it both before and after --libs
# In LLVM >= 3.4, --ldflags has only options, and --system-libs has the libraries.
ifneq ($(USE_LLVM_SHLIB),1)
LLVMLINK := $(shell $(LLVM_CONFIG_HOST) --ldflags) $(shell $(LLVM_CONFIG_HOST) --libs $(LLVM_LIBS)) $(shell $(LLVM_CONFIG_HOST) --ldflags) $(shell $(LLVM_CONFIG_HOST) --system-libs 2> /dev/null)
LLVMLINK += $(shell $(LLVM_CONFIG_HOST) --ldflags) $(shell $(LLVM_CONFIG_HOST) --libs $(LLVM_LIBS)) $(shell $(LLVM_CONFIG_HOST) --ldflags) $(shell $(LLVM_CONFIG_HOST) --system-libs 2> /dev/null)
else
ifeq ($(LLVM_USE_CMAKE),1)
LLVMLINK := $(shell $(LLVM_CONFIG_HOST) --ldflags) -lLLVM
LLVMLINK += $(shell $(LLVM_CONFIG_HOST) --ldflags) -lLLVM
else
LLVMLINK := $(shell $(LLVM_CONFIG_HOST) --ldflags) -lLLVM-$(shell $(LLVM_CONFIG_HOST) --version)
LLVMLINK += $(shell $(LLVM_CONFIG_HOST) --ldflags) -lLLVM-$(shell $(LLVM_CONFIG_HOST) --version)
endif
FLAGS += -DLLVM_SHLIB
endif
Expand Down
1 change: 1 addition & 0 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ jl_sym_t *pure_sym; jl_sym_t *simdloop_sym;
jl_sym_t *meta_sym; jl_sym_t *compiler_temp_sym;
jl_sym_t *inert_sym; jl_sym_t *vararg_sym;
jl_sym_t *unused_sym; jl_sym_t *static_parameter_sym;
jl_sym_t *polly_sym;

typedef struct {
int64_t a;
Expand Down
16 changes: 16 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@
#if defined(_CPU_ARM_) || defined(_CPU_AARCH64_)
# include <llvm/IR/InlineAsm.h>
#endif
#if defined(USE_POLLY)
#include <polly/RegisterPasses.h>
#include <polly/ScopDetection.h>
#endif

using namespace llvm;

Expand Down Expand Up @@ -4161,6 +4165,12 @@ static std::unique_ptr<Module> emit_function(jl_lambda_info_t *lam, jl_llvm_func
f->setHasUWTable(); // force NeedsWinEH
#endif

#ifdef USE_POLLY
if (!has_meta(code, polly_sym)) {
f->addFnAttr(polly::PollySkipFnAttr);
}
#endif

#ifdef JL_DEBUG_BUILD
f->addFnAttr(Attribute::StackProtectReq);
#endif
Expand Down Expand Up @@ -5676,6 +5686,12 @@ extern "C" void jl_init_codegen(void)
llvm::DisablePrettyStackTrace = true;
#endif

#ifdef USE_POLLY
PassRegistry &Registry = *PassRegistry::getPassRegistry();
polly::initializePollyPasses(Registry);
initializeAnalysis(Registry);
#endif

InitializeNativeTarget();
InitializeNativeTargetAsmPrinter();
InitializeNativeTargetAsmParser();
Expand Down
4 changes: 4 additions & 0 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ static void addOptimizationPasses(T *PM)

PM->add(createEarlyCSEPass()); //// ****

#ifdef USE_POLLY
polly::registerPollyPasses(*PM);
#endif

PM->add(createLoopIdiomPass()); //// ****
PM->add(createLoopRotatePass()); // Rotate loops.
// LoopRotate strips metadata from terminator, so run LowerSIMD afterwards
Expand Down
1 change: 1 addition & 0 deletions src/jltypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3786,6 +3786,7 @@ void jl_init_types(void)
slot_sym = jl_symbol("slot");
static_parameter_sym = jl_symbol("static_parameter");
compiler_temp_sym = jl_symbol("#temp#");
polly_sym = jl_symbol("polly");

tttvar = jl_new_typevar(jl_symbol("T"),
(jl_value_t*)jl_bottom_type,
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ extern jl_sym_t *copyast_sym; extern jl_sym_t *fastmath_sym;
extern jl_sym_t *pure_sym; extern jl_sym_t *simdloop_sym;
extern jl_sym_t *meta_sym; extern jl_sym_t *list_sym;
extern jl_sym_t *inert_sym; extern jl_sym_t *static_parameter_sym;
extern jl_sym_t *polly_sym;

// gc -------------------------------------------------------------------------

Expand Down

0 comments on commit fd5554e

Please sign in to comment.