diff options
author | Alexey Bataev <a.bataev@hotmail.com> | 2017-12-29 17:36:15 +0000 |
---|---|---|
committer | Alexey Bataev <a.bataev@hotmail.com> | 2017-12-29 17:36:15 +0000 |
commit | 2549be9234b97ad8c3cadd735b1608c1066515d4 (patch) | |
tree | 212cd56819a27234345212ef8a28b361dbf1cf25 | |
parent | 6bea6f7d496d5fefec598d69c1e797e2617dce19 (diff) | |
download | clang-2549be9234b97ad8c3cadd735b1608c1066515d4.tar.gz |
[OPENMP] Initial support for `-fopenmp-simd` option.
Added basic support for `-fopenmp-simd` options.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@321558 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/LangOptions.def | 1 | ||||
-rw-r--r-- | include/clang/Driver/Options.td | 6 | ||||
-rw-r--r-- | lib/Driver/ToolChains/Clang.cpp | 4 | ||||
-rw-r--r-- | lib/Frontend/CompilerInvocation.cpp | 14 | ||||
-rw-r--r-- | lib/Frontend/InitPreprocessor.cpp | 4 | ||||
-rw-r--r-- | test/OpenMP/driver.c | 11 | ||||
-rw-r--r-- | test/OpenMP/linking.c | 10 | ||||
-rw-r--r-- | test/OpenMP/predefined_macro.c | 3 |
8 files changed, 46 insertions, 7 deletions
diff --git a/include/clang/Basic/LangOptions.def b/include/clang/Basic/LangOptions.def index ca3a0e349d..c6ed256dd6 100644 --- a/include/clang/Basic/LangOptions.def +++ b/include/clang/Basic/LangOptions.def @@ -194,6 +194,7 @@ LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns") LANGOPT(HalfArgsAndReturns, 1, 0, "half args and returns") LANGOPT(CUDA , 1, 0, "CUDA") LANGOPT(OpenMP , 32, 0, "OpenMP support and version of OpenMP (31, 40 or 45)") +LANGOPT(OpenMPSimd , 1, 0, "Use SIMD only OpenMP support.") LANGOPT(OpenMPUseTLS , 1, 0, "Use TLS for threadprivates or runtime calls") LANGOPT(OpenMPIsDevice , 1, 0, "Generate code only for OpenMP target device") LANGOPT(RenderScript , 1, 0, "RenderScript") diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 09efd7b0af..7dc6632e82 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -1369,12 +1369,16 @@ def fopenmp_use_tls : Flag<["-"], "fopenmp-use-tls">, Group<f_Group>, Flags<[NoA def fnoopenmp_use_tls : Flag<["-"], "fnoopenmp-use-tls">, Group<f_Group>, Flags<[CC1Option, NoArgumentUnused]>; def fopenmp_targets_EQ : CommaJoined<["-"], "fopenmp-targets=">, Flags<[DriverOption, CC1Option]>, HelpText<"Specify comma-separated list of triples OpenMP offloading targets to be supported">; -def fopenmp_dump_offload_linker_script : Flag<["-"], "fopenmp-dump-offload-linker-script">, Group<f_Group>, +def fopenmp_dump_offload_linker_script : Flag<["-"], "fopenmp-dump-offload-linker-script">, Group<f_Group>, Flags<[NoArgumentUnused]>; def fopenmp_relocatable_target : Flag<["-"], "fopenmp-relocatable-target">, Group<f_Group>, Flags<[CC1Option, NoArgumentUnused]>, HelpText<"OpenMP target code is compiled as relocatable using the -c flag. For OpenMP targets the code is relocatable by default.">; def fnoopenmp_relocatable_target : Flag<["-"], "fnoopenmp-relocatable-target">, Group<f_Group>, Flags<[CC1Option, NoArgumentUnused]>, HelpText<"Do not compile OpenMP target code as relocatable.">; +def fopenmp_simd : Flag<["-"], "fopenmp-simd">, Group<f_Group>, Flags<[CC1Option, NoArgumentUnused]>, + HelpText<"Emit OpenMP code only for SIMD-based constructs.">; +def fno_openmp_simd : Flag<["-"], "fno-openmp-simd">, Group<f_Group>, Flags<[CC1Option, NoArgumentUnused]>, + HelpText<"Disable OpenMP code for SIMD-based constructs.">; def fno_optimize_sibling_calls : Flag<["-"], "fno-optimize-sibling-calls">, Group<f_Group>; def foptimize_sibling_calls : Flag<["-"], "foptimize-sibling-calls">, Group<f_Group>; def force__cpusubtype__ALL : Flag<["-"], "force_cpusubtype_ALL">; diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp index 8b895c4514..c445669a5a 100644 --- a/lib/Driver/ToolChains/Clang.cpp +++ b/lib/Driver/ToolChains/Clang.cpp @@ -3901,6 +3901,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // semantic analysis, etc. break; } + } else { + Args.AddLastArg(CmdArgs, options::OPT_fopenmp_simd, + options::OPT_fno_openmp_simd); + Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ); } const SanitizerArgs &Sanitize = getToolChain().getSanitizerArgs(); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 2e8a737de4..6ce719aac6 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2407,16 +2407,22 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK, // Check if -fopenmp is specified. Opts.OpenMP = Args.hasArg(options::OPT_fopenmp) ? 1 : 0; + // Check if -fopenmp-simd is specified. + Opts.OpenMPSimd = !Opts.OpenMP && Args.hasFlag(options::OPT_fopenmp_simd, + options::OPT_fno_openmp_simd, + /*Default=*/false); Opts.OpenMPUseTLS = Opts.OpenMP && !Args.hasArg(options::OPT_fnoopenmp_use_tls); Opts.OpenMPIsDevice = Opts.OpenMP && Args.hasArg(options::OPT_fopenmp_is_device); - if (Opts.OpenMP) { - int Version = - getLastArgIntValue(Args, OPT_fopenmp_version_EQ, Opts.OpenMP, Diags); - if (Version != 0) + if (Opts.OpenMP || Opts.OpenMPSimd) { + if (int Version = + getLastArgIntValue(Args, OPT_fopenmp_version_EQ, + Opts.OpenMPSimd ? 45 : Opts.OpenMP, Diags)) Opts.OpenMP = Version; + else if (Opts.OpenMPSimd) + Opts.OpenMP = 45; // Provide diagnostic when a given target is not expected to be an OpenMP // device or host. if (!Opts.OpenMPIsDevice) { diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp index d398904943..639050f7c6 100644 --- a/lib/Frontend/InitPreprocessor.cpp +++ b/lib/Frontend/InitPreprocessor.cpp @@ -1021,8 +1021,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI, Builder.defineMacro("_OPENMP", "201511"); break; default: - // Default version is OpenMP 3.1 - Builder.defineMacro("_OPENMP", "201107"); + // Default version is OpenMP 3.1, in Simd only mode - 4.5 + Builder.defineMacro("_OPENMP", LangOpts.OpenMPSimd ? "201511" : "201107"); break; } diff --git a/test/OpenMP/driver.c b/test/OpenMP/driver.c index 74aaea5071..9a2a940d76 100644 --- a/test/OpenMP/driver.c +++ b/test/OpenMP/driver.c @@ -15,15 +15,26 @@ // RUN: %clang %s -c -E -dM -fopenmp=libomp -fopenmp-version=31 | FileCheck --check-prefix=CHECK-DEFAULT-VERSION %s // CHECK-DEFAULT-VERSION: #define _OPENMP 201107 +// RUN: %clang %s -c -E -dM -fopenmp-simd | FileCheck --check-prefix=CHECK-SIMD-DEFAULT-VERSION %s +// RUN: %clang %s -c -E -dM -fopenmp-simd -fopenmp-version=1 | FileCheck --check-prefix=CHECK-SIMD-DEFAULT-VERSION %s +// RUN: %clang %s -c -E -dM -fopenmp-simd -fopenmp-version=0 | FileCheck --check-prefix=CHECK-SIMD-DEFAULT-VERSION %s +// RUN: %clang %s -c -E -dM -fopenmp-simd -fopenmp-version=100 | FileCheck --check-prefix=CHECK-SIMD-DEFAULT-VERSION %s +// RUN: %clang %s -c -E -dM -fopenmp-simd -fopenmp-version=31 | FileCheck --check-prefix=CHECK-SIMD-DEFAULT-VERSION %s +// CHECK-SIMD-DEFAULT-VERSION: #define _OPENMP 201511 + // RUN: %clang %s -c -E -dM -fopenmp=libomp -fopenmp-version=40 | FileCheck --check-prefix=CHECK-40-VERSION %s +// RUN: %clang %s -c -E -dM -fopenmp-simd -fopenmp-version=40 | FileCheck --check-prefix=CHECK-40-VERSION %s // CHECK-40-VERSION: #define _OPENMP 201307 // RUN: %clang %s -c -E -dM -fopenmp=libomp -fopenmp-version=45 | FileCheck --check-prefix=CHECK-45-VERSION %s +// RUN: %clang %s -c -E -dM -fopenmp-simd -fopenmp-version=45 | FileCheck --check-prefix=CHECK-45-VERSION %s // CHECK-45-VERSION: #define _OPENMP 201511 // RUN: %clang %s -c -E -dM -fopenmp-version=1 | FileCheck --check-prefix=CHECK-VERSION %s // RUN: %clang %s -c -E -dM -fopenmp-version=31 | FileCheck --check-prefix=CHECK-VERSION %s // RUN: %clang %s -c -E -dM -fopenmp-version=40 | FileCheck --check-prefix=CHECK-VERSION %s // RUN: %clang %s -c -E -dM -fopenmp-version=45 | FileCheck --check-prefix=CHECK-VERSION %s +// RUN: %clang %s -c -E -dM -fopenmp-version=45 | FileCheck --check-prefix=CHECK-VERSION %s +// RUN: %clang %s -c -E -dM -fopenmp-simd -fno-openmp-simd -fopenmp-version=45 | FileCheck --check-prefix=CHECK-VERSION %s // CHECK-VERSION-NOT: #define _OPENMP diff --git a/test/OpenMP/linking.c b/test/OpenMP/linking.c index 71e978f7fe..7109072c24 100644 --- a/test/OpenMP/linking.c +++ b/test/OpenMP/linking.c @@ -23,6 +23,11 @@ // CHECK-GOMP-LD-32: "{{.*}}ld{{(.exe)?}}" // CHECK-GOMP-LD-32: "-lgomp" "-lrt" // CHECK-GOMP-LD-32: "-lpthread" "-lc" + +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 -fopenmp-simd -target i386-unknown-linux -rtlib=platform | FileCheck --check-prefix SIMD-ONLY2 %s +// SIMD-ONLY2-NOT: lgomp +// SIMD-ONLY2-NOT: lomp +// SIMD-ONLY2-NOT: liomp // // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ // RUN: -fopenmp=libgomp -target x86_64-unknown-linux -rtlib=platform \ @@ -79,6 +84,11 @@ // CHECK-MSVC-LINK-64-SAME: -nodefaultlib:vcompd.lib // CHECK-MSVC-LINK-64-SAME: -libpath:{{.+}}/../lib // CHECK-MSVC-LINK-64-SAME: -defaultlib:libomp.lib + +// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 -fopenmp-simd -target x86_64-msvc-win32 -rtlib=platform | FileCheck --check-prefix SIMD-ONLY11 %s +// SIMD-ONLY11-NOT: libiomp +// SIMD-ONLY11-NOT: libomp +// SIMD-ONLY11-NOT: libgomp // // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ // RUN: -fopenmp=libiomp5 -target x86_64-msvc-win32 -rtlib=platform \ diff --git a/test/OpenMP/predefined_macro.c b/test/OpenMP/predefined_macro.c index e18c3d26d4..af60e957bb 100644 --- a/test/OpenMP/predefined_macro.c +++ b/test/OpenMP/predefined_macro.c @@ -1,5 +1,8 @@ // RUN: %clang_cc1 -fopenmp -verify -DFOPENMP -o - %s // RUN: %clang_cc1 -verify -o - %s + +// RUN: %clang_cc1 -fopenmp-simd -verify -DFOPENMP -o - %s +// RUN: %clang_cc1 -verify -o - %s // expected-no-diagnostics #ifdef FOPENMP // -fopenmp option is specified |