From d168c091f7d1b9759de38a3950204bc833799ea2 Mon Sep 17 00:00:00 2001 From: Justin Lebar Date: Mon, 11 Jan 2016 23:15:21 +0000 Subject: [PATCH] Add an Action* member to InputInfo. Summary: The CUDA toolchain needs to know which Actions created which InputInfos, because it needs to attach GPU archs to the various InputInfos. Reviewers: echristo Subscribers: jfb, dschuff, jhen, tra, cfe-commits Differential Revision: http://reviews.llvm.org/D16078 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257411 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Driver.cpp | 12 ++++++------ lib/Driver/InputInfo.h | 33 ++++++++++++++++++++++++++------- lib/Driver/Tools.cpp | 4 ++-- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 254348c9af..8248a165c8 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -1801,9 +1801,9 @@ InputInfo Driver::BuildJobsForAction(Compilation &C, const Action *A, Input.claim(); if (Input.getOption().matches(options::OPT_INPUT)) { const char *Name = Input.getValue(); - return InputInfo(Name, A->getType(), Name); + return InputInfo(A, Name, /* BaseInput = */ Name); } - return InputInfo(&Input, A->getType(), ""); + return InputInfo(A, &Input, /* BaseInput = */ ""); } if (const BindArchAction *BAA = dyn_cast(A)) { @@ -1877,11 +1877,11 @@ InputInfo Driver::BuildJobsForAction(Compilation &C, const Action *A, // Determine the place to write output to, if any. InputInfo Result; if (JA->getType() == types::TY_Nothing) - Result = InputInfo(A->getType(), BaseInput); + Result = InputInfo(A, BaseInput); else - Result = InputInfo(GetNamedOutputPath(C, *JA, BaseInput, BoundArch, - AtTopLevel, MultipleArchs), - A->getType(), BaseInput); + Result = InputInfo(A, GetNamedOutputPath(C, *JA, BaseInput, BoundArch, + AtTopLevel, MultipleArchs), + BaseInput); if (CCCPrintBindings && !CCGenDiagnostics) { llvm::errs() << "# \"" << T->getToolChain().getTripleString() << '"' diff --git a/lib/Driver/InputInfo.h b/lib/Driver/InputInfo.h index b23ba575b6..0c36e817c1 100644 --- a/lib/Driver/InputInfo.h +++ b/lib/Driver/InputInfo.h @@ -10,6 +10,7 @@ #ifndef LLVM_CLANG_LIB_DRIVER_INPUTINFO_H #define LLVM_CLANG_LIB_DRIVER_INPUTINFO_H +#include "clang/Driver/Action.h" #include "clang/Driver/Types.h" #include "llvm/Option/Arg.h" #include @@ -38,21 +39,36 @@ class InputInfo { const llvm::opt::Arg *InputArg; } Data; Class Kind; + const Action* Act; types::ID Type; const char *BaseInput; + static types::ID GetActionType(const Action *A) { + return A != nullptr ? A->getType() : types::TY_Nothing; + } + public: - InputInfo() {} - InputInfo(types::ID _Type, const char *_BaseInput) - : Kind(Nothing), Type(_Type), BaseInput(_BaseInput) { + InputInfo() : InputInfo(nullptr, nullptr) {} + InputInfo(const Action *A, const char *_BaseInput) + : Kind(Nothing), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) {} + + InputInfo(types::ID _Type, const char *_Filename, const char *_BaseInput) + : Kind(Filename), Act(nullptr), Type(_Type), BaseInput(_BaseInput) { + Data.Filename = _Filename; } - InputInfo(const char *_Filename, types::ID _Type, const char *_BaseInput) - : Kind(Filename), Type(_Type), BaseInput(_BaseInput) { + InputInfo(const Action *A, const char *_Filename, const char *_BaseInput) + : Kind(Filename), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) { Data.Filename = _Filename; } - InputInfo(const llvm::opt::Arg *_InputArg, types::ID _Type, + + InputInfo(types::ID _Type, const llvm::opt::Arg *_InputArg, + const char *_BaseInput) + : Kind(InputArg), Act(nullptr), Type(_Type), BaseInput(_BaseInput) { + Data.InputArg = _InputArg; + } + InputInfo(const Action *A, const llvm::opt::Arg *_InputArg, const char *_BaseInput) - : Kind(InputArg), Type(_Type), BaseInput(_BaseInput) { + : Kind(InputArg), Act(A), Type(GetActionType(A)), BaseInput(_BaseInput) { Data.InputArg = _InputArg; } @@ -61,6 +77,9 @@ public: bool isInputArg() const { return Kind == InputArg; } types::ID getType() const { return Type; } const char *getBaseInput() const { return BaseInput; } + /// The action for which this InputInfo was created. May be null. + const Action *getAction() const { return Act; } + void setAction(const Action *A) { Act = A; } const char *getFilename() const { assert(isFilename() && "Invalid accessor."); diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 2ed847abce..9a1a9498a9 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -2980,7 +2980,7 @@ static void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T, ExtractArgs.push_back(OutFile); const char *Exec = Args.MakeArgString(TC.GetProgramPath("objcopy")); - InputInfo II(Output.getFilename(), types::TY_Object, Output.getFilename()); + InputInfo II(types::TY_Object, Output.getFilename(), Output.getFilename()); // First extract the dwo sections. C.addCommand(llvm::make_unique(JA, T, Exec, ExtractArgs, II)); @@ -8987,7 +8987,7 @@ void nacltools::AssemblerARM::ConstructJob(Compilation &C, const JobAction &JA, const char *LinkingOutput) const { const toolchains::NaClToolChain &ToolChain = static_cast(getToolChain()); - InputInfo NaClMacros(ToolChain.GetNaClArmMacrosPath(), types::TY_PP_Asm, + InputInfo NaClMacros(types::TY_PP_Asm, ToolChain.GetNaClArmMacrosPath(), "nacl-arm-macros.s"); InputInfoList NewInputs; NewInputs.push_back(NaClMacros); -- 2.40.0