[llvm] [IR] Teach getAsmString to return StringRef (NFC) (PR #139406)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat May 10 13:28:06 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/139406
This is for consistency with #139401.
>From 5b934874b2226b5ecc9aeff860a50f836c7b5b18 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 10 May 2025 13:06:32 -0700
Subject: [PATCH] [IR] Teach getAsmString to return StringRef (NFC)
This is for consistency with #139401.
---
llvm/include/llvm/IR/InlineAsm.h | 2 +-
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 +-
llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp | 2 +-
llvm/lib/CodeGen/SelectionDAG/FastISel.cpp | 2 +-
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 2 +-
llvm/lib/IR/Core.cpp | 6 +++---
llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp | 2 +-
llvm/lib/Target/X86/X86ISelLowering.cpp | 2 +-
8 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/llvm/include/llvm/IR/InlineAsm.h b/llvm/include/llvm/IR/InlineAsm.h
index c3c3ed33adda9..3501c877a5c22 100644
--- a/llvm/include/llvm/IR/InlineAsm.h
+++ b/llvm/include/llvm/IR/InlineAsm.h
@@ -83,7 +83,7 @@ class InlineAsm final : public Value {
///
FunctionType *getFunctionType() const;
- const std::string &getAsmString() const { return AsmString; }
+ StringRef getAsmString() const { return AsmString; }
StringRef getConstraintString() const { return Constraints; }
void collectAsmStrs(SmallVectorImpl<StringRef> &AsmStrs) const;
diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
index 158b0a669acb1..658fd3fce7672 100644
--- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -2800,7 +2800,7 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
unsigned(IA->getDialect() & 1) << 2 | unsigned(IA->canThrow()) << 3);
// Add the asm string.
- const std::string &AsmStr = IA->getAsmString();
+ StringRef AsmStr = IA->getAsmString();
Record.push_back(AsmStr.size());
Record.append(AsmStr.begin(), AsmStr.end());
diff --git a/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp b/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
index 81f25b21a0409..fbbbea6156fc7 100644
--- a/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
@@ -297,7 +297,7 @@ bool InlineAsmLowering::lowerInlineAsm(
// Create the MachineInstr, but don't insert it yet since input
// operands still need to insert instructions before this one
auto Inst = MIRBuilder.buildInstrNoInsert(TargetOpcode::INLINEASM)
- .addExternalSymbol(IA->getAsmString().c_str())
+ .addExternalSymbol(IA->getAsmString().data())
.addImm(ExtraInfo.get());
// Starting from this operand: flag followed by register(s) will be added as
diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
index fbc0264961bc7..59cd0dc8dd348 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -1173,7 +1173,7 @@ bool FastISel::selectCall(const User *I) {
MachineInstrBuilder MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(TargetOpcode::INLINEASM));
- MIB.addExternalSymbol(IA->getAsmString().c_str());
+ MIB.addExternalSymbol(IA->getAsmString().data());
MIB.addImm(ExtraInfo);
const MDNode *SrcLoc = Call->getMetadata("srcloc");
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 9d138d364bad7..8e74a076cc013 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -10017,7 +10017,7 @@ void SelectionDAGBuilder::visitInlineAsm(const CallBase &Call,
std::vector<SDValue> AsmNodeOperands;
AsmNodeOperands.push_back(SDValue()); // reserve space for input chain
AsmNodeOperands.push_back(DAG.getTargetExternalSymbol(
- IA->getAsmString().c_str(), TLI.getProgramPointerTy(DAG.getDataLayout())));
+ IA->getAsmString().data(), TLI.getProgramPointerTy(DAG.getDataLayout())));
// If we have a !srcloc metadata node associated with it, we want to attach
// this to the ultimately generated inline asm machineinstr. To do this, we
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index a3cedcfd41095..1954b44af22ad 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -520,10 +520,10 @@ LLVMValueRef LLVMGetInlineAsm(LLVMTypeRef Ty, const char *AsmString,
const char *LLVMGetInlineAsmAsmString(LLVMValueRef InlineAsmVal, size_t *Len) {
Value *Val = unwrap<Value>(InlineAsmVal);
- const std::string &AsmString = cast<InlineAsm>(Val)->getAsmString();
+ StringRef AsmString = cast<InlineAsm>(Val)->getAsmString();
- *Len = AsmString.length();
- return AsmString.c_str();
+ *Len = AsmString.size();
+ return AsmString.data();
}
const char *LLVMGetInlineAsmConstraintString(LLVMValueRef InlineAsmVal,
diff --git a/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp b/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp
index 66c5139f8c2cc..2ada2e464698a 100644
--- a/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp
@@ -492,7 +492,7 @@ NVPTXTTIImpl::getInstructionCost(const User *U,
// since it is classified as a call in the IR. A better cost model would
// be to return the number of asm instructions embedded in the asm
// string.
- auto &AsmStr = IA->getAsmString();
+ StringRef AsmStr = IA->getAsmString();
const unsigned InstCount =
count_if(split(AsmStr, ';'), [](StringRef AsmInst) {
// Trim off scopes denoted by '{' and '}' as these can be ignored
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 9f75fe8803cda..ac4fb157a6026 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -60829,7 +60829,7 @@ static bool clobbersFlagRegisters(const SmallVector<StringRef, 4> &AsmPieces) {
bool X86TargetLowering::ExpandInlineAsm(CallInst *CI) const {
InlineAsm *IA = cast<InlineAsm>(CI->getCalledOperand());
- const std::string &AsmStr = IA->getAsmString();
+ StringRef AsmStr = IA->getAsmString();
IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
if (!Ty || Ty->getBitWidth() % 16 != 0)
More information about the llvm-commits
mailing list