Skip to content

[IR] Teach getConstraintString to return StringRef (NFC) #139401

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
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 @@ -84,7 +84,7 @@ class InlineAsm final : public Value {
FunctionType *getFunctionType() const;

const std::string &getAsmString() const { return AsmString; }
const std::string &getConstraintString() const { return Constraints; }
StringRef getConstraintString() const { return Constraints; }
void collectAsmStrs(SmallVectorImpl<StringRef> &AsmStrs) const;

/// This static method can be used by the parser to check to see if the
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6022,7 +6022,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
FunctionType::get(FTy->getReturnType(), ArgTys, FTy->isVarArg());

// Update constraint string to use label constraints.
std::string Constraints = IA->getConstraintString();
std::string Constraints = IA->getConstraintString().str();
unsigned ArgNo = 0;
size_t Pos = 0;
for (const auto &CI : ConstraintInfo) {
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 @@ -2805,7 +2805,7 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
Record.append(AsmStr.begin(), AsmStr.end());

// Add the constraint string.
const std::string &ConstraintStr = IA->getConstraintString();
StringRef ConstraintStr = IA->getConstraintString();
Record.push_back(ConstraintStr.size());
Record.append(ConstraintStr.begin(), ConstraintStr.end());
Stream.EmitRecord(bitc::CST_CODE_INLINEASM, Record);
Expand Down
7 changes: 3 additions & 4 deletions llvm/lib/IR/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,10 @@ const char *LLVMGetInlineAsmAsmString(LLVMValueRef InlineAsmVal, size_t *Len) {
const char *LLVMGetInlineAsmConstraintString(LLVMValueRef InlineAsmVal,
size_t *Len) {
Value *Val = unwrap<Value>(InlineAsmVal);
const std::string &ConstraintString =
cast<InlineAsm>(Val)->getConstraintString();
StringRef ConstraintString = cast<InlineAsm>(Val)->getConstraintString();

*Len = ConstraintString.length();
return ConstraintString.c_str();
*Len = ConstraintString.size();
return ConstraintString.data();
}

LLVMInlineAsmDialect LLVMGetInlineAsmDialect(LLVMValueRef InlineAsmVal) {
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/ARM/ARMISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20276,9 +20276,9 @@ bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const {
SplitString(AsmStr, AsmPieces, " \t,");

// rev $0, $1
if (AsmPieces.size() == 3 &&
AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" &&
IA->getConstraintString().compare(0, 4, "=l,l") == 0) {
if (AsmPieces.size() == 3 && AsmPieces[0] == "rev" &&
AsmPieces[1] == "$0" && AsmPieces[2] == "$1" &&
IA->getConstraintString().starts_with("=l,l")) {
IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
if (Ty && Ty->getBitWidth() == 32)
return IntrinsicLowering::LowerToByteSwap(CI);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,7 @@ void DXILBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
Record.append(AsmStr.begin(), AsmStr.end());

// Add the constraint string.
const std::string &ConstraintStr = IA->getConstraintString();
StringRef ConstraintStr = IA->getConstraintString();
Record.push_back(ConstraintStr.size());
Record.append(ConstraintStr.begin(), ConstraintStr.end());
Stream.EmitRecord(bitc::CST_CODE_INLINEASM, Record);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60860,7 +60860,7 @@ bool X86TargetLowering::ExpandInlineAsm(CallInst *CI) const {

// rorw $$8, ${0:w} --> llvm.bswap.i16
if (CI->getType()->isIntegerTy(16) &&
IA->getConstraintString().compare(0, 5, "=r,0,") == 0 &&
IA->getConstraintString().starts_with("=r,0,") &&
(matchAsm(AsmPieces[0], {"rorw", "$$8,", "${0:w}"}) ||
matchAsm(AsmPieces[0], {"rolw", "$$8,", "${0:w}"}))) {
AsmPieces.clear();
Expand All @@ -60873,7 +60873,7 @@ bool X86TargetLowering::ExpandInlineAsm(CallInst *CI) const {
break;
case 3:
if (CI->getType()->isIntegerTy(32) &&
IA->getConstraintString().compare(0, 5, "=r,0,") == 0 &&
IA->getConstraintString().starts_with("=r,0,") &&
matchAsm(AsmPieces[0], {"rorw", "$$8,", "${0:w}"}) &&
matchAsm(AsmPieces[1], {"rorl", "$$16,", "$0"}) &&
matchAsm(AsmPieces[2], {"rorw", "$$8,", "${0:w}"})) {
Expand Down
Loading