[Target, Transforms] Use StringRef::contains (NFC)

This commit is contained in:
Kazu Hirata 2021-10-22 08:52:33 -07:00
parent 12b44bf5ee
commit 6fe949c4ed
9 changed files with 24 additions and 26 deletions

View File

@ -3351,7 +3351,7 @@ void AArch64AsmParser::createSysAlias(uint16_t Encoding, OperandVector &Operands
/// the SYS instruction. Parse them specially so that we create a SYS MCInst. /// the SYS instruction. Parse them specially so that we create a SYS MCInst.
bool AArch64AsmParser::parseSysAlias(StringRef Name, SMLoc NameLoc, bool AArch64AsmParser::parseSysAlias(StringRef Name, SMLoc NameLoc,
OperandVector &Operands) { OperandVector &Operands) {
if (Name.find('.') != StringRef::npos) if (Name.contains('.'))
return TokError("invalid operand"); return TokError("invalid operand");
Mnemonic = Name; Mnemonic = Name;

View File

@ -113,7 +113,7 @@ MetadataStreamerV2::getAddressSpaceQualifier(
ValueKind MetadataStreamerV2::getValueKind(Type *Ty, StringRef TypeQual, ValueKind MetadataStreamerV2::getValueKind(Type *Ty, StringRef TypeQual,
StringRef BaseTypeName) const { StringRef BaseTypeName) const {
if (TypeQual.find("pipe") != StringRef::npos) if (TypeQual.contains("pipe"))
return ValueKind::Pipe; return ValueKind::Pipe;
return StringSwitch<ValueKind>(BaseTypeName) return StringSwitch<ValueKind>(BaseTypeName)
@ -533,7 +533,7 @@ MetadataStreamerV3::getAddressSpaceQualifier(unsigned AddressSpace) const {
StringRef MetadataStreamerV3::getValueKind(Type *Ty, StringRef TypeQual, StringRef MetadataStreamerV3::getValueKind(Type *Ty, StringRef TypeQual,
StringRef BaseTypeName) const { StringRef BaseTypeName) const {
if (TypeQual.find("pipe") != StringRef::npos) if (TypeQual.contains("pipe"))
return "pipe"; return "pipe";
return StringSwitch<StringRef>(BaseTypeName) return StringSwitch<StringRef>(BaseTypeName)

View File

@ -1371,8 +1371,7 @@ bool AMDGPULibCalls::fold_wavefrontsize(CallInst *CI, IRBuilder<> &B) {
StringRef CPU = TM->getTargetCPU(); StringRef CPU = TM->getTargetCPU();
StringRef Features = TM->getTargetFeatureString(); StringRef Features = TM->getTargetFeatureString();
if ((CPU.empty() || CPU.equals_insensitive("generic")) && if ((CPU.empty() || CPU.equals_insensitive("generic")) &&
(Features.empty() || (Features.empty() || !Features.contains_insensitive("wavefrontsize")))
Features.find_insensitive("wavefrontsize") == StringRef::npos))
return false; return false;
Function *F = CI->getParent()->getParent(); Function *F = CI->getParent()->getParent();

View File

@ -82,12 +82,12 @@ GCNSubtarget::initializeSubtargetDependencies(const Triple &TT,
FullFS += "+enable-prt-strict-null,"; // This is overridden by a disable in FS FullFS += "+enable-prt-strict-null,"; // This is overridden by a disable in FS
// Disable mutually exclusive bits. // Disable mutually exclusive bits.
if (FS.find_insensitive("+wavefrontsize") != StringRef::npos) { if (FS.contains_insensitive("+wavefrontsize")) {
if (FS.find_insensitive("wavefrontsize16") == StringRef::npos) if (!FS.contains_insensitive("wavefrontsize16"))
FullFS += "-wavefrontsize16,"; FullFS += "-wavefrontsize16,";
if (FS.find_insensitive("wavefrontsize32") == StringRef::npos) if (!FS.contains_insensitive("wavefrontsize32"))
FullFS += "-wavefrontsize32,"; FullFS += "-wavefrontsize32,";
if (FS.find_insensitive("wavefrontsize64") == StringRef::npos) if (!FS.contains_insensitive("wavefrontsize64"))
FullFS += "-wavefrontsize64,"; FullFS += "-wavefrontsize64,";
} }

View File

@ -90,9 +90,8 @@ static bool isSmallDataSection(StringRef Sec) {
return true; return true;
// If either ".sdata." or ".sbss." is a substring of the section name // If either ".sdata." or ".sbss." is a substring of the section name
// then put the symbol in small data. // then put the symbol in small data.
return Sec.find(".sdata.") != StringRef::npos || return Sec.contains(".sdata.") || Sec.contains(".sbss.") ||
Sec.find(".sbss.") != StringRef::npos || Sec.contains(".scommon.");
Sec.find(".scommon.") != StringRef::npos;
} }
static const char *getSectionSuffixForSize(unsigned Size) { static const char *getSectionSuffixForSize(unsigned Size) {
@ -178,10 +177,10 @@ MCSection *HexagonTargetObjectFile::getExplicitSectionGlobal(
if (GO->hasSection()) { if (GO->hasSection()) {
StringRef Section = GO->getSection(); StringRef Section = GO->getSection();
if (Section.find(".access.text.group") != StringRef::npos) if (Section.contains(".access.text.group"))
return getContext().getELFSection(GO->getSection(), ELF::SHT_PROGBITS, return getContext().getELFSection(GO->getSection(), ELF::SHT_PROGBITS,
ELF::SHF_ALLOC | ELF::SHF_EXECINSTR); ELF::SHF_ALLOC | ELF::SHF_EXECINSTR);
if (Section.find(".access.data.group") != StringRef::npos) if (Section.contains(".access.data.group"))
return getContext().getELFSection(GO->getSection(), ELF::SHT_PROGBITS, return getContext().getELFSection(GO->getSection(), ELF::SHT_PROGBITS,
ELF::SHF_WRITE | ELF::SHF_ALLOC); ELF::SHF_WRITE | ELF::SHF_ALLOC);
} }

View File

@ -431,10 +431,10 @@ public:
bool checkForP2AlignIfLoadStore(OperandVector &Operands, StringRef InstName) { bool checkForP2AlignIfLoadStore(OperandVector &Operands, StringRef InstName) {
// FIXME: there is probably a cleaner way to do this. // FIXME: there is probably a cleaner way to do this.
auto IsLoadStore = InstName.find(".load") != StringRef::npos || auto IsLoadStore = InstName.contains(".load") ||
InstName.find(".store") != StringRef::npos || InstName.contains(".store") ||
InstName.find("prefetch") != StringRef::npos; InstName.contains("prefetch");
auto IsAtomic = InstName.find("atomic.") != StringRef::npos; auto IsAtomic = InstName.contains("atomic.");
if (IsLoadStore || IsAtomic) { if (IsLoadStore || IsAtomic) {
// Parse load/store operands of the form: offset:p2align=align // Parse load/store operands of the form: offset:p2align=align
if (IsLoadStore && isNext(AsmToken::Colon)) { if (IsLoadStore && isNext(AsmToken::Colon)) {
@ -450,7 +450,7 @@ public:
// v128.{load,store}{8,16,32,64}_lane has both a memarg and a lane // v128.{load,store}{8,16,32,64}_lane has both a memarg and a lane
// index. We need to avoid parsing an extra alignment operand for the // index. We need to avoid parsing an extra alignment operand for the
// lane index. // lane index.
auto IsLoadStoreLane = InstName.find("_lane") != StringRef::npos; auto IsLoadStoreLane = InstName.contains("_lane");
if (IsLoadStoreLane && Operands.size() == 4) if (IsLoadStoreLane && Operands.size() == 4)
return false; return false;
// Alignment not specified (or atomics, must use default alignment). // Alignment not specified (or atomics, must use default alignment).

View File

@ -3104,8 +3104,7 @@ void X86FrameLowering::adjustForHiPEPrologue(
// having a ".", such as a simple <Module>.<Function>.<Arity>, or an // having a ".", such as a simple <Module>.<Function>.<Arity>, or an
// "_", such as the BIF "suspend_0") as they are executed on another // "_", such as the BIF "suspend_0") as they are executed on another
// stack. // stack.
if (F->getName().find("erlang.") != StringRef::npos || if (F->getName().contains("erlang.") || F->getName().contains("bif_") ||
F->getName().find("bif_") != StringRef::npos ||
F->getName().find_first_of("._") == StringRef::npos) F->getName().find_first_of("._") == StringRef::npos)
continue; continue;

View File

@ -2003,7 +2003,8 @@ bool ModuleAddressSanitizer::shouldInstrumentGlobal(GlobalVariable *G) const {
// Globals from llvm.metadata aren't emitted, do not instrument them. // Globals from llvm.metadata aren't emitted, do not instrument them.
if (Section == "llvm.metadata") return false; if (Section == "llvm.metadata") return false;
// Do not instrument globals from special LLVM sections. // Do not instrument globals from special LLVM sections.
if (Section.find("__llvm") != StringRef::npos || Section.find("__LLVM") != StringRef::npos) return false; if (Section.contains("__llvm") || Section.contains("__LLVM"))
return false;
// Do not instrument function pointers to initialization and termination // Do not instrument function pointers to initialization and termination
// routines: dynamic linker will not properly handle redzones. // routines: dynamic linker will not properly handle redzones.

View File

@ -2351,7 +2351,7 @@ Value *LibCallSimplifier::optimizePrintFString(CallInst *CI, IRBuilderBase &B) {
// printf("foo\n") --> puts("foo") // printf("foo\n") --> puts("foo")
if (FormatStr.back() == '\n' && if (FormatStr.back() == '\n' &&
FormatStr.find('%') == StringRef::npos) { // No format characters. !FormatStr.contains('%')) { // No format characters.
// Create a string literal with no \n on it. We expect the constant merge // Create a string literal with no \n on it. We expect the constant merge
// pass to be run after this pass, to merge duplicate strings. // pass to be run after this pass, to merge duplicate strings.
FormatStr = FormatStr.drop_back(); FormatStr = FormatStr.drop_back();
@ -2421,7 +2421,7 @@ Value *LibCallSimplifier::optimizeSPrintFString(CallInst *CI,
if (CI->arg_size() == 2) { if (CI->arg_size() == 2) {
// Make sure there's no % in the constant array. We could try to handle // Make sure there's no % in the constant array. We could try to handle
// %% -> % in the future if we cared. // %% -> % in the future if we cared.
if (FormatStr.find('%') != StringRef::npos) if (FormatStr.contains('%'))
return nullptr; // we found a format specifier, bail out. return nullptr; // we found a format specifier, bail out.
// sprintf(str, fmt) -> llvm.memcpy(align 1 str, align 1 fmt, strlen(fmt)+1) // sprintf(str, fmt) -> llvm.memcpy(align 1 str, align 1 fmt, strlen(fmt)+1)
@ -2548,7 +2548,7 @@ Value *LibCallSimplifier::optimizeSnPrintFString(CallInst *CI,
if (CI->arg_size() == 3) { if (CI->arg_size() == 3) {
// Make sure there's no % in the constant array. We could try to handle // Make sure there's no % in the constant array. We could try to handle
// %% -> % in the future if we cared. // %% -> % in the future if we cared.
if (FormatStr.find('%') != StringRef::npos) if (FormatStr.contains('%'))
return nullptr; // we found a format specifier, bail out. return nullptr; // we found a format specifier, bail out.
if (N == 0) if (N == 0)
@ -2637,7 +2637,7 @@ Value *LibCallSimplifier::optimizeFPrintFString(CallInst *CI,
// fprintf(F, "foo") --> fwrite("foo", 3, 1, F) // fprintf(F, "foo") --> fwrite("foo", 3, 1, F)
if (CI->arg_size() == 2) { if (CI->arg_size() == 2) {
// Could handle %% -> % if we cared. // Could handle %% -> % if we cared.
if (FormatStr.find('%') != StringRef::npos) if (FormatStr.contains('%'))
return nullptr; // We found a format specifier. return nullptr; // We found a format specifier.
return emitFWrite( return emitFWrite(