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 &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 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(InlineAsmVal); - const std::string &AsmString = cast(Val)->getAsmString(); + StringRef AsmString = cast(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 &AsmPieces) { bool X86TargetLowering::ExpandInlineAsm(CallInst *CI) const { InlineAsm *IA = cast(CI->getCalledOperand()); - const std::string &AsmStr = IA->getAsmString(); + StringRef AsmStr = IA->getAsmString(); IntegerType *Ty = dyn_cast(CI->getType()); if (!Ty || Ty->getBitWidth() % 16 != 0)