Skip to content

Commit

Permalink
[Driver][NFC] Update equals usage in driver sources (#14090)
Browse files Browse the repository at this point in the history
Move away from using .equals to '==' for string comparisons. This puts
us in line with community.
  • Loading branch information
mdtoguchi authored Jun 10, 2024
1 parent 3aee3db commit 7eee535
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion clang/lib/Driver/Compilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ bool Compilation::CleanupFile(const char *File, bool IssueErrors) const {
// when the nvptx*-nvidia-cuda is passed to -fsycl-targets.
if (DefaultToolChain.getTriple().isNVPTX())
return false;
if (llvm::sys::path::extension(ActualFile).equals(".spv"))
if (llvm::sys::path::extension(ActualFile) == ".spv")
return false;
}
}
Expand Down
18 changes: 9 additions & 9 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,8 @@ static bool isValidSYCLTriple(llvm::Triple T) {
// SPIR/SPIRV arch, but has invalid SubArch for AOT.
StringRef A(T.getArchName());
if (T.getSubArch() == llvm::Triple::NoSubArch &&
((T.getArch() == llvm::Triple::spir && !A.equals("spir")) ||
(T.getArch() == llvm::Triple::spir64 && !A.equals("spir64"))))
((T.getArch() == llvm::Triple::spir && A != "spir") ||
(T.getArch() == llvm::Triple::spir64 && A != "spir64")))
return false;
return true;
}
Expand Down Expand Up @@ -1149,7 +1149,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
return;
const char *ArgValue = A->getValue();
for (const StringRef AllowedValue : AllowedValues)
if (AllowedValue.equals(ArgValue))
if (AllowedValue == ArgValue)
return;
Diag(clang::diag::err_drv_invalid_argument_to_option)
<< ArgValue << A->getOption().getName();
Expand Down Expand Up @@ -1891,7 +1891,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
// an external option setting is required to target hardware.
setOffloadCompileMode(FPGAEmulationMode);
for (StringRef ArgString : TargetArgs) {
if (ArgString.equals("-hardware") || ArgString.equals("-simulation")) {
if (ArgString == "-hardware" || ArgString == "-simulation") {
setOffloadCompileMode(FPGAHWMode);
break;
}
Expand Down Expand Up @@ -6250,12 +6250,12 @@ class OffloadingActionBuilder final {
using namespace tools::SYCL;
StringRef Device{Value.first};
if (Device.consume_front(gen::AmdGPU))
return TargetArch.equals(Device) && TargetTriple.isAMDGCN();
return TargetArch == Device && TargetTriple.isAMDGCN();
if (Device.consume_front(gen::NvidiaGPU))
return TargetArch.equals(Device) && TargetTriple.isNVPTX();
return TargetArch == Device && TargetTriple.isNVPTX();
if (Device.consume_front(gen::IntelGPU))
return TargetArch.equals(Device) && TargetTriple.isSPIRAOT();
return TargetArch.equals(Device) && isValidSYCLTriple(TargetTriple);
return TargetArch == Device && TargetTriple.isSPIRAOT();
return TargetArch == Device && isValidSYCLTriple(TargetTriple);
});
} else {
TargetIt = TargetTable.find(TargetTriple.str());
Expand Down Expand Up @@ -9710,7 +9710,7 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
const auto &ResultFiles = C.getResultFiles();
const auto CollidingFilenameIt =
llvm::find_if(ResultFiles, [NamedOutput](const auto &It) {
return StringRef(NamedOutput).equals(It.second);
return StringRef(NamedOutput) == It.second;
});
if (CollidingFilenameIt != ResultFiles.end()) {
// Upon any collision, a unique hash will be appended to the filename,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4952,7 +4952,7 @@ void Clang::ConstructHostCompilerJob(Compilation &C, const JobAction &JA,
if (isa<PreprocessJobAction>(JA)) {
if (IsMSVCHostCompiler) {
// Check the output file, if it is 'stdout' we want to use -E.
if (StringRef(Output.getFilename()).equals("-")) {
if (StringRef(Output.getFilename()) == "-") {
HostCompileArgs.push_back("-E");
OutputAdded = true;
} else {
Expand Down
5 changes: 2 additions & 3 deletions clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1568,9 +1568,8 @@ bool tools::isDependentLibAdded(const ArgList &Args, StringRef Lib) {
// Check if given Lib is added via --dependent-lib
SmallString<64> DepLib("--dependent-lib=");
DepLib += Lib;
return llvm::any_of(
Args.getAllArgValues(options::OPT_Xclang),
[&DepLib](StringRef Option) { return Option.equals(DepLib); });
return llvm::any_of(Args.getAllArgValues(options::OPT_Xclang),
[&DepLib](StringRef Option) { return Option == DepLib; });
}

const char *tools::SplitDebugName(const JobAction &JA, const ArgList &Args,
Expand Down
17 changes: 8 additions & 9 deletions clang/lib/Driver/ToolChains/SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void SYCL::constructLLVMForeachCommand(Compilation &C, const JobAction &JA,
// If fsycl-dump-device-code is passed, put the PTX files
// into the path provided in fsycl-dump-device-code.
if (T->getToolChain().getTriple().isNVPTX() &&
C.getDriver().isDumpDeviceCodeEnabled() && Ext.equals("s")) {
C.getDriver().isDumpDeviceCodeEnabled() && Ext == "s") {
SmallString<128> OutputDir;

Arg *DumpDeviceCodeArg =
Expand Down Expand Up @@ -235,12 +235,11 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
for (StringRef Val : A->getValues()) {
if (Val == "all") {
for (const auto &K : DeviceLibLinkInfo.keys())
DeviceLibLinkInfo[K] =
true && (!NoDeviceLibs || K.equals("internal"));
DeviceLibLinkInfo[K] = true && (!NoDeviceLibs || K == "internal");
break;
}
auto LinkInfoIter = DeviceLibLinkInfo.find(Val);
if (LinkInfoIter == DeviceLibLinkInfo.end() || Val.equals("internal")) {
if (LinkInfoIter == DeviceLibLinkInfo.end() || Val == "internal") {
// TODO: Move the diagnostic to the SYCL section of
// Driver::CreateOffloadingDeviceToolChains() to minimize code
// duplication.
Expand Down Expand Up @@ -488,7 +487,7 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
for (const auto &L : SYCLDeviceLibList) {
std::string DeviceLibName(L);
DeviceLibName.append(LibPostfix);
if (StringRef(PureLibName).equals(DeviceLibName) ||
if (StringRef(PureLibName) == DeviceLibName ||
(IsNVPTX && StringRef(PureLibName).starts_with(L)))
return true;
}
Expand Down Expand Up @@ -899,7 +898,7 @@ static bool hasPVCDevice(const ArgStringList &CmdArgs) {
DeviceArg = SplitArg;
break;
}
if (SplitArg.equals("-device"))
if (SplitArg == "-device")
DeviceSeen = true;
}
if (DeviceSeen)
Expand Down Expand Up @@ -1477,8 +1476,8 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
auto ProcessElement = [&](StringRef Ele) {
auto [DeviceName, RegAllocMode] = Ele.split(':');
StringRef BackendOptName = SYCL::gen::getGenGRFFlag(RegAllocMode);
bool IsDefault = RegAllocMode.equals("default");
if (RegAllocMode.empty() || !DeviceName.equals("pvc") ||
bool IsDefault = RegAllocMode == "default";
if (RegAllocMode.empty() || DeviceName != "pvc" ||
(BackendOptName.empty() && !IsDefault)) {
getDriver().Diag(diag::err_drv_unsupported_option_argument)
<< A->getSpelling() << Ele;
Expand Down Expand Up @@ -1526,7 +1525,7 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
if (Args.hasArg(options::OPT_fintelfpga) && getDriver().IsFPGAHWMode() &&
Triple.getSubArch() == llvm::Triple::SPIRSubArch_fpga) {
if (Arg *A = Args.getLastArg(options::OPT_ffp_model_EQ)) {
if (StringRef(A->getValue()).equals("fast"))
if (StringRef(A->getValue()) == "fast")
BeArgs.push_back("-vpfp-relaxed");
}
}
Expand Down

0 comments on commit 7eee535

Please sign in to comment.