[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.
This commit is contained in:
@@ -84,7 +84,7 @@ public:
|
||||
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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
@@ -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}"})) {
|
||||
|
||||
Reference in New Issue
Block a user