Skip to content

Commit 7eee535

Browse files
authored
[Driver][NFC] Update equals usage in driver sources (#14090)
Move away from using .equals to '==' for string comparisons. This puts us in line with community.
1 parent 3aee3db commit 7eee535

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

clang/lib/Driver/Compilation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ bool Compilation::CleanupFile(const char *File, bool IssueErrors) const {
198198
// when the nvptx*-nvidia-cuda is passed to -fsycl-targets.
199199
if (DefaultToolChain.getTriple().isNVPTX())
200200
return false;
201-
if (llvm::sys::path::extension(ActualFile).equals(".spv"))
201+
if (llvm::sys::path::extension(ActualFile) == ".spv")
202202
return false;
203203
}
204204
}

clang/lib/Driver/Driver.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -829,8 +829,8 @@ static bool isValidSYCLTriple(llvm::Triple T) {
829829
// SPIR/SPIRV arch, but has invalid SubArch for AOT.
830830
StringRef A(T.getArchName());
831831
if (T.getSubArch() == llvm::Triple::NoSubArch &&
832-
((T.getArch() == llvm::Triple::spir && !A.equals("spir")) ||
833-
(T.getArch() == llvm::Triple::spir64 && !A.equals("spir64"))))
832+
((T.getArch() == llvm::Triple::spir && A != "spir") ||
833+
(T.getArch() == llvm::Triple::spir64 && A != "spir64")))
834834
return false;
835835
return true;
836836
}
@@ -1149,7 +1149,7 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C,
11491149
return;
11501150
const char *ArgValue = A->getValue();
11511151
for (const StringRef AllowedValue : AllowedValues)
1152-
if (AllowedValue.equals(ArgValue))
1152+
if (AllowedValue == ArgValue)
11531153
return;
11541154
Diag(clang::diag::err_drv_invalid_argument_to_option)
11551155
<< ArgValue << A->getOption().getName();
@@ -1891,7 +1891,7 @@ Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
18911891
// an external option setting is required to target hardware.
18921892
setOffloadCompileMode(FPGAEmulationMode);
18931893
for (StringRef ArgString : TargetArgs) {
1894-
if (ArgString.equals("-hardware") || ArgString.equals("-simulation")) {
1894+
if (ArgString == "-hardware" || ArgString == "-simulation") {
18951895
setOffloadCompileMode(FPGAHWMode);
18961896
break;
18971897
}
@@ -6250,12 +6250,12 @@ class OffloadingActionBuilder final {
62506250
using namespace tools::SYCL;
62516251
StringRef Device{Value.first};
62526252
if (Device.consume_front(gen::AmdGPU))
6253-
return TargetArch.equals(Device) && TargetTriple.isAMDGCN();
6253+
return TargetArch == Device && TargetTriple.isAMDGCN();
62546254
if (Device.consume_front(gen::NvidiaGPU))
6255-
return TargetArch.equals(Device) && TargetTriple.isNVPTX();
6255+
return TargetArch == Device && TargetTriple.isNVPTX();
62566256
if (Device.consume_front(gen::IntelGPU))
6257-
return TargetArch.equals(Device) && TargetTriple.isSPIRAOT();
6258-
return TargetArch.equals(Device) && isValidSYCLTriple(TargetTriple);
6257+
return TargetArch == Device && TargetTriple.isSPIRAOT();
6258+
return TargetArch == Device && isValidSYCLTriple(TargetTriple);
62596259
});
62606260
} else {
62616261
TargetIt = TargetTable.find(TargetTriple.str());
@@ -9710,7 +9710,7 @@ const char *Driver::GetNamedOutputPath(Compilation &C, const JobAction &JA,
97109710
const auto &ResultFiles = C.getResultFiles();
97119711
const auto CollidingFilenameIt =
97129712
llvm::find_if(ResultFiles, [NamedOutput](const auto &It) {
9713-
return StringRef(NamedOutput).equals(It.second);
9713+
return StringRef(NamedOutput) == It.second;
97149714
});
97159715
if (CollidingFilenameIt != ResultFiles.end()) {
97169716
// Upon any collision, a unique hash will be appended to the filename,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4952,7 +4952,7 @@ void Clang::ConstructHostCompilerJob(Compilation &C, const JobAction &JA,
49524952
if (isa<PreprocessJobAction>(JA)) {
49534953
if (IsMSVCHostCompiler) {
49544954
// Check the output file, if it is 'stdout' we want to use -E.
4955-
if (StringRef(Output.getFilename()).equals("-")) {
4955+
if (StringRef(Output.getFilename()) == "-") {
49564956
HostCompileArgs.push_back("-E");
49574957
OutputAdded = true;
49584958
} else {

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,9 +1568,8 @@ bool tools::isDependentLibAdded(const ArgList &Args, StringRef Lib) {
15681568
// Check if given Lib is added via --dependent-lib
15691569
SmallString<64> DepLib("--dependent-lib=");
15701570
DepLib += Lib;
1571-
return llvm::any_of(
1572-
Args.getAllArgValues(options::OPT_Xclang),
1573-
[&DepLib](StringRef Option) { return Option.equals(DepLib); });
1571+
return llvm::any_of(Args.getAllArgValues(options::OPT_Xclang),
1572+
[&DepLib](StringRef Option) { return Option == DepLib; });
15741573
}
15751574

15761575
const char *tools::SplitDebugName(const JobAction &JA, const ArgList &Args,

clang/lib/Driver/ToolChains/SYCL.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void SYCL::constructLLVMForeachCommand(Compilation &C, const JobAction &JA,
114114
// If fsycl-dump-device-code is passed, put the PTX files
115115
// into the path provided in fsycl-dump-device-code.
116116
if (T->getToolChain().getTriple().isNVPTX() &&
117-
C.getDriver().isDumpDeviceCodeEnabled() && Ext.equals("s")) {
117+
C.getDriver().isDumpDeviceCodeEnabled() && Ext == "s") {
118118
SmallString<128> OutputDir;
119119

120120
Arg *DumpDeviceCodeArg =
@@ -235,12 +235,11 @@ SYCL::getDeviceLibraries(const Compilation &C, const llvm::Triple &TargetTriple,
235235
for (StringRef Val : A->getValues()) {
236236
if (Val == "all") {
237237
for (const auto &K : DeviceLibLinkInfo.keys())
238-
DeviceLibLinkInfo[K] =
239-
true && (!NoDeviceLibs || K.equals("internal"));
238+
DeviceLibLinkInfo[K] = true && (!NoDeviceLibs || K == "internal");
240239
break;
241240
}
242241
auto LinkInfoIter = DeviceLibLinkInfo.find(Val);
243-
if (LinkInfoIter == DeviceLibLinkInfo.end() || Val.equals("internal")) {
242+
if (LinkInfoIter == DeviceLibLinkInfo.end() || Val == "internal") {
244243
// TODO: Move the diagnostic to the SYCL section of
245244
// Driver::CreateOffloadingDeviceToolChains() to minimize code
246245
// duplication.
@@ -488,7 +487,7 @@ const char *SYCL::Linker::constructLLVMLinkCommand(
488487
for (const auto &L : SYCLDeviceLibList) {
489488
std::string DeviceLibName(L);
490489
DeviceLibName.append(LibPostfix);
491-
if (StringRef(PureLibName).equals(DeviceLibName) ||
490+
if (StringRef(PureLibName) == DeviceLibName ||
492491
(IsNVPTX && StringRef(PureLibName).starts_with(L)))
493492
return true;
494493
}
@@ -899,7 +898,7 @@ static bool hasPVCDevice(const ArgStringList &CmdArgs) {
899898
DeviceArg = SplitArg;
900899
break;
901900
}
902-
if (SplitArg.equals("-device"))
901+
if (SplitArg == "-device")
903902
DeviceSeen = true;
904903
}
905904
if (DeviceSeen)
@@ -1477,8 +1476,8 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
14771476
auto ProcessElement = [&](StringRef Ele) {
14781477
auto [DeviceName, RegAllocMode] = Ele.split(':');
14791478
StringRef BackendOptName = SYCL::gen::getGenGRFFlag(RegAllocMode);
1480-
bool IsDefault = RegAllocMode.equals("default");
1481-
if (RegAllocMode.empty() || !DeviceName.equals("pvc") ||
1479+
bool IsDefault = RegAllocMode == "default";
1480+
if (RegAllocMode.empty() || DeviceName != "pvc" ||
14821481
(BackendOptName.empty() && !IsDefault)) {
14831482
getDriver().Diag(diag::err_drv_unsupported_option_argument)
14841483
<< A->getSpelling() << Ele;
@@ -1526,7 +1525,7 @@ void SYCLToolChain::AddImpliedTargetArgs(const llvm::Triple &Triple,
15261525
if (Args.hasArg(options::OPT_fintelfpga) && getDriver().IsFPGAHWMode() &&
15271526
Triple.getSubArch() == llvm::Triple::SPIRSubArch_fpga) {
15281527
if (Arg *A = Args.getLastArg(options::OPT_ffp_model_EQ)) {
1529-
if (StringRef(A->getValue()).equals("fast"))
1528+
if (StringRef(A->getValue()) == "fast")
15301529
BeArgs.push_back("-vpfp-relaxed");
15311530
}
15321531
}

0 commit comments

Comments
 (0)