From 1c46fc00f56f25abaefd8d124460599ae06214b4 Mon Sep 17 00:00:00 2001 From: Jacob Yu Date: Sun, 25 Aug 2024 18:59:25 +0100 Subject: [PATCH 1/3] [mlir][arith] Add comparison integration tests (#96974) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Comparison operations regression tests, from the original larger PR that has been broken down: https://github.com/llvm/llvm-project/pull/92272 --------- Co-authored-by: Jakub Kuderski Co-authored-by: Andrzej WarzyƄski --- .../Dialect/Arith/CPU/comparison.mlir | 174 ++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir diff --git a/mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir b/mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir new file mode 100644 index 00000000000000..418fbb0c0a94c7 --- /dev/null +++ b/mlir/test/Integration/Dialect/Arith/CPU/comparison.mlir @@ -0,0 +1,174 @@ +// RUN: mlir-opt %s --convert-scf-to-cf --convert-cf-to-llvm --convert-vector-to-llvm \ +// RUN: --convert-func-to-llvm --convert-arith-to-llvm | \ +// RUN: mlir-cpu-runner -e entry -entry-point-result=void \ +// RUN: --shared-libs=%mlir_c_runner_utils | \ +// RUN: FileCheck %s --match-full-lines + +func.func @cmpi_eq_i1(%v1 : i1, %v2 : i1) { + vector.print str "@cmpi_eq_i1\n" + %res = arith.cmpi eq, %v1, %v2 : i1 + vector.print %res : i1 + return +} + +func.func @cmpi_slt_i1(%v1 : i1, %v2 : i1) { + vector.print str "@cmpi_slt_i1\n" + %res = arith.cmpi slt, %v1, %v2 : i1 + vector.print %res : i1 + return +} + +func.func @cmpi_sle_i1(%v1 : i1, %v2 : i1) { + vector.print str "@cmpi_sle_i1\n" + %res = arith.cmpi sle, %v1, %v2 : i1 + vector.print %res : i1 + return +} + +func.func @cmpi_sgt_i1(%v1 : i1, %v2 : i1) { + vector.print str "@cmpi_sgt_i1\n" + %res = arith.cmpi sgt, %v1, %v2 : i1 + vector.print %res : i1 + return +} + +func.func @cmpi_sge_i1(%v1 : i1, %v2 : i1) { + vector.print str "@cmpi_sge_i1\n" + %res = arith.cmpi sge, %v1, %v2 : i1 + vector.print %res : i1 + return +} + +func.func @cmpi_eq() { + // ------------------------------------------------ + // Test i1 + // ------------------------------------------------ + %false_i1 = arith.constant 0 : i1 + %true_i1 = arith.constant 1 : i1 + %true_i1_n1 = arith.constant -1 : i1 + + // int values 1 and -1 are represented with the same bitvector (`0b1`) + // CHECK-LABEL: @cmpi_eq_i1 + // CHECK-NEXT: 1 + func.call @cmpi_eq_i1(%true_i1, %true_i1_n1) : (i1, i1) -> () + + // CHECK-LABEL: @cmpi_eq_i1 + // CHECK-NEXT: 0 + func.call @cmpi_eq_i1(%false_i1, %true_i1) : (i1, i1) -> () + + // CHECK-LABEL: @cmpi_eq_i1 + // CHECK-NEXT: 0 + func.call @cmpi_eq_i1(%true_i1, %false_i1) : (i1, i1) -> () + + // CHECK-LABEL: @cmpi_eq_i1 + // CHECK-NEXT: 1 + func.call @cmpi_eq_i1(%true_i1, %true_i1) : (i1, i1) -> () + + // CHECK-LABEL: @cmpi_eq_i1 + // CHECK-NEXT: 1 + func.call @cmpi_eq_i1(%false_i1, %false_i1) : (i1, i1) -> () + + %false = arith.constant false + %true = arith.constant true + + // CHECK-LABEL: @cmpi_eq_i1 + // CHECK-NEXT: 1 + func.call @cmpi_eq_i1(%true, %true_i1) : (i1, i1) -> () + + // CHECK-LABEL: @cmpi_eq_i1 + // CHECK-NEXT: 1 + func.call @cmpi_eq_i1(%false, %false_i1) : (i1, i1) -> () + + // CHECK-LABEL: @cmpi_eq_i1 + // CHECK-NEXT: 1 + func.call @cmpi_eq_i1(%true, %true_i1_n1) : (i1, i1) -> () + + // ------------------------------------------------ + // TODO: Test i8, i16 etc.. + // ------------------------------------------------ + return +} + +func.func @cmpi_signed() { + // ------------------------------------------------ + // Test i1 + // ------------------------------------------------ + %false_i1 = arith.constant 0 : i1 + %true_i1 = arith.constant 1 : i1 + %true_i1_n1 = arith.constant -1 : i1 + + // int values 1 and -1 are represented with the same bitvector (`0b1`) + // But, bitvector `1` is interpreted as int value -1 in signed comparison + + // CHECK-LABEL: @cmpi_sge_i1 + // CHECK-NEXT: 1 + func.call @cmpi_sge_i1(%false_i1, %true_i1_n1) : (i1, i1) -> () + + // CHECK-LABEL: @cmpi_sge_i1 + // CHECK-NEXT: 1 + func.call @cmpi_sge_i1(%false_i1, %true_i1) : (i1, i1) -> () + + // CHECK-LABEL: @cmpi_sge_i1 + // CHECK-NEXT: 0 + func.call @cmpi_sge_i1(%true_i1, %false_i1) : (i1, i1) -> () + + %false = arith.constant false + %true = arith.constant true + + // CHECK-LABEL: @cmpi_slt_i1 + // CHECK-NEXT: 0 + func.call @cmpi_slt_i1(%false, %true) : (i1, i1) -> () + + // CHECK-LABEL: @cmpi_sle_i1 + // CHECK-NEXT: 0 + func.call @cmpi_sle_i1(%false, %true) : (i1, i1) -> () + + // CHECK-LABEL: @cmpi_sgt_i1 + // CHECK-NEXT: 1 + func.call @cmpi_sgt_i1(%false, %true) : (i1, i1) -> () + + // CHECK-LABEL: @cmpi_sge_i1 + // CHECK-NEXT: 1 + func.call @cmpi_sge_i1(%false, %true) : (i1, i1) -> () + + // CHECK-LABEL: @cmpi_sge_i1 + // CHECK-NEXT: 0 + func.call @cmpi_sge_i1(%true, %false) : (i1, i1) -> () + + // ------------------------------------------------ + // TODO: Test i8, i16 etc.. + // ------------------------------------------------ + return +} + +func.func @cmpi_ult_index(%v1 : index, %v2 : index) { + vector.print str "@cmpi_ult_index\n" + %res = arith.cmpi ult, %v1, %v2 : index + vector.print %res : i1 + return +} + +func.func @cmpi_unsigned() { + // ------------------------------------------------ + // Test index + // ------------------------------------------------ + // 0 `ult` -2^63 = true + %zero = arith.constant 0 : index + %index_min = arith.constant -9223372036854775808 : index + + // CHECK-LABEL: @cmpi_ult_index + // CHECK-NEXT: 1 + func.call @cmpi_ult_index(%zero, %index_min) : (index, index) -> () + + // ------------------------------------------------ + // TODO: i1, i8, i16, uge, ule etc.. + // ------------------------------------------------ + return +} + +func.func @entry() { + func.call @cmpi_eq() : () -> () + func.call @cmpi_signed() : () -> () + func.call @cmpi_unsigned() : () -> () + return +} From 33f3ebc86e7d3afcb65c551feba5bbc2421b42ed Mon Sep 17 00:00:00 2001 From: Anshil Gandhi <95053726+gandhi56@users.noreply.github.com> Date: Sun, 25 Aug 2024 14:06:29 -0400 Subject: [PATCH 2/3] [AMDGPU][LTO] Assume closed world after linking (#105845) --- llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp | 4 ++++ llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp | 8 ++++++-- llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll | 10 ++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp index d65e0ae92308e6..81932cc2c3c3bc 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp @@ -1066,6 +1066,10 @@ static bool runImpl(Module &M, AnalysisGetter &AG, TargetMachine &TM, Attributor A(Functions, InfoCache, AC); + LLVM_DEBUG(dbgs() << "Module " << M.getName() << " is " + << (AC.IsClosedWorldModule ? "" : "not ") + << "assumed to be a closed world.\n"); + for (Function &F : M) { if (F.isIntrinsic()) continue; diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp index 7ac7b3315bb972..307774ea3da9eb 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -760,8 +760,12 @@ void AMDGPUTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) { // module is partitioned for codegen. if (EnableLowerModuleLDS) PM.addPass(AMDGPULowerModuleLDSPass(*this)); - if (EnableAMDGPUAttributor && Level != OptimizationLevel::O0) - PM.addPass(AMDGPUAttributorPass(*this)); + + if (EnableAMDGPUAttributor && Level != OptimizationLevel::O0) { + AMDGPUAttributorOptions Opts; + Opts.IsClosedWorld = true; + PM.addPass(AMDGPUAttributorPass(*this, Opts)); + } }); PB.registerRegClassFilterParsingCallback( diff --git a/llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll b/llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll new file mode 100644 index 00000000000000..6966c702e741cc --- /dev/null +++ b/llvm/test/LTO/AMDGPU/gpu-rdc-amdgpu-attrs.ll @@ -0,0 +1,10 @@ +; RUN: opt -O3 -debug-only=amdgpu-attributor -S -o - %s 2>&1 | FileCheck %s --check-prefix=PRE-LINK +; RUN: opt -passes="lto" -debug-only=amdgpu-attributor -S -o - %s 2>&1 | FileCheck %s --check-prefix=POST-LINK + +target triple = "amdgcn-amd-amdhsa" + +; PRE-LINK: Module {{.*}} is not assumed to be a closed world. +; POST-LINK: Module {{.*}} is assumed to be a closed world. +define hidden noundef i32 @_Z3foov() { + ret i32 1 +} From 33e7cd6ff23f6c904314d17c68dc58168fd32d09 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 25 Aug 2024 11:30:49 -0700 Subject: [PATCH 3/3] [llvm] Prefer StringRef::substr to StringRef::slice (NFC) (#105943) S.substr(N) is simpler than S.slice(N, StringRef::npos) and S.slice(N, S.size()). Also, substr is probably better recognizable than slice thanks to std::string_view::substr. --- llvm/include/llvm/ADT/StringRef.h | 4 ++-- llvm/lib/CodeGen/MIRParser/MIParser.cpp | 4 ++-- llvm/lib/MC/MCAsmStreamer.cpp | 4 ++-- llvm/lib/Object/MachOObjectFile.cpp | 10 +++++----- llvm/lib/Support/StringRef.cpp | 4 ++-- llvm/lib/Support/VirtualFileSystem.cpp | 6 +++--- llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp | 2 +- llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp | 8 ++++---- llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp | 2 +- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp | 2 +- llvm/lib/TargetParser/RISCVISAInfo.cpp | 6 +++--- llvm/utils/TableGen/AsmMatcherEmitter.cpp | 4 ++-- llvm/utils/TableGen/OptParserEmitter.cpp | 2 +- 13 files changed, 29 insertions(+), 29 deletions(-) diff --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h index 952d6485dafc1a..17ab10b9181f1a 100644 --- a/llvm/include/llvm/ADT/StringRef.h +++ b/llvm/include/llvm/ADT/StringRef.h @@ -713,7 +713,7 @@ namespace llvm { size_t Idx = find(Separator); if (Idx == npos) return std::make_pair(*this, StringRef()); - return std::make_pair(slice(0, Idx), slice(Idx + Separator.size(), npos)); + return std::make_pair(slice(0, Idx), substr(Idx + Separator.size())); } /// Split into two substrings around the last occurrence of a separator @@ -731,7 +731,7 @@ namespace llvm { size_t Idx = rfind(Separator); if (Idx == npos) return std::make_pair(*this, StringRef()); - return std::make_pair(slice(0, Idx), slice(Idx + Separator.size(), npos)); + return std::make_pair(slice(0, Idx), substr(Idx + Separator.size())); } /// Split into substrings around the occurrences of a separator string. diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index 0e2b71729fbf51..47b220172602d4 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -580,7 +580,7 @@ MIParser::MIParser(PerFunctionMIParsingState &PFS, SMDiagnostic &Error, void MIParser::lex(unsigned SkipChar) { CurrentSource = lexMIToken( - CurrentSource.slice(SkipChar, StringRef::npos), Token, + CurrentSource.substr(SkipChar), Token, [this](StringRef::iterator Loc, const Twine &Msg) { error(Loc, Msg); }); } @@ -2306,7 +2306,7 @@ bool MIParser::parseDIExpression(MDNode *&Expr) { Expr = llvm::parseDIExpressionBodyAtBeginning( CurrentSource, Read, Error, *PFS.MF.getFunction().getParent(), &PFS.IRSlots); - CurrentSource = CurrentSource.slice(Read, StringRef::npos); + CurrentSource = CurrentSource.substr(Read); lex(); if (!Expr) return error(Error.getMessage()); diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index 9309d5987dc949..bd6e8f03edf454 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -491,7 +491,7 @@ void MCAsmStreamer::addExplicitComment(const Twine &T) { ExplicitCommentToEmit.append("\t"); ExplicitCommentToEmit.append(MAI->getCommentString()); // drop // - ExplicitCommentToEmit.append(c.slice(2, c.size()).str()); + ExplicitCommentToEmit.append(c.substr(2).str()); } else if (c.starts_with(StringRef("/*"))) { size_t p = 2, len = c.size() - 2; // emit each line in comment as separate newline. @@ -512,7 +512,7 @@ void MCAsmStreamer::addExplicitComment(const Twine &T) { ExplicitCommentToEmit.append("\t"); ExplicitCommentToEmit.append(MAI->getCommentString()); - ExplicitCommentToEmit.append(c.slice(1, c.size()).str()); + ExplicitCommentToEmit.append(c.substr(1).str()); } else assert(false && "Unexpected Assembly Comment"); // full line comments immediately output diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index bd9b5dd13cdfe8..6f3dd4d8b51801 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -2436,12 +2436,12 @@ StringRef MachOObjectFile::guessLibraryShortName(StringRef Name, a = Name.rfind('/'); if (a == Name.npos || a == 0) goto guess_library; - Foo = Name.slice(a+1, Name.npos); + Foo = Name.substr(a + 1); // Look for a suffix starting with a '_' Idx = Foo.rfind('_'); if (Idx != Foo.npos && Foo.size() >= 2) { - Suffix = Foo.slice(Idx, Foo.npos); + Suffix = Foo.substr(Idx); if (Suffix != "_debug" && Suffix != "_profile") Suffix = StringRef(); else @@ -2468,7 +2468,7 @@ StringRef MachOObjectFile::guessLibraryShortName(StringRef Name, c = Name.rfind('/', b); if (c == Name.npos || c == 0) goto guess_library; - V = Name.slice(c+1, Name.npos); + V = Name.substr(c + 1); if (!V.starts_with("Versions/")) goto guess_library; d = Name.rfind('/', c); @@ -2489,7 +2489,7 @@ StringRef MachOObjectFile::guessLibraryShortName(StringRef Name, a = Name.rfind('.'); if (a == Name.npos || a == 0) return StringRef(); - Dylib = Name.slice(a, Name.npos); + Dylib = Name.substr(a); if (Dylib != ".dylib") goto guess_qtx; @@ -2527,7 +2527,7 @@ StringRef MachOObjectFile::guessLibraryShortName(StringRef Name, return Lib; guess_qtx: - Qtx = Name.slice(a, Name.npos); + Qtx = Name.substr(a); if (Qtx != ".qtx") return StringRef(); b = Name.rfind('/', a); diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp index f1042131a89cb7..4bbe4168820962 100644 --- a/llvm/lib/Support/StringRef.cpp +++ b/llvm/lib/Support/StringRef.cpp @@ -328,7 +328,7 @@ void StringRef::split(SmallVectorImpl &A, A.push_back(S.slice(0, Idx)); // Jump forward. - S = S.slice(Idx + Separator.size(), npos); + S = S.substr(Idx + Separator.size()); } // Push the tail. @@ -354,7 +354,7 @@ void StringRef::split(SmallVectorImpl &A, char Separator, A.push_back(S.slice(0, Idx)); // Jump forward. - S = S.slice(Idx + 1, npos); + S = S.substr(Idx + 1); } // Push the tail. diff --git a/llvm/lib/Support/VirtualFileSystem.cpp b/llvm/lib/Support/VirtualFileSystem.cpp index 9d21eba9df635f..6d756f425fb888 100644 --- a/llvm/lib/Support/VirtualFileSystem.cpp +++ b/llvm/lib/Support/VirtualFileSystem.cpp @@ -2780,7 +2780,7 @@ bool JSONWriter::containedIn(StringRef Parent, StringRef Path) { StringRef JSONWriter::containedPart(StringRef Parent, StringRef Path) { assert(!Parent.empty()); assert(containedIn(Parent, Path)); - return Path.slice(Parent.size() + 1, StringRef::npos); + return Path.substr(Parent.size() + 1); } void JSONWriter::startDirectory(StringRef Path) { @@ -2846,7 +2846,7 @@ void JSONWriter::write(ArrayRef Entries, if (UseOverlayRelative) { assert(RPath.starts_with(OverlayDir) && "Overlay dir must be contained in RPath"); - RPath = RPath.slice(OverlayDir.size(), RPath.size()); + RPath = RPath.substr(OverlayDir.size()); } bool IsCurrentDirEmpty = true; @@ -2879,7 +2879,7 @@ void JSONWriter::write(ArrayRef Entries, if (UseOverlayRelative) { assert(RPath.starts_with(OverlayDir) && "Overlay dir must be contained in RPath"); - RPath = RPath.slice(OverlayDir.size(), RPath.size()); + RPath = RPath.substr(OverlayDir.size()); } if (!Entry.IsDirectory) { writeEntry(path::filename(Entry.VPath), RPath); diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp index 1c5909c64bccd3..37add682b150e7 100644 --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -4183,7 +4183,7 @@ ParseStatus AArch64AsmParser::tryParseVectorRegister(MCRegister &Reg, if (RegNum) { if (Next != StringRef::npos) { - Kind = Name.slice(Next, StringRef::npos); + Kind = Name.substr(Next); if (!isValidVectorKind(Kind, MatchKind)) return TokError("invalid vector kind qualifier"); } diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp index c2951bf6dbf78f..1b6405c93820fc 100644 --- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -5251,7 +5251,7 @@ ParseStatus ARMAsmParser::parseMSRMaskOperand(OperandVector &Operands) { StringRef Flags = ""; std::string SpecReg = Mask.slice(Start, Next).lower(); if (Next != StringRef::npos) - Flags = Mask.slice(Next+1, Mask.size()); + Flags = Mask.substr(Next + 1); // FlagsVal contains the complete mask: // 3-0: Mask @@ -6648,15 +6648,15 @@ StringRef ARMAsmParser::splitMnemonic(StringRef Mnemonic, StringRef ExtraToken, // The "it" instruction has the condition mask on the end of the mnemonic. if (Mnemonic.starts_with("it")) { - ITMask = Mnemonic.slice(2, Mnemonic.size()); + ITMask = Mnemonic.substr(2); Mnemonic = Mnemonic.slice(0, 2); } if (Mnemonic.starts_with("vpst")) { - ITMask = Mnemonic.slice(4, Mnemonic.size()); + ITMask = Mnemonic.substr(4); Mnemonic = Mnemonic.slice(0, 4); } else if (Mnemonic.starts_with("vpt")) { - ITMask = Mnemonic.slice(3, Mnemonic.size()); + ITMask = Mnemonic.substr(3); Mnemonic = Mnemonic.slice(0, 3); } diff --git a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp index 55978af38000de..59ad995b44b04a 100644 --- a/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp +++ b/llvm/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp @@ -1682,7 +1682,7 @@ bool PPCAsmParser::ParseInstruction(ParseInstructionInfo &Info, StringRef Name, Operands.push_back(PPCOperand::CreateToken(Mnemonic, NameLoc, isPPC64())); if (Dot != StringRef::npos) { SMLoc DotLoc = SMLoc::getFromPointer(NameLoc.getPointer() + Dot); - StringRef DotStr = Name.slice(Dot, StringRef::npos); + StringRef DotStr = Name.substr(Dot); if (!NewOpcode.empty()) // Underlying memory for Name is volatile. Operands.push_back( PPCOperand::CreateTokenWithStringCopy(DotStr, DotLoc, isPPC64())); diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp index 6e17150edf2785..eda3c9fd50bf56 100644 --- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp +++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp @@ -1957,7 +1957,7 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) { consumeToken(); StringRef LHS = Identifier.slice(0, DotOffset); StringRef Dot = Identifier.slice(DotOffset, DotOffset + 1); - StringRef RHS = Identifier.slice(DotOffset + 1, StringRef::npos); + StringRef RHS = Identifier.substr(DotOffset + 1); if (!RHS.empty()) { getLexer().UnLex(AsmToken(AsmToken::Identifier, RHS)); } diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp index d82501ebf8d2fb..7fa3d8edec84d5 100644 --- a/llvm/lib/TargetParser/RISCVISAInfo.cpp +++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp @@ -508,7 +508,7 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) { size_t Idx = Arch.find('_'); StringRef Ext = Arch.slice(0, Idx); - Arch = Arch.slice(Idx, StringRef::npos); + Arch = Arch.substr(Idx); StringRef Prefix, MinorVersionStr; std::tie(Prefix, MinorVersionStr) = Ext.rsplit('p'); @@ -533,7 +533,7 @@ RISCVISAInfo::parseNormalizedArchString(StringRef Arch) { return getError("missing extension name"); StringRef ExtName = Prefix.slice(0, VersionStart); - StringRef MajorVersionStr = Prefix.slice(VersionStart, StringRef::npos); + StringRef MajorVersionStr = Prefix.substr(VersionStart); if (MajorVersionStr.getAsInteger(10, MajorVersion)) return getError("failed to parse major version number"); @@ -662,7 +662,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension, size_t Idx = Arch.find('_'); StringRef Ext = Arch.slice(0, Idx); - Arch = Arch.slice(Idx, StringRef::npos); + Arch = Arch.substr(Idx); do { StringRef Name, Vers, Desc; diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp index 98d0231d3055c2..3b630e3cf014e7 100644 --- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp +++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp @@ -849,14 +849,14 @@ parseTwoOperandConstraint(StringRef S, ArrayRef Loc) { size_t start = Ops.first.find_first_of('$'); if (start == std::string::npos) PrintFatalError(Loc, "expected '$' prefix on asm operand name"); - Ops.first = Ops.first.slice(start + 1, std::string::npos); + Ops.first = Ops.first.substr(start + 1); size_t end = Ops.first.find_last_of(" \t"); Ops.first = Ops.first.slice(0, end); // Now the second operand. start = Ops.second.find_first_of('$'); if (start == std::string::npos) PrintFatalError(Loc, "expected '$' prefix on asm operand name"); - Ops.second = Ops.second.slice(start + 1, std::string::npos); + Ops.second = Ops.second.substr(start + 1); end = Ops.second.find_last_of(" \t"); Ops.first = Ops.first.slice(0, end); return Ops; diff --git a/llvm/utils/TableGen/OptParserEmitter.cpp b/llvm/utils/TableGen/OptParserEmitter.cpp index 4fb1ca18ac11db..81195c8c106c23 100644 --- a/llvm/utils/TableGen/OptParserEmitter.cpp +++ b/llvm/utils/TableGen/OptParserEmitter.cpp @@ -178,7 +178,7 @@ static MarshallingInfo createMarshallingInfo(const Record &R) { break; if (Idx > 0) Ret.Values.push_back(ValuesStr.slice(0, Idx)); - ValuesStr = ValuesStr.slice(Idx + 1, StringRef::npos); + ValuesStr = ValuesStr.substr(Idx + 1); } if (!ValuesStr.empty()) Ret.Values.push_back(ValuesStr);