forked from OSchip/llvm-project
[OpenMP] Make default OpenMP library (the one selected with just -fopenmp)
configurable in the CMake build. There shouldn't be any change in default behavior. Derived from a patch by Daniel Jasper! llvm-svn: 237850
This commit is contained in:
parent
477300d333
commit
31d1de2229
|
@ -441,6 +441,11 @@ if(CLANG_ENABLE_STATIC_ANALYZER)
|
|||
add_definitions(-DCLANG_ENABLE_STATIC_ANALYZER)
|
||||
endif()
|
||||
|
||||
set(OPENMP_DEFAULT_LIB "" CACHE STRING "OpenMP library used by default for -fopenmp.")
|
||||
if(OPENMP_DEFAULT_LIB)
|
||||
add_definitions(-DOPENMP_DEFAULT_LIB=${OPENMP_DEFAULT_LIB})
|
||||
endif()
|
||||
|
||||
# Clang version information
|
||||
set(CLANG_EXECUTABLE_VERSION
|
||||
"${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
|
||||
|
|
|
@ -6221,6 +6221,27 @@ enum LibOpenMP {
|
|||
LibIOMP5
|
||||
};
|
||||
|
||||
/// Map a -fopenmp=<blah> macro to the corresponding library.
|
||||
static LibOpenMP getOpenMPLibByName(StringRef Name) {
|
||||
return llvm::StringSwitch<LibOpenMP>(Name).Case("libgomp", LibGOMP)
|
||||
.Case("libiomp5", LibIOMP5)
|
||||
.Default(LibUnknown);
|
||||
}
|
||||
|
||||
/// Get the default -l<blah> flag to use for -fopenmp, if no library is
|
||||
/// specified. This can be overridden at configure time.
|
||||
static const char *getDefaultOpenMPLibFlag() {
|
||||
#ifndef OPENMP_DEFAULT_LIB
|
||||
#define OPENMP_DEFAULT_LIB iomp5
|
||||
#endif
|
||||
|
||||
#define STR2(lib) #lib
|
||||
#define STR(lib) STR2(lib)
|
||||
return "-l" STR(OPENMP_DEFAULT_LIB);
|
||||
#undef STR
|
||||
#undef STR2
|
||||
}
|
||||
|
||||
void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
||||
const InputInfo &Output,
|
||||
const InputInfoList &Inputs,
|
||||
|
@ -6278,27 +6299,21 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
|
||||
Args.AddAllArgs(CmdArgs, options::OPT_L);
|
||||
|
||||
LibOpenMP UsedOpenMPLib = LibUnknown;
|
||||
if (const Arg *A = Args.getLastArg(options::OPT_fopenmp_EQ)) {
|
||||
UsedOpenMPLib = llvm::StringSwitch<LibOpenMP>(A->getValue())
|
||||
.Case("libgomp", LibGOMP)
|
||||
.Case("libiomp5", LibIOMP5)
|
||||
.Default(LibUnknown);
|
||||
if (UsedOpenMPLib == LibUnknown)
|
||||
switch (getOpenMPLibByName(A->getValue())) {
|
||||
case LibGOMP:
|
||||
CmdArgs.push_back("-lgomp");
|
||||
break;
|
||||
case LibIOMP5:
|
||||
CmdArgs.push_back("-liomp5");
|
||||
break;
|
||||
case LibUnknown:
|
||||
getToolChain().getDriver().Diag(diag::err_drv_unsupported_option_argument)
|
||||
<< A->getOption().getName() << A->getValue();
|
||||
break;
|
||||
}
|
||||
} else if (Args.hasArg(options::OPT_fopenmp)) {
|
||||
UsedOpenMPLib = LibIOMP5;
|
||||
}
|
||||
switch (UsedOpenMPLib) {
|
||||
case LibGOMP:
|
||||
CmdArgs.push_back("-lgomp");
|
||||
break;
|
||||
case LibIOMP5:
|
||||
CmdArgs.push_back("-liomp5");
|
||||
break;
|
||||
case LibUnknown:
|
||||
break;
|
||||
CmdArgs.push_back(getDefaultOpenMPLibFlag());
|
||||
}
|
||||
|
||||
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs);
|
||||
|
@ -8003,37 +8018,33 @@ void gnutools::Link::ConstructJob(Compilation &C, const JobAction &JA,
|
|||
if (NeedsSanitizerDeps)
|
||||
linkSanitizerRuntimeDeps(ToolChain, CmdArgs);
|
||||
|
||||
LibOpenMP UsedOpenMPLib = LibUnknown;
|
||||
bool WantPthread = true;
|
||||
if (const Arg *A = Args.getLastArg(options::OPT_fopenmp_EQ)) {
|
||||
UsedOpenMPLib = llvm::StringSwitch<LibOpenMP>(A->getValue())
|
||||
.Case("libgomp", LibGOMP)
|
||||
.Case("libiomp5", LibIOMP5)
|
||||
.Default(LibUnknown);
|
||||
if (UsedOpenMPLib == LibUnknown)
|
||||
switch (getOpenMPLibByName(A->getValue())) {
|
||||
case LibGOMP:
|
||||
CmdArgs.push_back("-lgomp");
|
||||
|
||||
// FIXME: Exclude this for platforms with libgomp that don't require
|
||||
// librt. Most modern Linux platforms require it, but some may not.
|
||||
CmdArgs.push_back("-lrt");
|
||||
break;
|
||||
case LibIOMP5:
|
||||
CmdArgs.push_back("-liomp5");
|
||||
break;
|
||||
case LibUnknown:
|
||||
D.Diag(diag::err_drv_unsupported_option_argument)
|
||||
<< A->getOption().getName() << A->getValue();
|
||||
break;
|
||||
}
|
||||
} else if (Args.hasArg(options::OPT_fopenmp)) {
|
||||
UsedOpenMPLib = LibIOMP5;
|
||||
}
|
||||
switch (UsedOpenMPLib) {
|
||||
case LibGOMP:
|
||||
CmdArgs.push_back("-lgomp");
|
||||
|
||||
// FIXME: Exclude this for platforms with libgomp that don't require
|
||||
// librt. Most modern Linux platforms require it, but some may not.
|
||||
CmdArgs.push_back("-lrt");
|
||||
break;
|
||||
case LibIOMP5:
|
||||
CmdArgs.push_back("-liomp5");
|
||||
break;
|
||||
case LibUnknown:
|
||||
break;
|
||||
CmdArgs.push_back(getDefaultOpenMPLibFlag());
|
||||
} else {
|
||||
WantPthread = Args.hasArg(options::OPT_pthread) ||
|
||||
Args.hasArg(options::OPT_pthreads);
|
||||
}
|
||||
AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
|
||||
|
||||
if ((Args.hasArg(options::OPT_pthread) ||
|
||||
Args.hasArg(options::OPT_pthreads) || UsedOpenMPLib != LibUnknown) &&
|
||||
!isAndroid)
|
||||
if (WantPthread && !isAndroid)
|
||||
CmdArgs.push_back("-lpthread");
|
||||
|
||||
CmdArgs.push_back("-lc");
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
// Test the that the driver produces reasonable linker invocations with
|
||||
// -fopenmp or -fopenmp|libgomp.
|
||||
//
|
||||
// FIXME: Replace DEFAULT_OPENMP_LIB below with the value chosen at configure time.
|
||||
//
|
||||
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
|
||||
// RUN: -fopenmp -target i386-unknown-linux \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-LD-32 %s
|
||||
// CHECK-LD-32: "{{.*}}ld{{(.exe)?}}"
|
||||
// CHECK-LD-32: "-liomp5" "-lgcc"
|
||||
// CHECK-LD-32: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]" "-lgcc"
|
||||
// CHECK-LD-32: "-lpthread" "-lc"
|
||||
//
|
||||
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
|
||||
// RUN: -fopenmp -target x86_64-unknown-linux \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-LD-64 %s
|
||||
// CHECK-LD-64: "{{.*}}ld{{(.exe)?}}"
|
||||
// CHECK-LD-64: "-liomp5" "-lgcc"
|
||||
// CHECK-LD-64: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]" "-lgcc"
|
||||
// CHECK-LD-64: "-lpthread" "-lc"
|
||||
//
|
||||
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
|
||||
|
@ -33,14 +35,14 @@
|
|||
// RUN: -fopenmp -target i386-unknown-linux \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-IOMP5-LD-32 %s
|
||||
// CHECK-IOMP5-LD-32: "{{.*}}ld{{(.exe)?}}"
|
||||
// CHECK-IOMP5-LD-32: "-liomp5" "-lgcc"
|
||||
// CHECK-IOMP5-LD-32: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]" "-lgcc"
|
||||
// CHECK-IOMP5-LD-32: "-lpthread" "-lc"
|
||||
//
|
||||
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
|
||||
// RUN: -fopenmp -target x86_64-unknown-linux \
|
||||
// RUN: | FileCheck --check-prefix=CHECK-IOMP5-LD-64 %s
|
||||
// CHECK-IOMP5-LD-64: "{{.*}}ld{{(.exe)?}}"
|
||||
// CHECK-IOMP5-LD-64: "-liomp5" "-lgcc"
|
||||
// CHECK-IOMP5-LD-64: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]" "-lgcc"
|
||||
// CHECK-IOMP5-LD-64: "-lpthread" "-lc"
|
||||
//
|
||||
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
|
||||
|
|
Loading…
Reference in New Issue