Patch that experimentally integrates Polly into Julia's execution engine.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Make.inc b/Make.inc | |
index 6d8ca15..8f93705 100644 | |
--- a/Make.inc | |
+++ b/Make.inc | |
@@ -19,7 +19,8 @@ endif | |
OPENBLAS_USE_THREAD:=1 | |
# Use libraries available on the system instead of building them | |
-USE_SYSTEM_LLVM:=0 | |
+USE_SYSTEM_LLVM:=1 | |
+LLVM_CONFIG:=/home/d412vv1n/opt/llvm/bin/llvm-config | |
USE_SYSTEM_LIBUNWIND:=0 | |
USE_SYSTEM_PCRE:=0 | |
USE_SYSTEM_LIBM:=0 | |
diff --git a/src/Makefile b/src/Makefile | |
index ae46d01..31eab33 100644 | |
--- a/src/Makefile | |
+++ b/src/Makefile | |
@@ -46,15 +46,19 @@ endif | |
HEADERS := $(addprefix $(SRCDIR)/,julia.h julia_threads.h julia_internal.h options.h) $(BUILDDIR)/julia_version.h $(wildcard $(SRCDIR)/support/*.h) $(LIBUV_INC)/uv.h | |
+LLVMLINK := $(shell $(LLVM_CONFIG_HOST) --libdir)/libPolly.a | |
+LLVMLINK += $(shell $(LLVM_CONFIG_HOST) --libdir)/libPollyISL.a | |
+FLAGS += -I$(shell $(LLVM_CONFIG_HOST) --src-root)/tools/polly/include | |
+ | |
# 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 | |
diff --git a/src/codegen.cpp b/src/codegen.cpp | |
index e06211e..7623120 100644 | |
--- a/src/codegen.cpp | |
+++ b/src/codegen.cpp | |
@@ -112,6 +112,8 @@ using namespace llvm; | |
#include <setjmp.h> | |
+#include <polly/RegisterPasses.h> | |
+ | |
#include <string> | |
#include <sstream> | |
#include <fstream> | |
@@ -1510,12 +1512,12 @@ static uint64_t compute_obj_symsize(const object::ObjectFile *obj, uint64_t offs | |
object::SectionRef Section = *I; | |
#endif | |
uint64_t SAddr, SSize; | |
-#ifdef LLVM38 | |
- SAddr = Section.getAddress().get(); | |
- SSize = Section.getSize().get(); | |
-#elif defined(LLVM36) | |
+#if defined(LLVM36) || defined(LLVM39) | |
SAddr = Section.getAddress(); | |
SSize = Section.getSize(); | |
+#elif defined(LLVM38) | |
+ SAddr = Section.getAddress().get(); | |
+ SSize = Section.getSize().get(); | |
#else | |
Section.getAddress(SAddr); | |
Section.getSize(SSize); | |
@@ -5974,6 +5976,10 @@ extern "C" void jl_init_codegen(void) | |
llvm::DisablePrettyStackTrace = true; | |
#endif | |
+ PassRegistry &Registry = *PassRegistry::getPassRegistry(); | |
+ polly::initializePollyPasses(Registry); | |
+ initializeAnalysis(Registry); | |
+ | |
InitializeNativeTarget(); | |
InitializeNativeTargetAsmPrinter(); | |
InitializeNativeTargetAsmParser(); | |
diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp | |
index cd8f32e..a8d6817 100644 | |
--- a/src/debuginfo.cpp | |
+++ b/src/debuginfo.cpp | |
@@ -377,7 +377,10 @@ public: | |
#endif | |
if (Section == EndSection) continue; | |
if (!Section->isText()) continue; | |
-#ifdef LLVM38 | |
+#if defined(LLVM39) | |
+ uint64_t SectionAddr = Section->getAddress(); | |
+ uint64_t SectionLoadAddr = L.getSectionLoadAddress(*Section); | |
+#elif LLVM38 | |
uint64_t SectionAddr = Section->getAddress().get(); | |
uint64_t SectionLoadAddr = L.getSectionLoadAddress(*Section); | |
#else | |
diff --git a/src/jitlayers.cpp b/src/jitlayers.cpp | |
index 78a56b3..58a634a 100644 | |
--- a/src/jitlayers.cpp | |
+++ b/src/jitlayers.cpp | |
@@ -63,6 +63,10 @@ static void addOptimizationPasses(T *PM) | |
PM->add(createEarlyCSEPass()); //// **** | |
+ if (getenv("JULIA_USE_POLLY")) | |
+ polly::registerPollyPasses(*PM); | |
+ | |
+ | |
PM->add(createLoopIdiomPass()); //// **** | |
PM->add(createLoopRotatePass()); // Rotate loops. | |
// LoopRotate strips metadata from terminator, so run LowerSIMD afterwards |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment