Skip to content

Commit 58014a5

Browse files
[IR] Teach getConstraintString to return StringRef (NFC) (#139401)
With this change, some callers get to use StringRef::starts_with. I'm planning to teach getAsmString to return StringRef also, but I'ld like to keep that separate from this patch.
1 parent f5f8ddc commit 58014a5

File tree

7 files changed

+12
-13
lines changed

7 files changed

+12
-13
lines changed

llvm/include/llvm/IR/InlineAsm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class InlineAsm final : public Value {
8484
FunctionType *getFunctionType() const;
8585

8686
const std::string &getAsmString() const { return AsmString; }
87-
const std::string &getConstraintString() const { return Constraints; }
87+
StringRef getConstraintString() const { return Constraints; }
8888
void collectAsmStrs(SmallVectorImpl<StringRef> &AsmStrs) const;
8989

9090
/// This static method can be used by the parser to check to see if the

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6022,7 +6022,7 @@ Error BitcodeReader::parseFunctionBody(Function *F) {
60226022
FunctionType::get(FTy->getReturnType(), ArgTys, FTy->isVarArg());
60236023

60246024
// Update constraint string to use label constraints.
6025-
std::string Constraints = IA->getConstraintString();
6025+
std::string Constraints = IA->getConstraintString().str();
60266026
unsigned ArgNo = 0;
60276027
size_t Pos = 0;
60286028
for (const auto &CI : ConstraintInfo) {

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2805,7 +2805,7 @@ void ModuleBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
28052805
Record.append(AsmStr.begin(), AsmStr.end());
28062806

28072807
// Add the constraint string.
2808-
const std::string &ConstraintStr = IA->getConstraintString();
2808+
StringRef ConstraintStr = IA->getConstraintString();
28092809
Record.push_back(ConstraintStr.size());
28102810
Record.append(ConstraintStr.begin(), ConstraintStr.end());
28112811
Stream.EmitRecord(bitc::CST_CODE_INLINEASM, Record);

llvm/lib/IR/Core.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,10 @@ const char *LLVMGetInlineAsmAsmString(LLVMValueRef InlineAsmVal, size_t *Len) {
529529
const char *LLVMGetInlineAsmConstraintString(LLVMValueRef InlineAsmVal,
530530
size_t *Len) {
531531
Value *Val = unwrap<Value>(InlineAsmVal);
532-
const std::string &ConstraintString =
533-
cast<InlineAsm>(Val)->getConstraintString();
532+
StringRef ConstraintString = cast<InlineAsm>(Val)->getConstraintString();
534533

535-
*Len = ConstraintString.length();
536-
return ConstraintString.c_str();
534+
*Len = ConstraintString.size();
535+
return ConstraintString.data();
537536
}
538537

539538
LLVMInlineAsmDialect LLVMGetInlineAsmDialect(LLVMValueRef InlineAsmVal) {

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20276,9 +20276,9 @@ bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const {
2027620276
SplitString(AsmStr, AsmPieces, " \t,");
2027720277

2027820278
// rev $0, $1
20279-
if (AsmPieces.size() == 3 &&
20280-
AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" &&
20281-
IA->getConstraintString().compare(0, 4, "=l,l") == 0) {
20279+
if (AsmPieces.size() == 3 && AsmPieces[0] == "rev" &&
20280+
AsmPieces[1] == "$0" && AsmPieces[2] == "$1" &&
20281+
IA->getConstraintString().starts_with("=l,l")) {
2028220282
IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
2028320283
if (Ty && Ty->getBitWidth() == 32)
2028420284
return IntrinsicLowering::LowerToByteSwap(CI);

llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ void DXILBitcodeWriter::writeConstants(unsigned FirstVal, unsigned LastVal,
19791979
Record.append(AsmStr.begin(), AsmStr.end());
19801980

19811981
// Add the constraint string.
1982-
const std::string &ConstraintStr = IA->getConstraintString();
1982+
StringRef ConstraintStr = IA->getConstraintString();
19831983
Record.push_back(ConstraintStr.size());
19841984
Record.append(ConstraintStr.begin(), ConstraintStr.end());
19851985
Stream.EmitRecord(bitc::CST_CODE_INLINEASM, Record);

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60860,7 +60860,7 @@ bool X86TargetLowering::ExpandInlineAsm(CallInst *CI) const {
6086060860

6086160861
// rorw $$8, ${0:w} --> llvm.bswap.i16
6086260862
if (CI->getType()->isIntegerTy(16) &&
60863-
IA->getConstraintString().compare(0, 5, "=r,0,") == 0 &&
60863+
IA->getConstraintString().starts_with("=r,0,") &&
6086460864
(matchAsm(AsmPieces[0], {"rorw", "$$8,", "${0:w}"}) ||
6086560865
matchAsm(AsmPieces[0], {"rolw", "$$8,", "${0:w}"}))) {
6086660866
AsmPieces.clear();
@@ -60873,7 +60873,7 @@ bool X86TargetLowering::ExpandInlineAsm(CallInst *CI) const {
6087360873
break;
6087460874
case 3:
6087560875
if (CI->getType()->isIntegerTy(32) &&
60876-
IA->getConstraintString().compare(0, 5, "=r,0,") == 0 &&
60876+
IA->getConstraintString().starts_with("=r,0,") &&
6087760877
matchAsm(AsmPieces[0], {"rorw", "$$8,", "${0:w}"}) &&
6087860878
matchAsm(AsmPieces[1], {"rorl", "$$16,", "$0"}) &&
6087960879
matchAsm(AsmPieces[2], {"rorw", "$$8,", "${0:w}"})) {

0 commit comments

Comments
 (0)