2011-01-01 01:31:54 +08:00
|
|
|
//===--- Action.cpp - Abstract compilation steps --------------------------===//
|
2009-03-13 02:40:18 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Driver/Action.h"
|
2016-01-13 06:23:04 +08:00
|
|
|
#include "llvm/ADT/StringSwitch.h"
|
2011-09-23 13:57:42 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2016-01-12 07:27:13 +08:00
|
|
|
#include "llvm/Support/Regex.h"
|
2009-03-13 02:40:18 +08:00
|
|
|
#include <cassert>
|
|
|
|
using namespace clang::driver;
|
2013-06-15 01:17:23 +08:00
|
|
|
using namespace llvm::opt;
|
2009-03-13 02:40:18 +08:00
|
|
|
|
2016-01-12 07:07:27 +08:00
|
|
|
Action::~Action() {}
|
2009-03-13 20:17:08 +08:00
|
|
|
|
|
|
|
const char *Action::getClassName(ActionClass AC) {
|
|
|
|
switch (AC) {
|
|
|
|
case InputClass: return "input";
|
|
|
|
case BindArchClass: return "bind-arch";
|
2015-07-14 07:27:56 +08:00
|
|
|
case CudaDeviceClass: return "cuda-device";
|
|
|
|
case CudaHostClass: return "cuda-host";
|
2009-03-14 01:52:07 +08:00
|
|
|
case PreprocessJobClass: return "preprocessor";
|
|
|
|
case PrecompileJobClass: return "precompiler";
|
|
|
|
case AnalyzeJobClass: return "analyzer";
|
2012-03-07 04:06:33 +08:00
|
|
|
case MigrateJobClass: return "migrator";
|
2009-03-14 01:52:07 +08:00
|
|
|
case CompileJobClass: return "compiler";
|
Reapply "Change -save-temps to emit unoptimized bitcode files."
This reapplies r224503 along with a fix for compiling Fortran by having the
clang driver invoke gcc (see r224546, where it was reverted). I have added
a testcase for that as well.
Original commit message:
It is often convenient to use -save-temps to collect the intermediate
results of a compilation, e.g., when triaging a bug report. Besides the
temporary files for preprocessed source and assembly code, this adds the
unoptimized bitcode files as well.
This adds a new BackendJobAction, which is mostly mechanical, to run after
the CompileJobAction. When not using -save-temps, the BackendJobAction is
combined into one job with the CompileJobAction, similar to the way the
integrated assembler is handled. I've implemented this entirely as a
driver change, so under the hood, it is just using -disable-llvm-optzns
to get the unoptimized bitcode.
Based in part on a patch by Steven Wu.
rdar://problem/18909437
llvm-svn: 224688
2014-12-21 15:00:00 +08:00
|
|
|
case BackendJobClass: return "backend";
|
2009-03-14 01:52:07 +08:00
|
|
|
case AssembleJobClass: return "assembler";
|
|
|
|
case LinkJobClass: return "linker";
|
2009-03-13 20:17:08 +08:00
|
|
|
case LipoJobClass: return "lipo";
|
2010-06-05 02:28:36 +08:00
|
|
|
case DsymutilJobClass: return "dsymutil";
|
2014-02-07 02:53:25 +08:00
|
|
|
case VerifyDebugInfoJobClass: return "verify-debug-info";
|
|
|
|
case VerifyPCHJobClass: return "verify-pch";
|
2009-03-13 20:17:08 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2011-09-23 13:06:16 +08:00
|
|
|
llvm_unreachable("invalid class");
|
2009-03-13 20:17:08 +08:00
|
|
|
}
|
2009-03-14 07:08:03 +08:00
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void InputAction::anchor() {}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
InputAction::InputAction(const Arg &_Input, types::ID _Type)
|
2009-03-14 07:08:03 +08:00
|
|
|
: Action(InputClass, _Type), Input(_Input) {
|
|
|
|
}
|
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void BindArchAction::anchor() {}
|
|
|
|
|
2016-01-12 07:07:27 +08:00
|
|
|
BindArchAction::BindArchAction(Action *Input, const char *_ArchName)
|
|
|
|
: Action(BindArchClass, Input), ArchName(_ArchName) {}
|
2009-03-14 07:08:03 +08:00
|
|
|
|
2016-01-13 06:23:04 +08:00
|
|
|
// Converts CUDA GPU architecture, e.g. "sm_21", to its corresponding virtual
|
|
|
|
// compute arch, e.g. "compute_20". Returns null if the input arch is null or
|
|
|
|
// doesn't match an existing arch.
|
|
|
|
static const char* GpuArchToComputeName(const char *ArchName) {
|
|
|
|
if (!ArchName)
|
|
|
|
return nullptr;
|
|
|
|
return llvm::StringSwitch<const char *>(ArchName)
|
|
|
|
.Cases("sm_20", "sm_21", "compute_20")
|
|
|
|
.Case("sm_30", "compute_30")
|
|
|
|
.Case("sm_32", "compute_32")
|
|
|
|
.Case("sm_35", "compute_35")
|
|
|
|
.Case("sm_37", "compute_37")
|
|
|
|
.Case("sm_50", "compute_50")
|
|
|
|
.Case("sm_52", "compute_52")
|
|
|
|
.Case("sm_53", "compute_53")
|
|
|
|
.Default(nullptr);
|
|
|
|
}
|
|
|
|
|
2015-07-14 07:27:56 +08:00
|
|
|
void CudaDeviceAction::anchor() {}
|
|
|
|
|
2016-01-12 07:07:27 +08:00
|
|
|
CudaDeviceAction::CudaDeviceAction(Action *Input, const char *ArchName,
|
|
|
|
bool AtTopLevel)
|
|
|
|
: Action(CudaDeviceClass, Input), GpuArchName(ArchName),
|
2016-01-12 07:27:13 +08:00
|
|
|
AtTopLevel(AtTopLevel) {
|
2016-01-15 05:41:27 +08:00
|
|
|
assert(!GpuArchName || IsValidGpuArchName(GpuArchName));
|
2016-01-12 07:27:13 +08:00
|
|
|
}
|
|
|
|
|
2016-01-13 06:23:04 +08:00
|
|
|
const char *CudaDeviceAction::getComputeArchName() const {
|
|
|
|
return GpuArchToComputeName(GpuArchName);
|
|
|
|
}
|
|
|
|
|
2016-01-12 07:27:13 +08:00
|
|
|
bool CudaDeviceAction::IsValidGpuArchName(llvm::StringRef ArchName) {
|
2016-01-13 06:23:04 +08:00
|
|
|
return GpuArchToComputeName(ArchName.data()) != nullptr;
|
2016-01-12 07:27:13 +08:00
|
|
|
}
|
2015-07-14 07:27:56 +08:00
|
|
|
|
|
|
|
void CudaHostAction::anchor() {}
|
|
|
|
|
2016-01-12 07:07:27 +08:00
|
|
|
CudaHostAction::CudaHostAction(Action *Input, const ActionList &DeviceActions)
|
|
|
|
: Action(CudaHostClass, Input), DeviceActions(DeviceActions) {}
|
2015-07-14 07:27:56 +08:00
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void JobAction::anchor() {}
|
|
|
|
|
2016-01-12 07:07:27 +08:00
|
|
|
JobAction::JobAction(ActionClass Kind, Action *Input, types::ID Type)
|
|
|
|
: Action(Kind, Input, Type) {}
|
2009-03-14 07:08:03 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
JobAction::JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type)
|
2009-03-14 07:08:03 +08:00
|
|
|
: Action(Kind, Inputs, Type) {
|
|
|
|
}
|
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void PreprocessJobAction::anchor() {}
|
|
|
|
|
2016-01-12 07:07:27 +08:00
|
|
|
PreprocessJobAction::PreprocessJobAction(Action *Input, types::ID OutputType)
|
|
|
|
: JobAction(PreprocessJobClass, Input, OutputType) {}
|
2009-03-14 07:08:03 +08:00
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void PrecompileJobAction::anchor() {}
|
|
|
|
|
2016-01-12 07:07:27 +08:00
|
|
|
PrecompileJobAction::PrecompileJobAction(Action *Input, types::ID OutputType)
|
|
|
|
: JobAction(PrecompileJobClass, Input, OutputType) {}
|
2009-03-14 07:08:03 +08:00
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void AnalyzeJobAction::anchor() {}
|
|
|
|
|
2016-01-12 07:07:27 +08:00
|
|
|
AnalyzeJobAction::AnalyzeJobAction(Action *Input, types::ID OutputType)
|
|
|
|
: JobAction(AnalyzeJobClass, Input, OutputType) {}
|
2009-03-14 07:08:03 +08:00
|
|
|
|
2012-03-07 04:06:33 +08:00
|
|
|
void MigrateJobAction::anchor() {}
|
|
|
|
|
2016-01-12 07:07:27 +08:00
|
|
|
MigrateJobAction::MigrateJobAction(Action *Input, types::ID OutputType)
|
|
|
|
: JobAction(MigrateJobClass, Input, OutputType) {}
|
2012-03-07 04:06:33 +08:00
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void CompileJobAction::anchor() {}
|
|
|
|
|
2016-01-12 07:07:27 +08:00
|
|
|
CompileJobAction::CompileJobAction(Action *Input, types::ID OutputType)
|
|
|
|
: JobAction(CompileJobClass, Input, OutputType) {}
|
2009-03-14 07:08:03 +08:00
|
|
|
|
Reapply "Change -save-temps to emit unoptimized bitcode files."
This reapplies r224503 along with a fix for compiling Fortran by having the
clang driver invoke gcc (see r224546, where it was reverted). I have added
a testcase for that as well.
Original commit message:
It is often convenient to use -save-temps to collect the intermediate
results of a compilation, e.g., when triaging a bug report. Besides the
temporary files for preprocessed source and assembly code, this adds the
unoptimized bitcode files as well.
This adds a new BackendJobAction, which is mostly mechanical, to run after
the CompileJobAction. When not using -save-temps, the BackendJobAction is
combined into one job with the CompileJobAction, similar to the way the
integrated assembler is handled. I've implemented this entirely as a
driver change, so under the hood, it is just using -disable-llvm-optzns
to get the unoptimized bitcode.
Based in part on a patch by Steven Wu.
rdar://problem/18909437
llvm-svn: 224688
2014-12-21 15:00:00 +08:00
|
|
|
void BackendJobAction::anchor() {}
|
|
|
|
|
2016-01-12 07:07:27 +08:00
|
|
|
BackendJobAction::BackendJobAction(Action *Input, types::ID OutputType)
|
|
|
|
: JobAction(BackendJobClass, Input, OutputType) {}
|
Reapply "Change -save-temps to emit unoptimized bitcode files."
This reapplies r224503 along with a fix for compiling Fortran by having the
clang driver invoke gcc (see r224546, where it was reverted). I have added
a testcase for that as well.
Original commit message:
It is often convenient to use -save-temps to collect the intermediate
results of a compilation, e.g., when triaging a bug report. Besides the
temporary files for preprocessed source and assembly code, this adds the
unoptimized bitcode files as well.
This adds a new BackendJobAction, which is mostly mechanical, to run after
the CompileJobAction. When not using -save-temps, the BackendJobAction is
combined into one job with the CompileJobAction, similar to the way the
integrated assembler is handled. I've implemented this entirely as a
driver change, so under the hood, it is just using -disable-llvm-optzns
to get the unoptimized bitcode.
Based in part on a patch by Steven Wu.
rdar://problem/18909437
llvm-svn: 224688
2014-12-21 15:00:00 +08:00
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void AssembleJobAction::anchor() {}
|
|
|
|
|
2016-01-12 07:07:27 +08:00
|
|
|
AssembleJobAction::AssembleJobAction(Action *Input, types::ID OutputType)
|
|
|
|
: JobAction(AssembleJobClass, Input, OutputType) {}
|
2009-03-14 07:08:03 +08:00
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void LinkJobAction::anchor() {}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
LinkJobAction::LinkJobAction(ActionList &Inputs, types::ID Type)
|
2009-03-14 07:08:03 +08:00
|
|
|
: JobAction(LinkJobClass, Inputs, Type) {
|
|
|
|
}
|
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void LipoJobAction::anchor() {}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
LipoJobAction::LipoJobAction(ActionList &Inputs, types::ID Type)
|
2009-03-14 07:08:03 +08:00
|
|
|
: JobAction(LipoJobClass, Inputs, Type) {
|
|
|
|
}
|
2010-06-05 02:28:36 +08:00
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void DsymutilJobAction::anchor() {}
|
|
|
|
|
2010-06-05 02:28:36 +08:00
|
|
|
DsymutilJobAction::DsymutilJobAction(ActionList &Inputs, types::ID Type)
|
|
|
|
: JobAction(DsymutilJobClass, Inputs, Type) {
|
|
|
|
}
|
2011-08-24 01:56:55 +08:00
|
|
|
|
2011-12-20 10:48:34 +08:00
|
|
|
void VerifyJobAction::anchor() {}
|
|
|
|
|
2016-01-12 07:07:27 +08:00
|
|
|
VerifyJobAction::VerifyJobAction(ActionClass Kind, Action *Input,
|
|
|
|
types::ID Type)
|
|
|
|
: JobAction(Kind, Input, Type) {
|
2014-02-07 02:53:25 +08:00
|
|
|
assert((Kind == VerifyDebugInfoJobClass || Kind == VerifyPCHJobClass) &&
|
|
|
|
"ActionClass is not a valid VerifyJobAction");
|
|
|
|
}
|
|
|
|
|
|
|
|
void VerifyDebugInfoJobAction::anchor() {}
|
|
|
|
|
2016-01-12 07:07:27 +08:00
|
|
|
VerifyDebugInfoJobAction::VerifyDebugInfoJobAction(Action *Input,
|
|
|
|
types::ID Type)
|
|
|
|
: VerifyJobAction(VerifyDebugInfoJobClass, Input, Type) {}
|
2014-02-07 02:53:25 +08:00
|
|
|
|
|
|
|
void VerifyPCHJobAction::anchor() {}
|
|
|
|
|
2016-01-12 07:07:27 +08:00
|
|
|
VerifyPCHJobAction::VerifyPCHJobAction(Action *Input, types::ID Type)
|
|
|
|
: VerifyJobAction(VerifyPCHJobClass, Input, Type) {}
|