Skip to content

Commit 10fb587

Browse files
Merge branch 'main' into uint_to_fp
2 parents 75e77f2 + b6960e2 commit 10fb587

File tree

81 files changed

+1191
-3136
lines changed

Some content is hidden

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

81 files changed

+1191
-3136
lines changed

.github/new-prs-labeler.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,11 @@ backend:DirectX:
661661

662662
backend:SPIR-V:
663663
- clang/lib/Driver/ToolChains/SPIRV.*
664+
- clang/lib/Sema/SemaSPIRV.cpp
665+
- clang/include/clang/Sema/SemaSPIRV.h
666+
- clang/include/clang/Basic/BuiltinsSPIRV.td
667+
- clang/test/CodeGenSPIRV/**
668+
- clang/test/SemaSPIRV/**
664669
- llvm/lib/Target/SPIRV/**
665670
- llvm/test/CodeGen/SPIRV/**
666671
- llvm/test/Frontend/HLSL/**
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===--- BuiltinsSPIRV.td - SPIRV Builtin function database ---------*- 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+
include "clang/Basic/BuiltinsBase.td"
10+
11+
def HLSLDistance : Builtin {
12+
let Spellings = ["__builtin_spirv_distance"];
13+
let Attributes = [NoThrow, Const];
14+
let Prototype = "void(...)";
15+
}

clang/include/clang/Basic/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ clang_tablegen(BuiltinsRISCV.inc -gen-clang-builtins
6060
SOURCE BuiltinsRISCV.td
6161
TARGET ClangBuiltinsRISCV)
6262

63+
clang_tablegen(BuiltinsSPIRV.inc -gen-clang-builtins
64+
SOURCE BuiltinsSPIRV.td
65+
TARGET ClangBuiltinsSPIRV)
66+
6367
clang_tablegen(BuiltinsX86.inc -gen-clang-builtins
6468
SOURCE BuiltinsX86.td
6569
TARGET ClangBuiltinsX86)

clang/include/clang/Basic/TargetBuiltins.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ namespace clang {
119119
};
120120
}
121121

122+
/// SPIRV builtins
123+
namespace SPIRV {
124+
enum {
125+
LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1,
126+
#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
127+
#include "clang/Basic/BuiltinsSPIRV.inc"
128+
LastTSBuiltin
129+
};
130+
} // namespace SPIRV
131+
122132
/// X86 builtins
123133
namespace X86 {
124134
enum {

clang/include/clang/Driver/Action.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class Action {
9494
OFK_Cuda = 0x02,
9595
OFK_OpenMP = 0x04,
9696
OFK_HIP = 0x08,
97+
OFK_SYCL = 0x10,
9798
};
9899

99100
static const char *getClassName(ActionClass AC);

clang/include/clang/Driver/Options.td

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ def opencl_Group : OptionGroup<"<opencl group>">, Group<f_Group>,
182182
DocName<"OpenCL options">;
183183

184184
def sycl_Group : OptionGroup<"<SYCL group>">, Group<f_Group>,
185-
DocName<"SYCL options">;
185+
DocName<"SYCL options">,
186+
Visibility<[ClangOption, CLOption]>;
186187

187188
def cuda_Group : OptionGroup<"<CUDA group>">, Group<f_Group>,
188189
DocName<"CUDA options">,
@@ -6839,16 +6840,21 @@ defm : FlangIgnoredDiagOpt<"frontend-loop-interchange">;
68396840
defm : FlangIgnoredDiagOpt<"target-lifetime">;
68406841

68416842
// C++ SYCL options
6843+
let Group = sycl_Group in {
68426844
def fsycl : Flag<["-"], "fsycl">,
6843-
Visibility<[ClangOption, CLOption]>,
6844-
Group<sycl_Group>, HelpText<"Enables SYCL kernels compilation for device">;
6845+
HelpText<"Enable SYCL C++ extensions">;
68456846
def fno_sycl : Flag<["-"], "fno-sycl">,
6846-
Visibility<[ClangOption, CLOption]>,
6847-
Group<sycl_Group>, HelpText<"Disables SYCL kernels compilation for device">;
6847+
HelpText<"Disable SYCL C++ extensions">;
6848+
def fsycl_device_only : Flag<["-"], "fsycl-device-only">,
6849+
Alias<offload_device_only>, HelpText<"Compile SYCL code for device only">;
6850+
def fsycl_host_only : Flag<["-"], "fsycl-host-only">,
6851+
Alias<offload_host_only>, HelpText<"Compile SYCL code for host only. Has no "
6852+
"effect on non-SYCL compilations">;
68486853
def sycl_link : Flag<["--"], "sycl-link">, Flags<[HelpHidden]>,
6849-
Visibility<[ClangOption, CLOption]>,
6850-
Group<sycl_Group>, HelpText<"Perform link through clang-sycl-linker via the target "
6854+
HelpText<"Perform link through clang-sycl-linker via the target "
68516855
"offloading toolchain.">;
6856+
} // let Group = sycl_Group
6857+
68526858
// OS-specific options
68536859
let Flags = [TargetSpecific] in {
68546860
defm android_pad_segment : BooleanFFlag<"android-pad-segment">, Group<f_Group>;

clang/include/clang/Driver/ToolChain.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,10 @@ class ToolChain {
762762
virtual void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
763763
llvm::opt::ArgStringList &CC1Args) const;
764764

765+
/// Add arguments to use system-specific SYCL includes.
766+
virtual void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
767+
llvm::opt::ArgStringList &CC1Args) const;
768+
765769
/// Add arguments to use MCU GCC toolchain includes.
766770
virtual void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
767771
llvm::opt::ArgStringList &CC1Args) const;

clang/include/clang/Sema/Sema.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ class SemaOpenMP;
173173
class SemaPPC;
174174
class SemaPseudoObject;
175175
class SemaRISCV;
176+
class SemaSPIRV;
176177
class SemaSYCL;
177178
class SemaSwift;
178179
class SemaSystemZ;
@@ -1142,6 +1143,11 @@ class Sema final : public SemaBase {
11421143
return *RISCVPtr;
11431144
}
11441145

1146+
SemaSPIRV &SPIRV() {
1147+
assert(SPIRVPtr);
1148+
return *SPIRVPtr;
1149+
}
1150+
11451151
SemaSYCL &SYCL() {
11461152
assert(SYCLPtr);
11471153
return *SYCLPtr;
@@ -1219,6 +1225,7 @@ class Sema final : public SemaBase {
12191225
std::unique_ptr<SemaPPC> PPCPtr;
12201226
std::unique_ptr<SemaPseudoObject> PseudoObjectPtr;
12211227
std::unique_ptr<SemaRISCV> RISCVPtr;
1228+
std::unique_ptr<SemaSPIRV> SPIRVPtr;
12221229
std::unique_ptr<SemaSYCL> SYCLPtr;
12231230
std::unique_ptr<SemaSwift> SwiftPtr;
12241231
std::unique_ptr<SemaSystemZ> SystemZPtr;

clang/include/clang/Sema/SemaSPIRV.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//===----- SemaSPIRV.h ----- Semantic Analysis for SPIRV constructs--------===//
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+
/// \file
9+
/// This file declares semantic analysis for SPIRV constructs.
10+
///
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef LLVM_CLANG_SEMA_SEMASPIRV_H
14+
#define LLVM_CLANG_SEMA_SEMASPIRV_H
15+
16+
#include "clang/AST/ASTFwd.h"
17+
#include "clang/Sema/SemaBase.h"
18+
19+
namespace clang {
20+
class SemaSPIRV : public SemaBase {
21+
public:
22+
SemaSPIRV(Sema &S);
23+
24+
bool CheckSPIRVBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
25+
};
26+
} // namespace clang
27+
28+
#endif // LLVM_CLANG_SEMA_SEMASPIRV_H

clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#ifndef LLVM_ADT_STRINGREF_H
13+
#ifndef LLVM_CLANG_STATICANALYZER_CORE_ANALYZEROPTIONS_H
1414
#error This .def file is expected to be included in translation units where \
15-
"llvm/ADT/StringRef.h" is already included!
15+
"clang/StaticAnalyzer/Core/AnalyzerOptions.h" is already included!
1616
#endif
1717

1818
#ifdef ANALYZER_OPTION
@@ -193,6 +193,8 @@ ANALYZER_OPTION(
193193
"with \"crosscheck-with-z3-timeout-threshold\" of 300 ms, would nicely "
194194
"guarantee that no bug report equivalence class can take longer than "
195195
"1 second, effectively mitigating Z3 hangs during refutation. "
196+
"If there were Z3 retries, only the minimum query time is considered "
197+
"when accumulating query times within a report equivalence class. "
196198
"Set 0 for no timeout.", 0)
197199

198200
ANALYZER_OPTION(
@@ -213,6 +215,15 @@ ANALYZER_OPTION(
213215
"400'000 should on average make Z3 queries run for up to 100ms on modern "
214216
"hardware. Set 0 for unlimited.", 0)
215217

218+
ANALYZER_OPTION(
219+
PositiveAnalyzerOption, Z3CrosscheckMaxAttemptsPerQuery,
220+
"crosscheck-with-z3-max-attempts-per-query",
221+
"Set how many times the oracle is allowed to run a Z3 query. "
222+
"This must be a positive value. Set 1 to not allow any retry attempts. "
223+
"Increasing the number of attempts is often more effective at reducing "
224+
"the number of nondeterministic diagnostics than "
225+
"\"crosscheck-with-z3-timeout-threshold\" in practice.", 3)
226+
216227
ANALYZER_OPTION(bool, ShouldReportIssuesInMainSourceFile,
217228
"report-in-main-source-file",
218229
"Whether or not the diagnostic report should be always "

clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,31 @@ enum UserModeKind {
124124

125125
enum class CTUPhase1InliningKind { None, Small, All };
126126

127+
class PositiveAnalyzerOption {
128+
public:
129+
PositiveAnalyzerOption() = default;
130+
PositiveAnalyzerOption(const PositiveAnalyzerOption &) = default;
131+
PositiveAnalyzerOption &operator=(const PositiveAnalyzerOption &) = default;
132+
133+
static std::optional<PositiveAnalyzerOption> create(unsigned Val) {
134+
if (Val == 0)
135+
return std::nullopt;
136+
return PositiveAnalyzerOption{Val};
137+
}
138+
static std::optional<PositiveAnalyzerOption> create(StringRef Str) {
139+
unsigned Parsed = 0;
140+
if (Str.getAsInteger(0, Parsed))
141+
return std::nullopt;
142+
return PositiveAnalyzerOption::create(Parsed);
143+
}
144+
operator unsigned() const { return Value; }
145+
146+
private:
147+
explicit constexpr PositiveAnalyzerOption(unsigned Value) : Value(Value) {}
148+
149+
unsigned Value = 1;
150+
};
151+
127152
/// Stores options for the analyzer from the command line.
128153
///
129154
/// Some options are frontend flags (e.g.: -analyzer-output), but some are

clang/lib/Basic/Targets/SPIR.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,24 @@
1313
#include "SPIR.h"
1414
#include "AMDGPU.h"
1515
#include "Targets.h"
16+
#include "clang/Basic/MacroBuilder.h"
17+
#include "clang/Basic/TargetBuiltins.h"
1618
#include "llvm/TargetParser/TargetParser.h"
1719

1820
using namespace clang;
1921
using namespace clang::targets;
2022

23+
static constexpr Builtin::Info BuiltinInfo[] = {
24+
#define BUILTIN(ID, TYPE, ATTRS) \
25+
{#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
26+
#include "clang/Basic/BuiltinsSPIRV.inc"
27+
};
28+
29+
ArrayRef<Builtin::Info> SPIRVTargetInfo::getTargetBuiltins() const {
30+
return llvm::ArrayRef(BuiltinInfo,
31+
clang::SPIRV::LastTSBuiltin - Builtin::FirstTSBuiltin);
32+
}
33+
2134
void SPIRTargetInfo::getTargetDefines(const LangOptions &Opts,
2235
MacroBuilder &Builder) const {
2336
DefineStd(Builder, "SPIR", Opts);

clang/lib/Basic/Targets/SPIR.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class LLVM_LIBRARY_VISIBILITY SPIRVTargetInfo : public BaseSPIRVTargetInfo {
313313
resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-"
314314
"v256:256-v512:512-v1024:1024-n8:16:32:64-G1");
315315
}
316-
316+
ArrayRef<Builtin::Info> getTargetBuiltins() const override;
317317
void getTargetDefines(const LangOptions &Opts,
318318
MacroBuilder &Builder) const override;
319319
};

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6797,6 +6797,8 @@ static Value *EmitTargetArchBuiltinExpr(CodeGenFunction *CGF,
67976797
case llvm::Triple::riscv32:
67986798
case llvm::Triple::riscv64:
67996799
return CGF->EmitRISCVBuiltinExpr(BuiltinID, E, ReturnValue);
6800+
case llvm::Triple::spirv:
6801+
return CGF->EmitSPIRVBuiltinExpr(BuiltinID, E);
68006802
case llvm::Triple::spirv64:
68016803
if (CGF->getTarget().getTriple().getOS() != llvm::Triple::OSType::AMDHSA)
68026804
return nullptr;
@@ -20480,6 +20482,26 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
2048020482
}
2048120483
}
2048220484

20485+
Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned BuiltinID,
20486+
const CallExpr *E) {
20487+
switch (BuiltinID) {
20488+
case SPIRV::BI__builtin_spirv_distance: {
20489+
Value *X = EmitScalarExpr(E->getArg(0));
20490+
Value *Y = EmitScalarExpr(E->getArg(1));
20491+
assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
20492+
E->getArg(1)->getType()->hasFloatingRepresentation() &&
20493+
"Distance operands must have a float representation");
20494+
assert(E->getArg(0)->getType()->isVectorType() &&
20495+
E->getArg(1)->getType()->isVectorType() &&
20496+
"Distance operands must be a vector");
20497+
return Builder.CreateIntrinsic(
20498+
/*ReturnType=*/X->getType()->getScalarType(), Intrinsic::spv_distance,
20499+
ArrayRef<Value *>{X, Y}, nullptr, "spv.distance");
20500+
}
20501+
}
20502+
return nullptr;
20503+
}
20504+
2048320505
/// Handle a SystemZ function in which the final argument is a pointer
2048420506
/// to an int that receives the post-instruction CC value. At the LLVM level
2048520507
/// this is represented as a function that returns a {result, cc} pair.

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4756,6 +4756,7 @@ class CodeGenFunction : public CodeGenTypeCache {
47564756
llvm::Value *EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
47574757
llvm::Value *EmitHLSLBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
47584758
ReturnValueSlot ReturnValue);
4759+
llvm::Value *EmitSPIRVBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
47594760
llvm::Value *EmitScalarOrConstFoldImmArg(unsigned ICEArguments, unsigned Idx,
47604761
const CallExpr *E);
47614762
llvm::Value *EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E);

clang/lib/Driver/Action.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ std::string Action::getOffloadingKindPrefix() const {
111111
return "device-openmp";
112112
case OFK_HIP:
113113
return "device-hip";
114+
case OFK_SYCL:
115+
return "device-sycl";
114116

115117
// TODO: Add other programming models here.
116118
}
@@ -128,6 +130,8 @@ std::string Action::getOffloadingKindPrefix() const {
128130
Res += "-hip";
129131
if (ActiveOffloadKindMask & OFK_OpenMP)
130132
Res += "-openmp";
133+
if (ActiveOffloadKindMask & OFK_SYCL)
134+
Res += "-sycl";
131135

132136
// TODO: Add other programming models here.
133137

@@ -164,6 +168,8 @@ StringRef Action::GetOffloadKindName(OffloadKind Kind) {
164168
return "openmp";
165169
case OFK_HIP:
166170
return "hip";
171+
case OFK_SYCL:
172+
return "sycl";
167173

168174
// TODO: Add other programming models here.
169175
}
@@ -320,7 +326,7 @@ void OffloadAction::DeviceDependences::add(Action &A, const ToolChain &TC,
320326
DeviceBoundArchs.push_back(BoundArch);
321327

322328
// Add each active offloading kind from a mask.
323-
for (OffloadKind OKind : {OFK_OpenMP, OFK_Cuda, OFK_HIP})
329+
for (OffloadKind OKind : {OFK_OpenMP, OFK_Cuda, OFK_HIP, OFK_SYCL})
324330
if (OKind & OffloadKindMask)
325331
DeviceOffloadKinds.push_back(OKind);
326332
}

clang/lib/Driver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ add_clang_library(clangDriver
7878
ToolChains/Solaris.cpp
7979
ToolChains/SPIRV.cpp
8080
ToolChains/SPIRVOpenMP.cpp
81+
ToolChains/SYCL.cpp
8182
ToolChains/TCE.cpp
8283
ToolChains/UEFI.cpp
8384
ToolChains/VEToolchain.cpp

clang/lib/Driver/Compilation.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,11 @@ static bool ActionFailed(const Action *A,
214214
if (FailingCommands.empty())
215215
return false;
216216

217-
// CUDA/HIP can have the same input source code compiled multiple times so do
218-
// not compiled again if there are already failures. It is OK to abort the
219-
// CUDA pipeline on errors.
220-
if (A->isOffloading(Action::OFK_Cuda) || A->isOffloading(Action::OFK_HIP))
217+
// CUDA/HIP/SYCL can have the same input source code compiled multiple times
218+
// so do not compile again if there are already failures. It is OK to abort
219+
// the CUDA/HIP/SYCL pipeline on errors.
220+
if (A->isOffloading(Action::OFK_Cuda) || A->isOffloading(Action::OFK_HIP) ||
221+
A->isOffloading(Action::OFK_SYCL))
221222
return true;
222223

223224
for (const auto &CI : FailingCommands)

0 commit comments

Comments
 (0)