Skip to content

Commit 383a07c

Browse files
committed
Merge branch 'vladimirlaz-sycl' into sycl
2 parents 0818f3e + b318148 commit 383a07c

File tree

11,048 files changed

+266945
-215761
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

11,048 files changed

+266945
-215761
lines changed

buildbot/configure.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ done && shift $(($OPTIND - 1))
2626
# we're in llvm.obj dir
2727
BUILD_DIR=${PWD}
2828

29-
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=clang -DLLVM_EXTERNAL_PROJECTS="sycl;llvm-spirv" \
30-
-DLLVM_EXTERNAL_SYCL_SOURCE_DIR=../llvm.src/sycl -DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR=../llvm.src/llvm-spirv \
31-
-DLLVM_TOOL_SYCL_BUILD=ON -DLLVM_TOOL_LLVM_SPIRV_BUILD=ON -DOpenCL_INCLUDE_DIR="OpenCL-Headers" \
32-
-DOpenCL_LIBRARY="OpenCL-ICD-Loader/build/lib/libOpenCL.so" ../llvm.src/llvm
29+
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=clang \
30+
-DLLVM_EXTERNAL_SYCL_SOURCE_DIR=../llvm.src/sycl \
31+
-DLLVM_EXTERNAL_LLVM_SPIRV_SOURCE_DIR=../llvm.src/llvm-spirv \
32+
-DLLVM_TOOL_SYCL_BUILD=ON -DLLVM_TOOL_LLVM_SPIRV_BUILD=ON \
33+
-DOpenCL_INCLUDE_DIR="OpenCL-Headers" \
34+
-DOpenCL_LIBRARY="OpenCL-ICD-Loader/build/lib/libOpenCL.so" \
35+
../llvm.src/llvm

buildbot/dependency.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
#!/bin/bash
1+
#!/bin/bash -x
22

33
BRANCH=
44
BUILD_NUMBER=
55
PR_NUMBER=
6+
SRC_DIR="../llvm.src"
7+
DST_DIR="."
68

79
# $1 exit code
810
# $2 error message
@@ -15,17 +17,38 @@ exit_if_err()
1517
}
1618

1719
unset OPTIND
18-
while getopts ":b:r:n:" option; do
20+
while getopts ":b:r:n:s:d" option; do
1921
case $option in
2022
b) BRANCH=$OPTARG ;;
2123
n) BUILD_NUMBER=$OPTARG ;;
24+
s) SRC_DIR=$OPTARG ;;
25+
d) DST_DIR=$OPTARG ;;
2226
r) PR_NUMBER=$OPTARG ;;
2327
esac
2428
done && shift $(($OPTIND - 1))
2529

2630
# we're in llvm.obj dir
2731
BUILD_DIR=${PWD}
2832

33+
# Get changed build script files
34+
cd ${SRC_DIR}
35+
git fetch -t origin refs/pull/${PR_NUMBER}/merge
36+
exit_if_err $? "fail to get tags"
37+
git checkout -B refs/pull/${PR_NUMBER}/merge
38+
exit_if_err $? "fail to get tags"
39+
base_commit=`git merge-base origin/sycl refs/pull/${PR_NUMBER}/merge`
40+
exit_if_err $? "fail to get base commit"
41+
42+
BUILD_SCRIPT=`git --no-pager diff ${base_commit} refs/pull/${PR_NUMBER}/merge --name-only buildbot`
43+
cd -
44+
45+
## Clean up build directory if build scripts has changed
46+
cd ${DST_DIR}
47+
if [ -n "$BUILD_SCRIPT" ]; then
48+
rm -rf *
49+
fi
50+
cd -
51+
2952
## GET dependencies
3053
if [ ! -d "OpenCL-Headers" ]; then
3154
git clone https://github.com/KhronosGroup/OpenCL-Headers OpenCL-Headers

clang-tools-extra/change-namespace/tool/ClangChangeNamespace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- ClangIncludeFixer.cpp - Standalone change namespace ---------------===//
1+
//===-- ClangChangeNamespace.cpp - Standalone change namespace ------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

