Skip to content

[IR] Teach getAsmString to return StringRef (NFC) #139406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/IR/InlineAsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/GlobalISel/InlineAsmLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/IR/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/NVPTX/NVPTXTargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading