Skip to content

Commit bdc5794

Browse files
committed
Merge from 'master' to 'sycl-web' (#10)
CONFLICT (content): Merge conflict in clang/test/Preprocessor/sycl-macro.cpp CONFLICT (content): Merge conflict in clang/test/Driver/sycl.c CONFLICT (content): Merge conflict in clang/lib/Frontend/CompilerInvocation.cpp CONFLICT (content): Merge conflict in clang/lib/Driver/ToolChains/Clang.cpp CONFLICT (content): Merge conflict in clang/include/clang/Basic/LangOptions.def
2 parents 08318b7 + 740ed61 commit bdc5794

File tree

109 files changed

+3562
-2042
lines changed

Some content is hidden

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

109 files changed

+3562
-2042
lines changed

clang/include/clang/Basic/LangOptions.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ LANGOPT(OpenCL , 1, 0, "OpenCL")
204204
LANGOPT(OpenCLVersion , 32, 0, "OpenCL C version")
205205
LANGOPT(OpenCLCPlusPlus , 1, 0, "C++ for OpenCL")
206206
LANGOPT(OpenCLCPlusPlusVersion , 32, 0, "C++ for OpenCL version")
207+
ENUM_LANGOPT(SYCLVersion, SYCLVersionList, 4, SYCLVersionList::undefined, "Version of the SYCL standard used")
207208
LANGOPT(NativeHalfType , 1, 0, "Native half type support")
208209
LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns")
209210
LANGOPT(HalfArgsAndReturns, 1, 0, "half args and returns")
@@ -230,13 +231,11 @@ LANGOPT(GPURelocatableDeviceCode, 1, 0, "generate relocatable device code")
230231
LANGOPT(GPUAllowDeviceInit, 1, 0, "allowing device side global init functions for HIP")
231232
LANGOPT(GPUMaxThreadsPerBlock, 32, 256, "default max threads per block for kernel launch bounds for HIP")
232233

233-
LANGOPT(SYCL , 1, 0, "SYCL")
234234
LANGOPT(SYCLIsDevice , 1, 0, "Generate code for SYCL device")
235235
LANGOPT(SYCLIsHost , 1, 0, "SYCL host compilation")
236236
LANGOPT(SYCLAllowFuncPtr , 1, 0, "Allow function pointers in SYCL device code")
237237
LANGOPT(SYCLStdLayoutKernelParams, 1, 0, "Enable standard layout requirement for SYCL kernel parameters")
238238
LANGOPT(SYCLUnnamedLambda , 1, 0, "Allow unnamed lambda SYCL kernels")
239-
LANGOPT(SYCLVersion , 32, 0, "Version of the SYCL standard used")
240239

241240
LANGOPT(HIPUseNewLaunchAPI, 1, 0, "Use new kernel launching API for HIP")
242241

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,8 @@ def cl_no_signed_zeros : Flag<["-"], "cl-no-signed-zeros">, Group<opencl_Group>,
545545
HelpText<"OpenCL only. Allow use of less precise no signed zeros computations in the generated binary.">;
546546
def cl_std_EQ : Joined<["-"], "cl-std=">, Group<opencl_Group>, Flags<[CC1Option]>,
547547
HelpText<"OpenCL language standard to compile for.">, Values<"cl,CL,cl1.1,CL1.1,cl1.2,CL1.2,cl2.0,CL2.0,clc++,CLC++">;
548+
def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group<sycl_Group>, Flags<[CC1Option]>,
549+
HelpText<"SYCL language standard to compile for.">, Values<"1.2.1">;
548550
def cl_denorms_are_zero : Flag<["-"], "cl-denorms-are-zero">, Group<opencl_Group>,
549551
HelpText<"OpenCL only. Allow denormals to be flushed to zero.">;
550552
def cl_fp32_correctly_rounded_divide_sqrt : Flag<["-"], "cl-fp32-correctly-rounded-divide-sqrt">, Group<opencl_Group>, Flags<[CC1Option]>,
@@ -3477,13 +3479,10 @@ defm underscoring : BooleanFFlag<"underscoring">, Group<gfortran_Group>;
34773479
defm whole_file : BooleanFFlag<"whole-file">, Group<gfortran_Group>;
34783480

34793481
// C++ SYCL options
3480-
def fsycl : Flag<["-"], "fsycl">, Group<sycl_Group>, Flags<[CC1Option, CoreOption]>,
3482+
def fsycl : Flag<["-"], "fsycl">, Group<sycl_Group>, Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
34813483
HelpText<"Enable SYCL kernels compilation for device">;
3482-
def fno_sycl : Flag<["-"], "fno-sycl">, Group<sycl_Group>, Flags<[CoreOption]>,
3483-
HelpText<"Disable SYCL kernels compilation for device">;
3484-
def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group<sycl_Group>, Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
3485-
HelpText<"SYCL language standard to compile for.">, Values<"2017, 121, 1.2.1, sycl-1.2.1">;
3486-
3484+
def fno_sycl : Flag<["-"], "fno-sycl">, Group<sycl_Group>,
3485+
HelpText<"Disable SYCL kernels compilation for device">, Flags<[NoArgumentUnused, CoreOption]>;
34873486
def reuse_exe_EQ : Joined<["-"], "reuse-exe=">,
34883487
HelpText<"Speed up FPGA aoc compile if the device code in <exe> is unchanged.">,
34893488
MetaVarName<"<exe>">;

clang/lib/AST/Mangle.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ enum CCMangling {
5050
CCM_Fast,
5151
CCM_RegCall,
5252
CCM_Vector,
53-
CCM_Std
53+
CCM_Std,
54+
CCM_WasmMainArgcArgv
5455
};
5556

5657
static bool isExternC(const NamedDecl *ND) {
@@ -63,6 +64,16 @@ static CCMangling getCallingConvMangling(const ASTContext &Context,
6364
const NamedDecl *ND) {
6465
const TargetInfo &TI = Context.getTargetInfo();
6566
const llvm::Triple &Triple = TI.getTriple();
67+
68+
// On wasm, the argc/argv form of "main" is renamed so that the startup code
69+
// can call it with the correct function signature.
70+
// On Emscripten, users may be exporting "main" and expecting to call it
71+
// themselves, so we can't mangle it.
72+
if (Triple.isWasm() && !Triple.isOSEmscripten())
73+
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND))
74+
if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2)
75+
return CCM_WasmMainArgcArgv;
76+
6677
if (!Triple.isOSWindows() || !Triple.isX86())
6778
return CCM_Other;
6879

@@ -143,6 +154,12 @@ void MangleContext::mangleName(const NamedDecl *D, raw_ostream &Out) {
143154

144155
const ASTContext &ASTContext = getASTContext();
145156
CCMangling CC = getCallingConvMangling(ASTContext, D);
157+
158+
if (CC == CCM_WasmMainArgcArgv) {
159+
Out << "__main_argc_argv";
160+
return;
161+
}
162+
146163
bool MCXX = shouldMangleCXXName(D);
147164
const TargetInfo &TI = Context.getTargetInfo();
148165
if (CC == CCM_Other || (MCXX && TI.getCXXABI() == TargetCXXABI::Microsoft)) {

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ void CodeGenModule::Release() {
464464
CodeGenFunction(*this).EmitCfiCheckStub();
465465
}
466466
emitAtAvailableLinkGuard();
467+
if (Context.getTargetInfo().getTriple().isWasm() &&
468+
!Context.getTargetInfo().getTriple().isOSEmscripten()) {
469+
EmitMainVoidAlias();
470+
}
467471
emitLLVMUsed();
468472
if (SanStats)
469473
SanStats->finish();
@@ -5807,6 +5811,17 @@ void CodeGenModule::EmitDeferredUnusedCoverageMappings() {
58075811
}
58085812
}
58095813

5814+
void CodeGenModule::EmitMainVoidAlias() {
5815+
// In order to transition away from "__original_main" gracefully, emit an
5816+
// alias for "main" in the no-argument case so that libc can detect when
5817+
// new-style no-argument main is in used.
5818+
if (llvm::Function *F = getModule().getFunction("main")) {
5819+
if (!F->isDeclaration() && F->arg_size() == 0 && !F->isVarArg() &&
5820+
F->getReturnType()->isIntegerTy(Context.getTargetInfo().getIntWidth()))
5821+
addUsedGlobal(llvm::GlobalAlias::create("__main_void", F));
5822+
}
5823+
}
5824+
58105825
/// Turns the given pointer into a constant.
58115826
static llvm::Constant *GetPointerConstant(llvm::LLVMContext &Context,
58125827
const void *Ptr) {

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,6 +1036,9 @@ class CodeGenModule : public CodeGenTypeCache {
10361036
/// for the uninstrumented functions.
10371037
void EmitDeferredUnusedCoverageMappings();
10381038

1039+
/// Emit an alias for "main" if it has no arguments (needed for wasm).
1040+
void EmitMainVoidAlias();
1041+
10391042
/// Tell the consumer that this variable has been instantiated.
10401043
void HandleCXXStaticMemberVarInstantiation(VarDecl *VD);
10411044

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4080,7 +4080,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
40804080

40814081
if (UseSYCLTriple) {
40824082
// We want to compile sycl kernels.
4083-
CmdArgs.push_back("-fsycl");
40844083
CmdArgs.push_back("-fsycl-is-device");
40854084
// Pass the triple of host when doing SYCL
40864085
auto AuxT = llvm::Triple(llvm::sys::getProcessTriple());
@@ -4120,7 +4119,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
41204119
CmdArgs.push_back("-fsycl-std-layout-kernel-params");
41214120
} else if (IsSYCL) {
41224121
// Ensure the default version in SYCL mode is 1.2.1
4123-
CmdArgs.push_back("-sycl-std=2017");
4122+
CmdArgs.push_back("-sycl-std=1.2.1");
41244123
}
41254124

41264125
if (IsOpenMPDevice) {

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,22 +2538,22 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
25382538
LangStd = OpenCLLangStd;
25392539
}
25402540

2541-
Opts.SYCL = Args.hasArg(options::OPT_fsycl);
2542-
Opts.SYCLIsDevice = Opts.SYCL && Args.hasArg(options::OPT_fsycl_is_device);
2543-
if (Opts.SYCL) {
2544-
// -sycl-std applies to any SYCL source, not only those containing kernels,
2545-
// but also those using the SYCL API
2546-
if (const Arg *A = Args.getLastArg(OPT_sycl_std_EQ)) {
2547-
Opts.SYCLVersion = llvm::StringSwitch<unsigned>(A->getValue())
2548-
.Cases("2017", "1.2.1", "121", "sycl-1.2.1", 2017)
2549-
.Default(0U);
2550-
2551-
if (Opts.SYCLVersion == 0U) {
2552-
// User has passed an invalid value to the flag, this is an error
2553-
Diags.Report(diag::err_drv_invalid_value)
2554-
<< A->getAsString(Args) << A->getValue();
2555-
}
2541+
// -sycl-std applies to any SYCL source, not only those containing kernels,
2542+
// but also those using the SYCL API
2543+
if(const Arg *A = Args.getLastArg(OPT_sycl_std_EQ)) {
2544+
Opts.setSYCLVersion(llvm::StringSwitch<LangOptions::SYCLVersionList>(A->getValue())
2545+
.Cases("1.2.1", "121", "sycl-1.2.1", LangOptions::SYCLVersionList::sycl_1_2_1)
2546+
.Default(LangOptions::SYCLVersionList::undefined));
2547+
2548+
if (Opts.getSYCLVersion() == LangOptions::SYCLVersionList::undefined) {
2549+
// User has passed an invalid value to the flag, this is an error
2550+
Diags.Report(diag::err_drv_invalid_value)
2551+
<< A->getAsString(Args) << A->getValue();
25562552
}
2553+
} else if (Args.hasArg(options::OPT_fsycl_is_device)
2554+
|| Args.hasArg(options::OPT_fsycl_is_host)
2555+
|| Args.hasArg(options::OPT_fsycl)) {
2556+
Opts.setSYCLVersion(LangOptions::SYCLVersionList::sycl_1_2_1);
25572557
}
25582558

25592559
Opts.IncludeDefaultHeader = Args.hasArg(OPT_finclude_default_header);

clang/lib/Frontend/InitHeaderSearch.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,7 @@ void InitHeaderSearch::AddDefaultIncludePaths(const LangOptions &Lang,
433433
break;
434434

435435
case llvm::Triple::UnknownOS:
436-
if (triple.getArch() == llvm::Triple::wasm32 ||
437-
triple.getArch() == llvm::Triple::wasm64)
436+
if (triple.isWasm())
438437
return;
439438
break;
440439
}

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,10 +461,15 @@ static void InitializeStandardPredefinedMacros(const TargetInfo &TI,
461461
Builder.defineMacro("__FAST_RELAXED_MATH__");
462462
}
463463

464-
if (LangOpts.SYCL) {
465-
// SYCL Version is set to a value when building SYCL applications
466-
if (LangOpts.SYCLVersion == 2017)
464+
// SYCL Version is set to a value when building SYCL applications
465+
switch (LangOpts.getSYCLVersion()) {
466+
case LangOptions::SYCLVersionList::sycl_1_2_1:
467467
Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121");
468+
break;
469+
case LangOptions::SYCLVersionList::undefined:
470+
default:
471+
// This is not a SYCL source, nothing to add
472+
break;
468473
}
469474

470475
// Not "standard" per se, but available even with the -undef flag.

clang/test/CodeGen/wasm-call-main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -triple wasm32 -o - -emit-llvm %s | FileCheck %s
2+
3+
// Mangle argc/argv main even when it's not defined in this TU.
4+
5+
#include <stddef.h>
6+
7+
int main(int argc, char *argv[]);
8+
9+
int foo(void) {
10+
return main(0, NULL);
11+
}
12+
13+
// CHECK: call i32 @__main_argc_argv(

0 commit comments

Comments
 (0)