blob: b45f290efc1b8e2efea2e4f3ba3e1435bd309ebf [file] [log] [blame]
Nick Lewycky6da90772010-12-31 17:31:54 +00001//===--- Action.cpp - Abstract compilation steps --------------------------===//
Daniel Dunbarf479c122009-03-12 18:40:18 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "clang/Driver/Action.h"
Justin Lebar29bfa892016-01-12 22:23:04 +000011#include "llvm/ADT/StringSwitch.h"
David Blaikie79000202011-09-23 05:57:42 +000012#include "llvm/Support/ErrorHandling.h"
Justin Lebar7bf77982016-01-11 23:27:13 +000013#include "llvm/Support/Regex.h"
Daniel Dunbarf479c122009-03-12 18:40:18 +000014#include <cassert>
15using namespace clang::driver;
Reid Kleckner898229a2013-06-14 17:17:23 +000016using namespace llvm::opt;
Daniel Dunbarf479c122009-03-12 18:40:18 +000017
Justin Lebar41094612016-01-11 23:07:27 +000018Action::~Action() {}
Daniel Dunbar80665fb2009-03-13 12:17:08 +000019
20const char *Action::getClassName(ActionClass AC) {
21 switch (AC) {
22 case InputClass: return "input";
23 case BindArchClass: return "bind-arch";
Artem Belevich0ff05cd2015-07-13 23:27:56 +000024 case CudaDeviceClass: return "cuda-device";
25 case CudaHostClass: return "cuda-host";
Daniel Dunbar7326ad52009-03-13 17:52:07 +000026 case PreprocessJobClass: return "preprocessor";
27 case PrecompileJobClass: return "precompiler";
28 case AnalyzeJobClass: return "analyzer";
Ted Kremenekf7639e12012-03-06 20:06:33 +000029 case MigrateJobClass: return "migrator";
Daniel Dunbar7326ad52009-03-13 17:52:07 +000030 case CompileJobClass: return "compiler";
Bob Wilson23a55f12014-12-21 07:00:00 +000031 case BackendJobClass: return "backend";
Daniel Dunbar7326ad52009-03-13 17:52:07 +000032 case AssembleJobClass: return "assembler";
33 case LinkJobClass: return "linker";
Daniel Dunbar80665fb2009-03-13 12:17:08 +000034 case LipoJobClass: return "lipo";
Daniel Dunbar88299622010-06-04 18:28:36 +000035 case DsymutilJobClass: return "dsymutil";
Ben Langmuir9b9a8d32014-02-06 18:53:25 +000036 case VerifyDebugInfoJobClass: return "verify-debug-info";
37 case VerifyPCHJobClass: return "verify-pch";
Daniel Dunbar80665fb2009-03-13 12:17:08 +000038 }
Mike Stump11289f42009-09-09 15:08:12 +000039
David Blaikie83d382b2011-09-23 05:06:16 +000040 llvm_unreachable("invalid class");
Daniel Dunbar80665fb2009-03-13 12:17:08 +000041}
Daniel Dunbar3f261ff2009-03-13 23:08:03 +000042
David Blaikie68e081d2011-12-20 02:48:34 +000043void InputAction::anchor() {}
44
Mike Stump11289f42009-09-09 15:08:12 +000045InputAction::InputAction(const Arg &_Input, types::ID _Type)
Daniel Dunbar3f261ff2009-03-13 23:08:03 +000046 : Action(InputClass, _Type), Input(_Input) {
47}
48
David Blaikie68e081d2011-12-20 02:48:34 +000049void BindArchAction::anchor() {}
50
Justin Lebar41094612016-01-11 23:07:27 +000051BindArchAction::BindArchAction(Action *Input, const char *_ArchName)
52 : Action(BindArchClass, Input), ArchName(_ArchName) {}
Daniel Dunbar3f261ff2009-03-13 23:08:03 +000053
Justin Lebar29bfa892016-01-12 22:23:04 +000054// Converts CUDA GPU architecture, e.g. "sm_21", to its corresponding virtual
55// compute arch, e.g. "compute_20". Returns null if the input arch is null or
56// doesn't match an existing arch.
57static const char* GpuArchToComputeName(const char *ArchName) {
58 if (!ArchName)
59 return nullptr;
60 return llvm::StringSwitch<const char *>(ArchName)
61 .Cases("sm_20", "sm_21", "compute_20")
62 .Case("sm_30", "compute_30")
63 .Case("sm_32", "compute_32")
64 .Case("sm_35", "compute_35")
65 .Case("sm_37", "compute_37")
66 .Case("sm_50", "compute_50")
67 .Case("sm_52", "compute_52")
68 .Case("sm_53", "compute_53")
69 .Default(nullptr);
70}
71
Artem Belevich0ff05cd2015-07-13 23:27:56 +000072void CudaDeviceAction::anchor() {}
73
Justin Lebar41094612016-01-11 23:07:27 +000074CudaDeviceAction::CudaDeviceAction(Action *Input, const char *ArchName,
75 bool AtTopLevel)
76 : Action(CudaDeviceClass, Input), GpuArchName(ArchName),
Justin Lebar7bf77982016-01-11 23:27:13 +000077 AtTopLevel(AtTopLevel) {
Justin Lebar21e5d4f2016-01-14 21:41:27 +000078 assert(!GpuArchName || IsValidGpuArchName(GpuArchName));
Justin Lebar7bf77982016-01-11 23:27:13 +000079}
80
Justin Lebar29bfa892016-01-12 22:23:04 +000081const char *CudaDeviceAction::getComputeArchName() const {
82 return GpuArchToComputeName(GpuArchName);
83}
84
Justin Lebar7bf77982016-01-11 23:27:13 +000085bool CudaDeviceAction::IsValidGpuArchName(llvm::StringRef ArchName) {
Justin Lebar29bfa892016-01-12 22:23:04 +000086 return GpuArchToComputeName(ArchName.data()) != nullptr;
Justin Lebar7bf77982016-01-11 23:27:13 +000087}
Artem Belevich0ff05cd2015-07-13 23:27:56 +000088
89void CudaHostAction::anchor() {}
90
Justin Lebar41094612016-01-11 23:07:27 +000091CudaHostAction::CudaHostAction(Action *Input, const ActionList &DeviceActions)
92 : Action(CudaHostClass, Input), DeviceActions(DeviceActions) {}
Artem Belevich0ff05cd2015-07-13 23:27:56 +000093
David Blaikie68e081d2011-12-20 02:48:34 +000094void JobAction::anchor() {}
95
Justin Lebar41094612016-01-11 23:07:27 +000096JobAction::JobAction(ActionClass Kind, Action *Input, types::ID Type)
97 : Action(Kind, Input, Type) {}
Daniel Dunbar3f261ff2009-03-13 23:08:03 +000098
Mike Stump11289f42009-09-09 15:08:12 +000099JobAction::JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type)
Daniel Dunbar3f261ff2009-03-13 23:08:03 +0000100 : Action(Kind, Inputs, Type) {
101}
102
David Blaikie68e081d2011-12-20 02:48:34 +0000103void PreprocessJobAction::anchor() {}
104
Justin Lebar41094612016-01-11 23:07:27 +0000105PreprocessJobAction::PreprocessJobAction(Action *Input, types::ID OutputType)
106 : JobAction(PreprocessJobClass, Input, OutputType) {}
Daniel Dunbar3f261ff2009-03-13 23:08:03 +0000107
David Blaikie68e081d2011-12-20 02:48:34 +0000108void PrecompileJobAction::anchor() {}
109
Justin Lebar41094612016-01-11 23:07:27 +0000110PrecompileJobAction::PrecompileJobAction(Action *Input, types::ID OutputType)
111 : JobAction(PrecompileJobClass, Input, OutputType) {}
Daniel Dunbar3f261ff2009-03-13 23:08:03 +0000112
David Blaikie68e081d2011-12-20 02:48:34 +0000113void AnalyzeJobAction::anchor() {}
114
Justin Lebar41094612016-01-11 23:07:27 +0000115AnalyzeJobAction::AnalyzeJobAction(Action *Input, types::ID OutputType)
116 : JobAction(AnalyzeJobClass, Input, OutputType) {}
Daniel Dunbar3f261ff2009-03-13 23:08:03 +0000117
Ted Kremenekf7639e12012-03-06 20:06:33 +0000118void MigrateJobAction::anchor() {}
119
Justin Lebar41094612016-01-11 23:07:27 +0000120MigrateJobAction::MigrateJobAction(Action *Input, types::ID OutputType)
121 : JobAction(MigrateJobClass, Input, OutputType) {}
Ted Kremenekf7639e12012-03-06 20:06:33 +0000122
David Blaikie68e081d2011-12-20 02:48:34 +0000123void CompileJobAction::anchor() {}
124
Justin Lebar41094612016-01-11 23:07:27 +0000125CompileJobAction::CompileJobAction(Action *Input, types::ID OutputType)
126 : JobAction(CompileJobClass, Input, OutputType) {}
Daniel Dunbar3f261ff2009-03-13 23:08:03 +0000127
Bob Wilson23a55f12014-12-21 07:00:00 +0000128void BackendJobAction::anchor() {}
129
Justin Lebar41094612016-01-11 23:07:27 +0000130BackendJobAction::BackendJobAction(Action *Input, types::ID OutputType)
131 : JobAction(BackendJobClass, Input, OutputType) {}
Bob Wilson23a55f12014-12-21 07:00:00 +0000132
David Blaikie68e081d2011-12-20 02:48:34 +0000133void AssembleJobAction::anchor() {}
134
Justin Lebar41094612016-01-11 23:07:27 +0000135AssembleJobAction::AssembleJobAction(Action *Input, types::ID OutputType)
136 : JobAction(AssembleJobClass, Input, OutputType) {}
Daniel Dunbar3f261ff2009-03-13 23:08:03 +0000137
David Blaikie68e081d2011-12-20 02:48:34 +0000138void LinkJobAction::anchor() {}
139
Mike Stump11289f42009-09-09 15:08:12 +0000140LinkJobAction::LinkJobAction(ActionList &Inputs, types::ID Type)
Daniel Dunbar3f261ff2009-03-13 23:08:03 +0000141 : JobAction(LinkJobClass, Inputs, Type) {
142}
143
David Blaikie68e081d2011-12-20 02:48:34 +0000144void LipoJobAction::anchor() {}
145
Mike Stump11289f42009-09-09 15:08:12 +0000146LipoJobAction::LipoJobAction(ActionList &Inputs, types::ID Type)
Daniel Dunbar3f261ff2009-03-13 23:08:03 +0000147 : JobAction(LipoJobClass, Inputs, Type) {
148}
Daniel Dunbar88299622010-06-04 18:28:36 +0000149
David Blaikie68e081d2011-12-20 02:48:34 +0000150void DsymutilJobAction::anchor() {}
151
Daniel Dunbar88299622010-06-04 18:28:36 +0000152DsymutilJobAction::DsymutilJobAction(ActionList &Inputs, types::ID Type)
153 : JobAction(DsymutilJobClass, Inputs, Type) {
154}
Eric Christopher551ef452011-08-23 17:56:55 +0000155
David Blaikie68e081d2011-12-20 02:48:34 +0000156void VerifyJobAction::anchor() {}
157
Justin Lebar41094612016-01-11 23:07:27 +0000158VerifyJobAction::VerifyJobAction(ActionClass Kind, Action *Input,
159 types::ID Type)
160 : JobAction(Kind, Input, Type) {
Ben Langmuir9b9a8d32014-02-06 18:53:25 +0000161 assert((Kind == VerifyDebugInfoJobClass || Kind == VerifyPCHJobClass) &&
162 "ActionClass is not a valid VerifyJobAction");
163}
164
Ben Langmuir9b9a8d32014-02-06 18:53:25 +0000165void VerifyDebugInfoJobAction::anchor() {}
166
Justin Lebar41094612016-01-11 23:07:27 +0000167VerifyDebugInfoJobAction::VerifyDebugInfoJobAction(Action *Input,
168 types::ID Type)
169 : VerifyJobAction(VerifyDebugInfoJobClass, Input, Type) {}
Ben Langmuir9b9a8d32014-02-06 18:53:25 +0000170
171void VerifyPCHJobAction::anchor() {}
172
Justin Lebar41094612016-01-11 23:07:27 +0000173VerifyPCHJobAction::VerifyPCHJobAction(Action *Input, types::ID Type)
174 : VerifyJobAction(VerifyPCHJobClass, Input, Type) {}