clang-tools-extra/clang-doc/Generators.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===---- Generator.cpp - Generator Registry ---------------------*- C++-*-===//
1+
//===-- Generators.cpp - Generator Registry ----------------------*- C++-*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

clang-tools-extra/clang-doc/Serialize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- Serializer.cpp - ClangDoc Serializer --------------------*- C++ -*-===//
1+
//===-- Serialize.cpp - ClangDoc Serializer ---------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

clang-tools-extra/clang-doc/YAMLGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- ClangDocYAML.cpp - ClangDoc YAML -----------------------*- C++ -*-===//
1+
//===-- YAMLGenerator.cpp - ClangDoc YAML -----------------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

clang-tools-extra/clang-move/HelperDeclRefGraph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===-- UsedHelperDeclFinder.cpp - AST-based call graph for helper decls --===//
1+
//===-- HelperDeclRefGraph.cpp - AST-based call graph for helper decls ----===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.

clang-tools-extra/clang-tidy/abseil/AbseilTidyModule.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
#include "DurationFactoryFloatCheck.h"
1717
#include "DurationFactoryScaleCheck.h"
1818
#include "DurationSubtractionCheck.h"
19+
#include "DurationUnnecessaryConversionCheck.h"
1920
#include "FasterStrsplitDelimiterCheck.h"
2021
#include "NoInternalDependenciesCheck.h"
2122
#include "NoNamespaceCheck.h"
2223
#include "RedundantStrcatCallsCheck.h"
2324
#include "StringFindStartswithCheck.h"
2425
#include "StrCatAppendCheck.h"
26+
#include "TimeSubtractionCheck.h"
2527
#include "UpgradeDurationConversionsCheck.h"
2628

