2011-04-05 07:16:36 +08:00
|
|
|
//===--- CreateInvocationFromCommandLine.cpp - CompilerInvocation from Args ==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Construct a compiler invocation object for command line driver arguments
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Frontend/Utils.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Basic/DiagnosticOptions.h"
|
2011-04-05 07:16:36 +08:00
|
|
|
#include "clang/Driver/Compilation.h"
|
|
|
|
#include "clang/Driver/Driver.h"
|
2015-07-14 07:27:56 +08:00
|
|
|
#include "clang/Driver/Action.h"
|
2011-04-05 07:16:36 +08:00
|
|
|
#include "clang/Driver/Options.h"
|
|
|
|
#include "clang/Driver/Tool.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/Frontend/CompilerInstance.h"
|
|
|
|
#include "clang/Frontend/FrontendDiagnostic.h"
|
2013-06-15 01:17:23 +08:00
|
|
|
#include "llvm/Option/ArgList.h"
|
2011-04-05 07:16:36 +08:00
|
|
|
#include "llvm/Support/Host.h"
|
|
|
|
using namespace clang;
|
2013-06-15 01:17:23 +08:00
|
|
|
using namespace llvm::opt;
|
2011-04-05 07:16:36 +08:00
|
|
|
|
|
|
|
/// createInvocationFromCommandLine - Construct a compiler invocation object for
|
|
|
|
/// a command line argument vector.
|
|
|
|
///
|
|
|
|
/// \return A CompilerInvocation, or 0 if none was built for the given
|
|
|
|
/// argument vector.
|
|
|
|
CompilerInvocation *
|
2011-07-24 01:14:25 +08:00
|
|
|
clang::createInvocationFromCommandLine(ArrayRef<const char *> ArgList,
|
2012-02-20 22:00:23 +08:00
|
|
|
IntrusiveRefCntPtr<DiagnosticsEngine> Diags) {
|
2014-07-05 11:08:06 +08:00
|
|
|
if (!Diags.get()) {
|
2011-04-05 07:16:36 +08:00
|
|
|
// No diagnostics engine was provided, so create our own diagnostics object
|
|
|
|
// with the default options.
|
2013-01-20 09:58:28 +08:00
|
|
|
Diags = CompilerInstance::createDiagnostics(new DiagnosticOptions);
|
2011-04-05 07:16:36 +08:00
|
|
|
}
|
|
|
|
|
2015-11-19 00:14:27 +08:00
|
|
|
SmallVector<const char *, 16> Args(ArgList.begin(), ArgList.end());
|
2011-04-05 07:16:36 +08:00
|
|
|
|
2012-05-22 04:11:54 +08:00
|
|
|
// FIXME: Find a cleaner way to force the driver into restricted modes.
|
2011-04-05 07:16:36 +08:00
|
|
|
Args.push_back("-fsyntax-only");
|
|
|
|
|
|
|
|
// FIXME: We shouldn't have to pass in the path info.
|
2015-11-19 00:14:27 +08:00
|
|
|
driver::Driver TheDriver(Args[0], llvm::sys::getDefaultTargetTriple(),
|
2014-05-16 06:26:36 +08:00
|
|
|
*Diags);
|
2011-04-05 07:16:36 +08:00
|
|
|
|
|
|
|
// Don't check that inputs exist, they may have been remapped.
|
|
|
|
TheDriver.setCheckInputsExist(false);
|
|
|
|
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<driver::Compilation> C(TheDriver.BuildCompilation(Args));
|
2011-04-05 07:16:36 +08:00
|
|
|
|
|
|
|
// Just print the cc1 options if -### was present.
|
|
|
|
if (C->getArgs().hasArg(driver::options::OPT__HASH_HASH_HASH)) {
|
2013-09-13 02:23:34 +08:00
|
|
|
C->getJobs().Print(llvm::errs(), "\n", true);
|
2014-05-22 12:46:25 +08:00
|
|
|
return nullptr;
|
2011-04-05 07:16:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// We expect to get back exactly one command job, if we didn't something
|
[CUDA][OpenMP] Create generic offload action
Summary:
This patch replaces the CUDA specific action by a generic offload action. The offload action may have multiple dependences classier in “host” and “device”. The way this generic offloading action is used is very similar to what is done today by the CUDA implementation: it is used to set a specific toolchain and architecture to its dependences during the generation of jobs.
This patch also proposes propagating the offloading information through the action graph so that that information can be easily retrieved at any time during the generation of commands. This allows e.g. the "clang tool” to evaluate whether CUDA should be supported for the device or host and ptas to easily retrieve the target architecture.
This is an example of how the action graphs would look like (compilation of a single CUDA file with two GPU architectures)
```
0: input, "cudatests.cu", cuda, (host-cuda)
1: preprocessor, {0}, cuda-cpp-output, (host-cuda)
2: compiler, {1}, ir, (host-cuda)
3: input, "cudatests.cu", cuda, (device-cuda, sm_35)
4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_35)
5: compiler, {4}, ir, (device-cuda, sm_35)
6: backend, {5}, assembler, (device-cuda, sm_35)
7: assembler, {6}, object, (device-cuda, sm_35)
8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_35)" {7}, object
9: offload, "device-cuda (nvptx64-nvidia-cuda:sm_35)" {6}, assembler
10: input, "cudatests.cu", cuda, (device-cuda, sm_37)
11: preprocessor, {10}, cuda-cpp-output, (device-cuda, sm_37)
12: compiler, {11}, ir, (device-cuda, sm_37)
13: backend, {12}, assembler, (device-cuda, sm_37)
14: assembler, {13}, object, (device-cuda, sm_37)
15: offload, "device-cuda (nvptx64-nvidia-cuda:sm_37)" {14}, object
16: offload, "device-cuda (nvptx64-nvidia-cuda:sm_37)" {13}, assembler
17: linker, {8, 9, 15, 16}, cuda-fatbin, (device-cuda)
18: offload, "host-cuda (powerpc64le-unknown-linux-gnu)" {2}, "device-cuda (nvptx64-nvidia-cuda)" {17}, ir
19: backend, {18}, assembler
20: assembler, {19}, object
21: input, "cuda", object
22: input, "cudart", object
23: linker, {20, 21, 22}, image
```
The changes in this patch pass the existent regression tests (keeps the existent functionality) and resulting binaries execute correctly in a Power8+K40 machine.
Reviewers: echristo, hfinkel, jlebar, ABataev, tra
Subscribers: guansong, andreybokhanko, tcramer, mkuron, cfe-commits, arpith-jacob, carlo.bertolli, caomhin
Differential Revision: https://reviews.llvm.org/D18171
llvm-svn: 275645
2016-07-16 07:13:27 +08:00
|
|
|
// failed. Offload compilation is an exception as it creates multiple jobs. If
|
|
|
|
// that's the case, we proceed with the first job. If caller needs a
|
|
|
|
// particular job, it should be controlled via options (e.g.
|
|
|
|
// --cuda-{host|device}-only for CUDA) passed to the driver.
|
2011-04-05 07:16:36 +08:00
|
|
|
const driver::JobList &Jobs = C->getJobs();
|
[CUDA][OpenMP] Create generic offload action
Summary:
This patch replaces the CUDA specific action by a generic offload action. The offload action may have multiple dependences classier in “host” and “device”. The way this generic offloading action is used is very similar to what is done today by the CUDA implementation: it is used to set a specific toolchain and architecture to its dependences during the generation of jobs.
This patch also proposes propagating the offloading information through the action graph so that that information can be easily retrieved at any time during the generation of commands. This allows e.g. the "clang tool” to evaluate whether CUDA should be supported for the device or host and ptas to easily retrieve the target architecture.
This is an example of how the action graphs would look like (compilation of a single CUDA file with two GPU architectures)
```
0: input, "cudatests.cu", cuda, (host-cuda)
1: preprocessor, {0}, cuda-cpp-output, (host-cuda)
2: compiler, {1}, ir, (host-cuda)
3: input, "cudatests.cu", cuda, (device-cuda, sm_35)
4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_35)
5: compiler, {4}, ir, (device-cuda, sm_35)
6: backend, {5}, assembler, (device-cuda, sm_35)
7: assembler, {6}, object, (device-cuda, sm_35)
8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_35)" {7}, object
9: offload, "device-cuda (nvptx64-nvidia-cuda:sm_35)" {6}, assembler
10: input, "cudatests.cu", cuda, (device-cuda, sm_37)
11: preprocessor, {10}, cuda-cpp-output, (device-cuda, sm_37)
12: compiler, {11}, ir, (device-cuda, sm_37)
13: backend, {12}, assembler, (device-cuda, sm_37)
14: assembler, {13}, object, (device-cuda, sm_37)
15: offload, "device-cuda (nvptx64-nvidia-cuda:sm_37)" {14}, object
16: offload, "device-cuda (nvptx64-nvidia-cuda:sm_37)" {13}, assembler
17: linker, {8, 9, 15, 16}, cuda-fatbin, (device-cuda)
18: offload, "host-cuda (powerpc64le-unknown-linux-gnu)" {2}, "device-cuda (nvptx64-nvidia-cuda)" {17}, ir
19: backend, {18}, assembler
20: assembler, {19}, object
21: input, "cuda", object
22: input, "cudart", object
23: linker, {20, 21, 22}, image
```
The changes in this patch pass the existent regression tests (keeps the existent functionality) and resulting binaries execute correctly in a Power8+K40 machine.
Reviewers: echristo, hfinkel, jlebar, ABataev, tra
Subscribers: guansong, andreybokhanko, tcramer, mkuron, cfe-commits, arpith-jacob, carlo.bertolli, caomhin
Differential Revision: https://reviews.llvm.org/D18171
llvm-svn: 275645
2016-07-16 07:13:27 +08:00
|
|
|
bool OffloadCompilation = false;
|
2015-07-14 07:27:56 +08:00
|
|
|
if (Jobs.size() > 1) {
|
|
|
|
for (auto &A : C->getActions()){
|
|
|
|
// On MacOSX real actions may end up being wrapped in BindArchAction
|
|
|
|
if (isa<driver::BindArchAction>(A))
|
2016-02-24 03:30:43 +08:00
|
|
|
A = *A->input_begin();
|
[CUDA][OpenMP] Create generic offload action
Summary:
This patch replaces the CUDA specific action by a generic offload action. The offload action may have multiple dependences classier in “host” and “device”. The way this generic offloading action is used is very similar to what is done today by the CUDA implementation: it is used to set a specific toolchain and architecture to its dependences during the generation of jobs.
This patch also proposes propagating the offloading information through the action graph so that that information can be easily retrieved at any time during the generation of commands. This allows e.g. the "clang tool” to evaluate whether CUDA should be supported for the device or host and ptas to easily retrieve the target architecture.
This is an example of how the action graphs would look like (compilation of a single CUDA file with two GPU architectures)
```
0: input, "cudatests.cu", cuda, (host-cuda)
1: preprocessor, {0}, cuda-cpp-output, (host-cuda)
2: compiler, {1}, ir, (host-cuda)
3: input, "cudatests.cu", cuda, (device-cuda, sm_35)
4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_35)
5: compiler, {4}, ir, (device-cuda, sm_35)
6: backend, {5}, assembler, (device-cuda, sm_35)
7: assembler, {6}, object, (device-cuda, sm_35)
8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_35)" {7}, object
9: offload, "device-cuda (nvptx64-nvidia-cuda:sm_35)" {6}, assembler
10: input, "cudatests.cu", cuda, (device-cuda, sm_37)
11: preprocessor, {10}, cuda-cpp-output, (device-cuda, sm_37)
12: compiler, {11}, ir, (device-cuda, sm_37)
13: backend, {12}, assembler, (device-cuda, sm_37)
14: assembler, {13}, object, (device-cuda, sm_37)
15: offload, "device-cuda (nvptx64-nvidia-cuda:sm_37)" {14}, object
16: offload, "device-cuda (nvptx64-nvidia-cuda:sm_37)" {13}, assembler
17: linker, {8, 9, 15, 16}, cuda-fatbin, (device-cuda)
18: offload, "host-cuda (powerpc64le-unknown-linux-gnu)" {2}, "device-cuda (nvptx64-nvidia-cuda)" {17}, ir
19: backend, {18}, assembler
20: assembler, {19}, object
21: input, "cuda", object
22: input, "cudart", object
23: linker, {20, 21, 22}, image
```
The changes in this patch pass the existent regression tests (keeps the existent functionality) and resulting binaries execute correctly in a Power8+K40 machine.
Reviewers: echristo, hfinkel, jlebar, ABataev, tra
Subscribers: guansong, andreybokhanko, tcramer, mkuron, cfe-commits, arpith-jacob, carlo.bertolli, caomhin
Differential Revision: https://reviews.llvm.org/D18171
llvm-svn: 275645
2016-07-16 07:13:27 +08:00
|
|
|
if (isa<driver::OffloadAction>(A)) {
|
|
|
|
OffloadCompilation = true;
|
2015-07-14 07:27:56 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Jobs.size() == 0 || !isa<driver::Command>(*Jobs.begin()) ||
|
[CUDA][OpenMP] Create generic offload action
Summary:
This patch replaces the CUDA specific action by a generic offload action. The offload action may have multiple dependences classier in “host” and “device”. The way this generic offloading action is used is very similar to what is done today by the CUDA implementation: it is used to set a specific toolchain and architecture to its dependences during the generation of jobs.
This patch also proposes propagating the offloading information through the action graph so that that information can be easily retrieved at any time during the generation of commands. This allows e.g. the "clang tool” to evaluate whether CUDA should be supported for the device or host and ptas to easily retrieve the target architecture.
This is an example of how the action graphs would look like (compilation of a single CUDA file with two GPU architectures)
```
0: input, "cudatests.cu", cuda, (host-cuda)
1: preprocessor, {0}, cuda-cpp-output, (host-cuda)
2: compiler, {1}, ir, (host-cuda)
3: input, "cudatests.cu", cuda, (device-cuda, sm_35)
4: preprocessor, {3}, cuda-cpp-output, (device-cuda, sm_35)
5: compiler, {4}, ir, (device-cuda, sm_35)
6: backend, {5}, assembler, (device-cuda, sm_35)
7: assembler, {6}, object, (device-cuda, sm_35)
8: offload, "device-cuda (nvptx64-nvidia-cuda:sm_35)" {7}, object
9: offload, "device-cuda (nvptx64-nvidia-cuda:sm_35)" {6}, assembler
10: input, "cudatests.cu", cuda, (device-cuda, sm_37)
11: preprocessor, {10}, cuda-cpp-output, (device-cuda, sm_37)
12: compiler, {11}, ir, (device-cuda, sm_37)
13: backend, {12}, assembler, (device-cuda, sm_37)
14: assembler, {13}, object, (device-cuda, sm_37)
15: offload, "device-cuda (nvptx64-nvidia-cuda:sm_37)" {14}, object
16: offload, "device-cuda (nvptx64-nvidia-cuda:sm_37)" {13}, assembler
17: linker, {8, 9, 15, 16}, cuda-fatbin, (device-cuda)
18: offload, "host-cuda (powerpc64le-unknown-linux-gnu)" {2}, "device-cuda (nvptx64-nvidia-cuda)" {17}, ir
19: backend, {18}, assembler
20: assembler, {19}, object
21: input, "cuda", object
22: input, "cudart", object
23: linker, {20, 21, 22}, image
```
The changes in this patch pass the existent regression tests (keeps the existent functionality) and resulting binaries execute correctly in a Power8+K40 machine.
Reviewers: echristo, hfinkel, jlebar, ABataev, tra
Subscribers: guansong, andreybokhanko, tcramer, mkuron, cfe-commits, arpith-jacob, carlo.bertolli, caomhin
Differential Revision: https://reviews.llvm.org/D18171
llvm-svn: 275645
2016-07-16 07:13:27 +08:00
|
|
|
(Jobs.size() > 1 && !OffloadCompilation)) {
|
2012-02-05 10:13:05 +08:00
|
|
|
SmallString<256> Msg;
|
2011-04-05 07:16:36 +08:00
|
|
|
llvm::raw_svector_ostream OS(Msg);
|
2013-09-13 02:23:34 +08:00
|
|
|
Jobs.Print(OS, "; ", true);
|
2011-04-05 07:16:36 +08:00
|
|
|
Diags->Report(diag::err_fe_expected_compiler_job) << OS.str();
|
2014-05-22 12:46:25 +08:00
|
|
|
return nullptr;
|
2011-04-05 07:16:36 +08:00
|
|
|
}
|
|
|
|
|
2014-10-03 09:04:53 +08:00
|
|
|
const driver::Command &Cmd = cast<driver::Command>(*Jobs.begin());
|
2014-09-05 00:04:28 +08:00
|
|
|
if (StringRef(Cmd.getCreator().getName()) != "clang") {
|
2011-04-05 07:16:36 +08:00
|
|
|
Diags->Report(diag::err_fe_expected_clang_command);
|
2014-05-22 12:46:25 +08:00
|
|
|
return nullptr;
|
2011-04-05 07:16:36 +08:00
|
|
|
}
|
|
|
|
|
2014-09-05 00:04:28 +08:00
|
|
|
const ArgStringList &CCArgs = Cmd.getArguments();
|
2014-03-08 04:03:18 +08:00
|
|
|
std::unique_ptr<CompilerInvocation> CI(new CompilerInvocation());
|
2011-12-23 11:05:38 +08:00
|
|
|
if (!CompilerInvocation::CreateFromArgs(*CI,
|
2011-04-05 07:16:36 +08:00
|
|
|
const_cast<const char **>(CCArgs.data()),
|
|
|
|
const_cast<const char **>(CCArgs.data()) +
|
|
|
|
CCArgs.size(),
|
2011-12-23 11:05:38 +08:00
|
|
|
*Diags))
|
2014-05-22 12:46:25 +08:00
|
|
|
return nullptr;
|
2014-03-08 03:33:25 +08:00
|
|
|
return CI.release();
|
2011-04-05 07:16:36 +08:00
|
|
|
}
|