Skip to content

Commit 61d480b

Browse files
author
ARPITH C. JACOB acjacob@us.ibm.com
committed
[XLA][WIP] Add support for Polyhedral compilation through Polly
Patch by @annanay25 tensorflow#12408
1 parent 2a857df commit 61d480b

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

tensorflow/compiler/xla/service/cpu/BUILD

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ load("//tensorflow:tensorflow.bzl", "tf_cc_test")
1919
load("//tensorflow:tensorflow.bzl", "tf_cc_binary")
2020
load("//tensorflow/compiler/xla:xla.bzl", "ORC_JIT_MEMORY_MAPPER_TARGETS")
2121

22+
config_setting(
23+
name = "using_polly",
24+
values = {
25+
"polly": "true",
26+
},
27+
visibility = ["//tensorflow:internal"]
28+
)
29+
#visibility = ["@%ws%//tensorflow:internal"]
30+
2231
# Filegroup used to collect source files for dependency checking.
2332
filegroup(
2433
name = "c_srcs",
@@ -368,6 +377,7 @@ cc_library(
368377
"@llvm//:object",
369378
"@llvm//:support",
370379
"@llvm//:target",
380+
"@llvm//:polly",
371381
],
372382
)
373383

tensorflow/compiler/xla/service/cpu/build_defs.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,14 @@ def runtime_copts():
1010
"//tensorflow:android": ["-O2"],
1111
"//conditions:default": []
1212
}))
13+
14+
def if_polly(basic_deps):
15+
"""Shorthand for select()'ing on whether we're building with Polly.
16+
Returns a select statement which evaluates to basic_deps if we're building
17+
with Polly enabled. Otherwise, the select statement evaluates to basic_deps.
18+
"""
19+
return select({
20+
"//third_party/llvm:using_polly": basic_deps.append("@llvm//:polly"),
21+
"//conditions:default": basic_deps
22+
})
23+

tensorflow/compiler/xla/service/cpu/compiler_functor.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ limitations under the License.
2222
#include <utility>
2323
#include <vector>
2424

25+
#include "external/llvm/tools/polly/include/polly/LinkAllPasses.h"
26+
#include "external/llvm/tools/polly/include/polly/RegisterPasses.h"
27+
2528
#include "llvm/ADT/StringRef.h"
2629
#include "llvm/Analysis/TargetLibraryInfo.h"
2730
#include "llvm/Analysis/TargetTransformInfo.h"
@@ -312,6 +315,11 @@ void CompilerFunctor::AddOptimizationPasses(
312315
builder.SLPVectorize = opt_level > 1 && size_level == 0;
313316

314317
builder.populateFunctionPassManager(*function_passes);
318+
319+
llvm::PassRegistry& Registry = *llvm::PassRegistry::getPassRegistry();
320+
::polly::initializePollyPasses(Registry);
321+
::polly::registerPollyPasses(*module_passes);
322+
315323
builder.populateModulePassManager(*module_passes);
316324
}
317325

third_party/llvm/BUILD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,10 @@ py_binary(
66
srcs_version = "PY2AND3",
77
visibility = ["@llvm//:__subpackages__"],
88
)
9+
10+
py_binary(
11+
name = "expand_isl_cmake_vars",
12+
srcs = ["expand_isl_cmake_vars.py"],
13+
srcs_version = "PY2AND3",
14+
visibility = ["@llvm//:__subpackages__"],
15+
)

third_party/llvm/llvm.bzl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ def cmake_var_string(cmake_vars):
8585
return " ".join([_quote("{}={}".format(k, str(v)))
8686
for (k, v) in cmake_vars.items()])
8787

88+
def expand_isl_cmake_vars(name, src, dst, cmake_vars):
89+
"""Expands #cmakedefine, #cmakedefine01, and CMake variables in a text file.
90+
91+
Args:
92+
name: the name of the rule
93+
src: the input of the rule
94+
dst: the output of the rule
95+
cmake_vars: a string containing the CMake variables, as generated by
96+
cmake_var_string.
97+
"""
98+
expand_isl_cmake_vars_tool = "@//third_party/llvm:expand_isl_cmake_vars"
99+
native.genrule(
100+
name = name,
101+
srcs = [src],
102+
tools = [expand_isl_cmake_vars_tool],
103+
outs = [dst],
104+
cmd = ("$(location {}) ".format(expand_isl_cmake_vars_tool) + cmake_vars +
105+
"< $< > $@")
106+
)
107+
88108
def expand_cmake_vars(name, src, dst, cmake_vars):
89109
"""Expands #cmakedefine, #cmakedefine01, and CMake variables in a text file.
90110

0 commit comments

Comments
 (0)