Turn ArchName/BoundArch in Driver from raw pointer to StringRef (NFC)

llvm-svn: 283605
This commit is contained in:
Mehdi Amini 2016-10-07 21:27:26 +00:00
parent 8f04805c9f
commit c50b1a263b
10 changed files with 39 additions and 41 deletions

View File

@ -190,12 +190,12 @@ class BindArchAction : public Action {
virtual void anchor();
/// The architecture to bind, or 0 if the default architecture
/// should be bound.
const char *ArchName;
StringRef ArchName;
public:
BindArchAction(Action *Input, const char *ArchName);
BindArchAction(Action *Input, StringRef ArchName);
const char *getArchName() const { return ArchName; }
StringRef getArchName() const { return ArchName; }
static bool classof(const Action *A) {
return A->getKind() == BindArchClass;

View File

@ -69,8 +69,9 @@ class Compilation {
/// Cache of translated arguments for a particular tool chain and bound
/// architecture.
llvm::DenseMap<std::pair<const ToolChain *, const char *>,
llvm::opt::DerivedArgList *> TCArgs;
llvm::DenseMap<std::pair<const ToolChain *, StringRef>,
llvm::opt::DerivedArgList *>
TCArgs;
/// Temporary files which should be removed on exit.
llvm::opt::ArgStringList TempFiles;
@ -184,7 +185,7 @@ public:
///
/// \param BoundArch - The bound architecture name, or 0.
const llvm::opt::DerivedArgList &getArgsForToolChain(const ToolChain *TC,
const char *BoundArch);
StringRef BoundArch);
/// addTempFile - Add a file to remove on exit, and returns its
/// argument.

View File

@ -397,7 +397,7 @@ public:
/// jobs for a given (Action, ToolChain, BoundArch) tuple once.
InputInfo
BuildJobsForAction(Compilation &C, const Action *A, const ToolChain *TC,
const char *BoundArch, bool AtTopLevel, bool MultipleArchs,
StringRef BoundArch, bool AtTopLevel, bool MultipleArchs,
const char *LinkingOutput,
std::map<std::pair<const Action *, std::string>, InputInfo>
&CachedResults,
@ -419,7 +419,7 @@ public:
/// \param MultipleArchs - Whether multiple -arch options were supplied.
/// \param NormalizedTriple - The normalized triple of the relevant target.
const char *GetNamedOutputPath(Compilation &C, const JobAction &JA,
const char *BaseInput, const char *BoundArch,
const char *BaseInput, StringRef BoundArch,
bool AtTopLevel, bool MultipleArchs,
StringRef NormalizedTriple) const;
@ -468,9 +468,8 @@ private:
/// jobs specifically for the given action, but will use the cache when
/// building jobs for the Action's inputs.
InputInfo BuildJobsForActionNoCache(
Compilation &C, const Action *A, const ToolChain *TC,
const char *BoundArch, bool AtTopLevel, bool MultipleArchs,
const char *LinkingOutput,
Compilation &C, const Action *A, const ToolChain *TC, StringRef BoundArch,
bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput,
std::map<std::pair<const Action *, std::string>, InputInfo>
&CachedResults,
bool BuildForOffloadDevice) const;

View File

@ -195,7 +195,7 @@ public:
/// \param BoundArch - The bound architecture name, or 0.
virtual llvm::opt::DerivedArgList *
TranslateArgs(const llvm::opt::DerivedArgList &Args,
const char *BoundArch) const {
StringRef BoundArch) const {
return nullptr;
}

View File

@ -125,7 +125,7 @@ InputAction::InputAction(const Arg &_Input, types::ID _Type)
void BindArchAction::anchor() {}
BindArchAction::BindArchAction(Action *Input, const char *_ArchName)
BindArchAction::BindArchAction(Action *Input, StringRef _ArchName)
: Action(BindArchClass, Input), ArchName(_ArchName) {}
void OffloadAction::anchor() {}

View File

@ -37,11 +37,9 @@ Compilation::~Compilation() {
delete Args;
// Free any derived arg lists.
for (llvm::DenseMap<std::pair<const ToolChain*, const char*>,
DerivedArgList*>::iterator it = TCArgs.begin(),
ie = TCArgs.end(); it != ie; ++it)
if (it->second != TranslatedArgs)
delete it->second;
for (auto Arg : TCArgs)
if (Arg.second != TranslatedArgs)
delete Arg.second;
// Free redirections of stdout/stderr.
if (Redirects) {
@ -53,7 +51,7 @@ Compilation::~Compilation() {
}
const DerivedArgList &Compilation::getArgsForToolChain(const ToolChain *TC,
const char *BoundArch) {
StringRef BoundArch) {
if (!TC)
TC = &DefaultToolChain;

View File

@ -2307,7 +2307,7 @@ void Driver::BuildJobs(Compilation &C) const {
}
BuildJobsForAction(C, A, &C.getDefaultToolChain(),
/*BoundArch*/ nullptr,
/*BoundArch*/ StringRef(),
/*AtTopLevel*/ true,
/*MultipleArchs*/ ArchNames.size() > 1,
/*LinkingOutput*/ LinkingOutput, CachedResults,
@ -2499,7 +2499,7 @@ static const Tool *selectToolForJob(Compilation &C, bool SaveTemps,
}
InputInfo Driver::BuildJobsForAction(
Compilation &C, const Action *A, const ToolChain *TC, const char *BoundArch,
Compilation &C, const Action *A, const ToolChain *TC, StringRef BoundArch,
bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput,
std::map<std::pair<const Action *, std::string>, InputInfo> &CachedResults,
bool BuildForOffloadDevice) const {
@ -2507,7 +2507,7 @@ InputInfo Driver::BuildJobsForAction(
// for example, armv7 and armv7s both map to the same triple -- so we need
// both in our map.
std::string TriplePlusArch = TC->getTriple().normalize();
if (BoundArch) {
if (!BoundArch.empty()) {
TriplePlusArch += "-";
TriplePlusArch += BoundArch;
}
@ -2524,7 +2524,7 @@ InputInfo Driver::BuildJobsForAction(
}
InputInfo Driver::BuildJobsForActionNoCache(
Compilation &C, const Action *A, const ToolChain *TC, const char *BoundArch,
Compilation &C, const Action *A, const ToolChain *TC, StringRef BoundArch,
bool AtTopLevel, bool MultipleArchs, const char *LinkingOutput,
std::map<std::pair<const Action *, std::string>, InputInfo> &CachedResults,
bool BuildForOffloadDevice) const {
@ -2601,9 +2601,9 @@ InputInfo Driver::BuildJobsForActionNoCache(
if (const BindArchAction *BAA = dyn_cast<BindArchAction>(A)) {
const ToolChain *TC;
const char *ArchName = BAA->getArchName();
StringRef ArchName = BAA->getArchName();
if (ArchName)
if (!ArchName.empty())
TC = &getToolChain(C.getArgs(),
computeTargetTriple(*this, DefaultTargetTriple,
C.getArgs(), ArchName));
@ -2745,7 +2745,7 @@ static const char *MakeCLOutputFilename(const ArgList &Args, StringRef ArgValue,
const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
const char *BaseInput,
const char *BoundArch, bool AtTopLevel,
StringRef BoundArch, bool AtTopLevel,
bool MultipleArchs,
StringRef NormalizedTriple) const {
llvm::PrettyStackTraceString CrashInfo("Computing output path");
@ -2831,7 +2831,7 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
// clang-cl uses BaseName for the executable name.
NamedOutput =
MakeCLOutputFilename(C.getArgs(), "", BaseName, types::TY_Image);
} else if (MultipleArchs && BoundArch) {
} else if (MultipleArchs && !BoundArch.empty()) {
SmallString<128> Output(getDefaultImageName());
Output += JA.getOffloadingFileNamePrefix(NormalizedTriple);
Output += "-";
@ -2851,7 +2851,7 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
End = BaseName.rfind('.');
SmallString<128> Suffixed(BaseName.substr(0, End));
Suffixed += JA.getOffloadingFileNamePrefix(NormalizedTriple);
if (MultipleArchs && BoundArch) {
if (MultipleArchs && !BoundArch.empty()) {
Suffixed += "-";
Suffixed.append(BoundArch);
}

View File

@ -811,7 +811,7 @@ static void TranslateDArg(Arg *A, llvm::opt::DerivedArgList &DAL,
llvm::opt::DerivedArgList *
MSVCToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
const char *BoundArch) const {
StringRef BoundArch) const {
DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
const OptTable &Opts = getDriver().getOpts();

View File

@ -801,7 +801,7 @@ void DarwinClang::AddCCKextLibArgs(const ArgList &Args,
}
DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args,
const char *BoundArch) const {
StringRef BoundArch) const {
DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
const OptTable &Opts = getDriver().getOpts();
@ -819,7 +819,7 @@ DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args,
llvm::Triple::ArchType XarchArch =
tools::darwin::getArchTypeForMachOArchName(A->getValue(0));
if (!(XarchArch == getArch() ||
(BoundArch &&
(!BoundArch.empty() &&
XarchArch ==
tools::darwin::getArchTypeForMachOArchName(BoundArch))))
continue;
@ -935,7 +935,7 @@ DerivedArgList *MachO::TranslateArgs(const DerivedArgList &Args,
// Add the arch options based on the particular spelling of -arch, to match
// how the driver driver works.
if (BoundArch) {
if (!BoundArch.empty()) {
StringRef Name = BoundArch;
const Option MCpu = Opts.getOption(options::OPT_mcpu_EQ);
const Option MArch = Opts.getOption(options::OPT_march_EQ);
@ -1031,13 +1031,13 @@ void MachO::AddLinkRuntimeLibArgs(const ArgList &Args,
}
DerivedArgList *Darwin::TranslateArgs(const DerivedArgList &Args,
const char *BoundArch) const {
StringRef BoundArch) const {
// First get the generic Apple args, before moving onto Darwin-specific ones.
DerivedArgList *DAL = MachO::TranslateArgs(Args, BoundArch);
const OptTable &Opts = getDriver().getOpts();
// If no architecture is bound, none of the translations here are relevant.
if (!BoundArch)
if (BoundArch.empty())
return DAL;
// Add an explicit version min argument for the deployment target. We do this
@ -4948,14 +4948,14 @@ void CudaToolChain::AddCudaIncludeArgs(const ArgList &DriverArgs,
llvm::opt::DerivedArgList *
CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
const char *BoundArch) const {
StringRef BoundArch) const {
DerivedArgList *DAL = new DerivedArgList(Args.getBaseArgs());
const OptTable &Opts = getDriver().getOpts();
for (Arg *A : Args) {
if (A->getOption().matches(options::OPT_Xarch__)) {
// Skip this argument unless the architecture matches BoundArch
if (!BoundArch || A->getValue(0) != StringRef(BoundArch))
if (BoundArch.empty() || A->getValue(0) != BoundArch)
continue;
unsigned Index = Args.getBaseArgs().MakeIndex(A->getValue(1));
@ -4986,7 +4986,7 @@ CudaToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
DAL->append(A);
}
if (BoundArch) {
if (!BoundArch.empty()) {
DAL->eraseArg(options::OPT_march_EQ);
DAL->AddJoinedArg(nullptr, Opts.getOption(options::OPT_march_EQ), BoundArch);
}

View File

@ -318,7 +318,7 @@ public:
llvm::opt::DerivedArgList *
TranslateArgs(const llvm::opt::DerivedArgList &Args,
const char *BoundArch) const override;
StringRef BoundArch) const override;
bool IsBlocksDefault() const override {
// Always allow blocks on Apple; users interested in versioning are
@ -523,7 +523,7 @@ public:
llvm::opt::DerivedArgList *
TranslateArgs(const llvm::opt::DerivedArgList &Args,
const char *BoundArch) const override;
StringRef BoundArch) const override;
CXXStdlibType GetDefaultCXXStdlibType() const override;
ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const override;
@ -856,7 +856,7 @@ public:
llvm::opt::DerivedArgList *
TranslateArgs(const llvm::opt::DerivedArgList &Args,
const char *BoundArch) const override;
StringRef BoundArch) const override;
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const override;
@ -1062,7 +1062,7 @@ public:
llvm::opt::DerivedArgList *
TranslateArgs(const llvm::opt::DerivedArgList &Args,
const char *BoundArch) const override;
StringRef BoundArch) const override;
bool IsIntegratedAssemblerDefault() const override;
bool IsUnwindTablesDefault() const override;