2729
namespace clang {
@@ -45,6 +47,8 @@ class AbseilModule : public ClangTidyModule {
4547
"abseil-duration-factory-scale");
4648
CheckFactories.registerCheck<DurationSubtractionCheck>(
4749
"abseil-duration-subtraction");
50+
CheckFactories.registerCheck<DurationUnnecessaryConversionCheck>(
51+
"abseil-duration-unnecessary-conversion");
4852
CheckFactories.registerCheck<FasterStrsplitDelimiterCheck>(
4953
"abseil-faster-strsplit-delimiter");
5054
CheckFactories.registerCheck<NoInternalDependenciesCheck>(
@@ -56,6 +60,8 @@ class AbseilModule : public ClangTidyModule {
5660
"abseil-str-cat-append");
5761
CheckFactories.registerCheck<StringFindStartswithCheck>(
5862
"abseil-string-find-startswith");
63+
CheckFactories.registerCheck<TimeSubtractionCheck>(
64+
"abseil-time-subtraction");
5965
CheckFactories.registerCheck<UpgradeDurationConversionsCheck>(
6066
"abseil-upgrade-duration-conversions");
6167
}

clang-tools-extra/clang-tidy/abseil/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ add_clang_library(clangTidyAbseilModule
1010
DurationFactoryScaleCheck.cpp
1111
DurationRewriter.cpp
1212
DurationSubtractionCheck.cpp
13+
DurationUnnecessaryConversionCheck.cpp
1314
FasterStrsplitDelimiterCheck.cpp
1415
NoInternalDependenciesCheck.cpp
1516
NoNamespaceCheck.cpp
1617
RedundantStrcatCallsCheck.cpp
1718
StrCatAppendCheck.cpp
1819
StringFindStartswithCheck.cpp
20+
TimeSubtractionCheck.cpp
1921
UpgradeDurationConversionsCheck.cpp
2022

2123
LINK_LIBS

clang-tools-extra/clang-tidy/abseil/DurationRewriter.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ rewriteInverseDurationCall(const MatchFinder::MatchResult &Result,
8484
return llvm::None;
8585
}
8686

87+
/// If `Node` is a call to the inverse of `Scale`, return that inverse's
88+
/// argument, otherwise None.
89+
static llvm::Optional<std::string>
90+
rewriteInverseTimeCall(const MatchFinder::MatchResult &Result,
91+
DurationScale Scale, const Expr &Node) {
92+
llvm::StringRef InverseFunction = getTimeInverseForScale(Scale);
93+
if (const auto *MaybeCallArg = selectFirst<const Expr>(
94+
"e", match(callExpr(callee(functionDecl(hasName(InverseFunction))),
95+
hasArgument(0, expr().bind("e"))),
96+
Node, *Result.Context))) {
97+
return tooling::fixit::getText(*MaybeCallArg, *Result.Context).str();
98+
}
99+
100+
return llvm::None;
101+
}
102+
87103
/// Returns the factory function name for a given `Scale`.
88104
llvm::StringRef getDurationFactoryForScale(DurationScale Scale) {
89105
switch (Scale) {
@@ -103,6 +119,24 @@ llvm::StringRef getDurationFactoryForScale(DurationScale Scale) {
103119
llvm_unreachable("unknown scaling factor");
104120
}
105121

122+
llvm::StringRef getTimeFactoryForScale(DurationScale Scale) {
123+
switch (Scale) {
124+
case DurationScale::Hours:
125+
return "absl::FromUnixHours";
126+
case DurationScale::Minutes:
127+
return "absl::FromUnixMinutes";
128+
case DurationScale::Seconds:
129+
return "absl::FromUnixSeconds";
130+
case DurationScale::Milliseconds:
131+
return "absl::FromUnixMillis";
132+
case DurationScale::Microseconds:
133+
return "absl::FromUnixMicros";
134+
case DurationScale::Nanoseconds:
135+
return "absl::FromUnixNanos";
136+
}
137+
llvm_unreachable("unknown scaling factor");
138+
}
139+
106140
/// Returns the Time factory function name for a given `Scale`.
107141
llvm::StringRef getTimeInverseForScale(DurationScale scale) {
108142
switch (scale) {
@@ -250,6 +284,24 @@ std::string rewriteExprFromNumberToDuration(
250284
.str();
251285
}
252286

287+
std::string rewriteExprFromNumberToTime(
288+
const ast_matchers::MatchFinder::MatchResult &Result, DurationScale Scale,
289+
const Expr *Node) {
290+
const Expr &RootNode = *Node->IgnoreParenImpCasts();
291+
292+
// First check to see if we can undo a complimentary function call.
293+
if (llvm::Optional<std::string> MaybeRewrite =
294+
rewriteInverseTimeCall(Result, Scale, RootNode))
295+
return *MaybeRewrite;
296+
297+
if (IsLiteralZero(Result, RootNode))
298+
return std::string("absl::UnixEpoch()");
299+
300+
return (llvm::Twine(getTimeFactoryForScale(Scale)) + "(" +
301+
tooling::fixit::getText(RootNode, *Result.Context) + ")")
302+
.str();
303+
}
304+
253305
bool isNotInMacro(const MatchFinder::MatchResult &Result, const Expr *E) {
254306
if (!E->getBeginLoc().isMacroID())
255307
return true;

clang-tools-extra/clang-tidy/abseil/DurationRewriter.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ enum class DurationScale : std::uint8_t {
3131
/// constructing a `Duration` for that scale.
3232
llvm::StringRef getDurationFactoryForScale(DurationScale Scale);
3333

34+
/// Given a 'Scale', return the appropriate factory function call for
35+
/// constructing a `Time` for that scale.
36+
llvm::StringRef getTimeFactoryForScale(DurationScale scale);
37+
3438
// Determine if `Node` represents a literal floating point or integral zero.
3539
bool IsLiteralZero(const ast_matchers::MatchFinder::MatchResult &Result,
3640
const Expr &Node);
@@ -81,6 +85,12 @@ std::string rewriteExprFromNumberToDuration(
8185
const ast_matchers::MatchFinder::MatchResult &Result, DurationScale Scale,
8286
const Expr *Node);
8387

88+
/// Assuming `Node` has a type `int` representing a time instant of `Scale`
89+
/// since The Epoch, return the expression to make it a suitable `Time`.
90+
std::string rewriteExprFromNumberToTime(
91+
const ast_matchers::MatchFinder::MatchResult &Result, DurationScale Scale,
92+
const Expr *Node);
93+
8494
/// Return `true` if `E` is a either: not a macro at all; or an argument to
8595
/// one. In the both cases, we often want to do the transformation.
8696
bool isNotInMacro(const ast_matchers::MatchFinder::MatchResult &Result,
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//===--- DurationUnnecessaryConversionCheck.cpp - clang-tidy
2+
//-----------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#include "DurationUnnecessaryConversionCheck.h"
11+
#include "DurationRewriter.h"
12+
#include "clang/AST/ASTContext.h"
13+
#include "clang/ASTMatchers/ASTMatchFinder.h"
14+
#include "clang/Tooling/FixIt.h"
15+
16+
using namespace clang::ast_matchers;
17+
18+
namespace clang {
19+
namespace tidy {
20+
namespace abseil {
21+
22+
void DurationUnnecessaryConversionCheck::registerMatchers(MatchFinder *Finder) {
23+
for (const auto &Scale : {"Hours", "Minutes", "Seconds", "Milliseconds",
24+
"Microseconds", "Nanoseconds"}) {
25+
std::string DurationFactory = (llvm::Twine("::absl::") + Scale).str();
26+
std::string FloatConversion =
27+
(llvm::Twine("::absl::ToDouble") + Scale).str();
28+
std::string IntegerConversion =
29+
(llvm::Twine("::absl::ToInt64") + Scale).str();
30+
31+
Finder->addMatcher(
32+
callExpr(
33+
callee(functionDecl(hasName(DurationFactory))),
34+
hasArgument(0, callExpr(callee(functionDecl(hasAnyName(
35+
FloatConversion, IntegerConversion))),
36+
hasArgument(0, expr().bind("arg")))))
37+
.bind("call"),
38+
this);
39+
}
40+
}
41+
42+
void DurationUnnecessaryConversionCheck::check(
43+
const MatchFinder::MatchResult &Result) {
44+
const auto *OuterCall = Result.Nodes.getNodeAs<Expr>("call");
45+
const auto *Arg = Result.Nodes.getNodeAs<Expr>("arg");
46+
47+
if (!isNotInMacro(Result, OuterCall))
48+
return;
49+
50+
diag(OuterCall->getBeginLoc(), "remove unnecessary absl::Duration conversions")
51+
<< FixItHint::CreateReplacement(
52+
OuterCall->getSourceRange(),
53+
tooling::fixit::getText(*Arg, *Result.Context));
54+
}
55+
56+
} // namespace abseil
57+
} // namespace tidy
58+
} // namespace clang
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===--- DurationUnnecessaryConversionCheck.h - clang-tidy ------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEDOUBLECONVERSIONCHECK_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEDOUBLECONVERSIONCHECK_H
11+
12+
#include "../ClangTidy.h"
13+
14+
namespace clang {
15+
namespace tidy {
16+
namespace abseil {
17+
18+
/// Finds and fixes cases where ``absl::Duration`` values are being converted
19+
/// to numeric types and back again.
20+
///
21+
/// For the user-facing documentation see:
22+
/// http://clang.llvm.org/extra/clang-tidy/checks/abseil-duration-unnecessary-conversion.html
23+
class DurationUnnecessaryConversionCheck : public ClangTidyCheck {
24+
public:
25+
DurationUnnecessaryConversionCheck(StringRef Name, ClangTidyContext *Context)
26+
: ClangTidyCheck(Name, Context) {}
27+
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
28+
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
29+
};
30+
31+
} // namespace abseil
32+
} // namespace tidy
33+
} // namespace clang
34+
35+
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_TIMEDOUBLECONVERSIONCHECK_H

0 commit comments

Comments
 (0)