Skip to content

Commit e0c497b

Browse files
authored
Merge pull request JuliaLang#21498 from JuliaLang/kf/llvmtests
Add infrastructure for testing julia's LLVM passes
2 parents 5955d79 + 418afaa commit e0c497b

6 files changed

Lines changed: 79 additions & 24 deletions

File tree

deps/llvm-options.mk

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
ifeq ($(LLVM_DEBUG),1)
2+
LLVM_BUILDTYPE := Debug
3+
else
4+
LLVM_BUILDTYPE := Release
5+
endif
6+
LLVM_CMAKE_BUILDTYPE := $(LLVM_BUILDTYPE)
7+
ifeq ($(LLVM_ASSERTIONS),1)
8+
LLVM_BUILDTYPE := $(LLVM_BUILDTYPE)+Asserts
9+
endif
10+
LLVM_FLAVOR := $(LLVM_BUILDTYPE)
11+
ifeq ($(LLVM_SANITIZE),1)
12+
ifeq ($(SANITIZE_MEMORY),1)
13+
LLVM_BUILDTYPE := $(LLVM_BUILDTYPE)+MSAN
14+
else
15+
LLVM_BUILDTYPE := $(LLVM_BUILDTYPE)+ASAN
16+
endif
17+
endif
18+
19+
LLVM_SRC_DIR:=$(SRCDIR)/srccache/llvm-$(LLVM_VER)
20+
LLVM_BUILD_DIR:=$(BUILDDIR)/llvm-$(LLVM_VER)
21+
LLVM_BUILDDIR_withtype := $(LLVM_BUILD_DIR)/build_$(LLVM_BUILDTYPE)

deps/llvm.mk

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,7 @@ endif
2323
endif
2424
endif
2525

26-
ifeq ($(LLVM_DEBUG),1)
27-
LLVM_BUILDTYPE := Debug
28-
else
29-
LLVM_BUILDTYPE := Release
30-
endif
31-
LLVM_CMAKE_BUILDTYPE := $(LLVM_BUILDTYPE)
32-
ifeq ($(LLVM_ASSERTIONS),1)
33-
LLVM_BUILDTYPE := $(LLVM_BUILDTYPE)+Asserts
34-
endif
35-
LLVM_FLAVOR := $(LLVM_BUILDTYPE)
36-
ifeq ($(LLVM_SANITIZE),1)
37-
ifeq ($(SANITIZE_MEMORY),1)
38-
LLVM_BUILDTYPE := $(LLVM_BUILDTYPE)+MSAN
39-
else
40-
LLVM_BUILDTYPE := $(LLVM_BUILDTYPE)+ASAN
41-
endif
42-
endif
43-
44-
LLVM_SRC_DIR:=$(SRCDIR)/srccache/llvm-$(LLVM_VER)
45-
LLVM_BUILD_DIR:=$(BUILDDIR)/llvm-$(LLVM_VER)
46-
LLVM_BUILDDIR_withtype := $(LLVM_BUILD_DIR)/build_$(LLVM_BUILDTYPE)
26+
include $(SRCDIR)/llvm-options.mk
4727
LLVM_LIB_FILE := libLLVMCodeGen.a
4828

4929
ifeq ($(LLVM_VER), 3.3)
@@ -124,7 +104,7 @@ ifeq ($(USE_LLVM_SHLIB),1)
124104
# NOTE: we could also --disable-static here (on the condition we link tools
125105
# against libLLVM) but there doesn't seem to be a CMake counterpart option
126106
LLVM_FLAGS += --enable-shared
127-
LLVM_CMAKE += -DLLVM_BUILD_LLVM_DYLIB:BOOL=ON
107+
LLVM_CMAKE += -DLLVM_BUILD_LLVM_DYLIB:BOOL=ON -DLLVM_LINK_LLVM_DYLIB:BOOL=ON
128108
# NOTE: starting with LLVM 3.8, all symbols are exported
129109
ifeq ($(LLVM_VER_SHORT),$(filter $(LLVM_VER_SHORT),3.3 3.4 3.5 3.6 3.7))
130110
LLVM_CMAKE += -DLLVM_DYLIB_EXPORT_ALL:BOOL=ON

src/llvm-simdloop.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,14 @@ void LowerSIMDLoop::enableUnsafeAlgebraIfReduction(PHINode *Phi, Loop *L) const
144144

145145
bool LowerSIMDLoop::runOnLoop(Loop *L, LPPassManager &LPM)
146146
{
147-
if (!simd_loop_mdkind)
148-
return false; // Fast rejection test.
147+
if (!simd_loop_mdkind) {
148+
simd_loop_mdkind = L->getHeader()->getContext().getMDKindID("simd_loop");
149+
#if JL_LLVM_VERSION >= 30600
150+
simd_loop_md = MDNode::get(L->getHeader()->getContext(), ArrayRef<Metadata*>());
151+
#else
152+
simd_loop_md = MDNode::get(L->getHeader()->getContext(), ArrayRef<Value*>());
153+
#endif
154+
}
149155

150156
if (!hasSIMDLoopMetadata(L))
151157
return false;

test/llvmpasses/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
SRCDIR := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
2+
JULIAHOME := $(abspath $(SRCDIR)/../..)
3+
include $(JULIAHOME)/deps/Versions.make
4+
include $(JULIAHOME)/Make.inc
5+
include $(JULIAHOME)/deps/llvm-ver.make
6+
BUILDDIR = $(JULIAHOME)/deps/scratch
7+
include $(JULIAHOME)/deps/llvm-options.mk
8+
LLVM_SRC_DIR:=$(JULIAHOME)/deps/srccache/llvm-$(LLVM_VER)
9+
test:
10+
PATH=$$PATH:$(LLVM_BUILDDIR_withtype)/bin $(LLVM_SRC_DIR)/utils/lit/lit.py -v .
11+
.PHONY: test

test/llvmpasses/lit.cfg

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import os
2+
import sys
3+
import re
4+
import platform
5+
6+
import lit.util
7+
import lit.formats
8+
9+
config.name = 'Julia'
10+
config.suffixes = ['.ll']
11+
config.test_source_root = os.path.dirname(__file__)
12+
config.test_format = lit.formats.ShTest(False)
13+
14+
path = os.path.pathsep.join((os.path.join(os.path.dirname(__file__),"../../usr/tools"), config.environment['PATH']))
15+
config.environment['PATH'] = path

test/llvmpasses/simdloop.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: opt -load libjulia.so -LowerSIMDLoop -S %s | FileCheck %s
2+
3+
define void @simd_test(double *%a, double *%b) {
4+
top:
5+
br label %loop
6+
loop:
7+
%i = phi i64 [0, %top], [%nexti, %loop]
8+
%aptr = getelementptr double, double *%a, i64 %i
9+
%bptr = getelementptr double, double *%b, i64 %i
10+
; CHECK: llvm.mem.parallel_loop_access
11+
%aval = load double, double *%aptr
12+
%bval = load double, double *%aptr
13+
%cval = fadd double %aval, %bval
14+
store double %cval, double *%bptr
15+
%nexti = add i64 %i, 1, !simd_loop !1
16+
%done = icmp sgt i64 %nexti, 500
17+
br i1 %done, label %loopdone, label %loop
18+
loopdone:
19+
ret void
20+
}
21+
22+
!1 = !{}

0 commit comments

Comments
 (0)