diff --git a/llvm/utils/TableGen/CodeGenInstruction.cpp b/llvm/utils/TableGen/CodeGenInstruction.cpp index 960fe08677f78..3933ce6e1106c 100644 --- a/llvm/utils/TableGen/CodeGenInstruction.cpp +++ b/llvm/utils/TableGen/CodeGenInstruction.cpp @@ -177,17 +177,17 @@ bool CGIOperandList::hasOperandNamed(StringRef Name, unsigned &OpIdx) const { } std::pair -CGIOperandList::ParseOperandName(const std::string &Op, bool AllowWholeOp) { +CGIOperandList::ParseOperandName(StringRef Op, bool AllowWholeOp) { if (Op.empty() || Op[0] != '$') PrintFatalError(TheDef->getLoc(), TheDef->getName() + ": Illegal operand name: '" + Op + "'"); - std::string OpName = Op.substr(1); - std::string SubOpName; + StringRef OpName = Op.substr(1); + StringRef SubOpName; // Check to see if this is $foo.bar. - std::string::size_type DotIdx = OpName.find_first_of('.'); - if (DotIdx != std::string::npos) { + StringRef::size_type DotIdx = OpName.find_first_of('.'); + if (DotIdx != StringRef::npos) { SubOpName = OpName.substr(DotIdx+1); if (SubOpName.empty()) PrintFatalError(TheDef->getLoc(), @@ -231,16 +231,16 @@ CGIOperandList::ParseOperandName(const std::string &Op, bool AllowWholeOp) { return std::make_pair(0U, 0U); } -static void ParseConstraint(const std::string &CStr, CGIOperandList &Ops, +static void ParseConstraint(StringRef CStr, CGIOperandList &Ops, Record *Rec) { // EARLY_CLOBBER: @early $reg - std::string::size_type wpos = CStr.find_first_of(" \t"); - std::string::size_type start = CStr.find_first_not_of(" \t"); - std::string Tok = CStr.substr(start, wpos - start); + StringRef::size_type wpos = CStr.find_first_of(" \t"); + StringRef::size_type start = CStr.find_first_not_of(" \t"); + StringRef Tok = CStr.substr(start, wpos - start); if (Tok == "@earlyclobber") { - std::string Name = CStr.substr(wpos+1); + StringRef Name = CStr.substr(wpos+1); wpos = Name.find_first_not_of(" \t"); - if (wpos == std::string::npos) + if (wpos == StringRef::npos) PrintFatalError( Rec->getLoc(), "Illegal format for @earlyclobber constraint in '" + Rec->getName() + "': '" + CStr + "'"); @@ -258,8 +258,8 @@ static void ParseConstraint(const std::string &CStr, CGIOperandList &Ops, } // Only other constraint is "TIED_TO" for now. - std::string::size_type pos = CStr.find_first_of('='); - if (pos == std::string::npos) + StringRef::size_type pos = CStr.find_first_of('='); + if (pos == StringRef::npos) PrintFatalError( Rec->getLoc(), "Unrecognized constraint '" + CStr + "' in '" + Rec->getName() + "'"); @@ -267,20 +267,19 @@ static void ParseConstraint(const std::string &CStr, CGIOperandList &Ops, // TIED_TO: $src1 = $dst wpos = CStr.find_first_of(" \t", start); - if (wpos == std::string::npos || wpos > pos) + if (wpos == StringRef::npos || wpos > pos) PrintFatalError( Rec->getLoc(), "Illegal format for tied-to constraint in '" + Rec->getName() + "': '" + CStr + "'"); - std::string LHSOpName = - std::string(StringRef(CStr).substr(start, wpos - start)); + StringRef LHSOpName = CStr.substr(start, wpos - start); std::pair LHSOp = Ops.ParseOperandName(LHSOpName, false); wpos = CStr.find_first_not_of(" \t", pos + 1); - if (wpos == std::string::npos) + if (wpos == StringRef::npos) PrintFatalError( Rec->getLoc(), "Illegal format for tied-to constraint: '" + CStr + "'"); - std::string RHSOpName = std::string(StringRef(CStr).substr(wpos)); + StringRef RHSOpName = CStr.substr(wpos); std::pair RHSOp = Ops.ParseOperandName(RHSOpName, false); // Sort the operands into order, which should put the output one @@ -325,29 +324,27 @@ static void ParseConstraint(const std::string &CStr, CGIOperandList &Ops, Ops[SrcOp.first].Constraints[SrcOp.second] = NewConstraint; } -static void ParseConstraints(const std::string &CStr, CGIOperandList &Ops, - Record *Rec) { +static void ParseConstraints(StringRef CStr, CGIOperandList &Ops, Record *Rec) { if (CStr.empty()) return; - const std::string delims(","); - std::string::size_type bidx, eidx; + StringRef delims(","); + StringRef::size_type bidx, eidx; bidx = CStr.find_first_not_of(delims); - while (bidx != std::string::npos) { + while (bidx != StringRef::npos) { eidx = CStr.find_first_of(delims, bidx); - if (eidx == std::string::npos) - eidx = CStr.length(); + if (eidx == StringRef::npos) + eidx = CStr.size(); ParseConstraint(CStr.substr(bidx, eidx - bidx), Ops, Rec); bidx = CStr.find_first_not_of(delims, eidx); } } -void CGIOperandList::ProcessDisableEncoding(std::string DisableEncoding) { +void CGIOperandList::ProcessDisableEncoding(StringRef DisableEncoding) { while (1) { - std::pair P = getToken(DisableEncoding, " ,\t"); - std::string OpName = std::string(P.first); - DisableEncoding = std::string(P.second); + StringRef OpName; + std::tie(OpName, DisableEncoding) = getToken(DisableEncoding, " ,\t"); if (OpName.empty()) break; // Figure out which operand this is. @@ -427,12 +424,11 @@ CodeGenInstruction::CodeGenInstruction(Record *R) hasChain_Inferred = false; // Parse Constraints. - ParseConstraints(std::string(R->getValueAsString("Constraints")), Operands, - R); + ParseConstraints(R->getValueAsString("Constraints"), Operands, R); // Parse the DisableEncoding field. Operands.ProcessDisableEncoding( - std::string(R->getValueAsString("DisableEncoding"))); + R->getValueAsString("DisableEncoding")); // First check for a ComplexDeprecationPredicate. if (R->getValue("ComplexDeprecationPredicate")) { diff --git a/llvm/utils/TableGen/CodeGenInstruction.h b/llvm/utils/TableGen/CodeGenInstruction.h index af851a11676b1..e35d2191ea458 100644 --- a/llvm/utils/TableGen/CodeGenInstruction.h +++ b/llvm/utils/TableGen/CodeGenInstruction.h @@ -182,7 +182,7 @@ template class ArrayRef; /// where $foo is a whole operand and $foo.bar refers to a suboperand. /// This aborts if the name is invalid. If AllowWholeOp is true, references /// to operands with suboperands are allowed, otherwise not. - std::pair ParseOperandName(const std::string &Op, + std::pair ParseOperandName(StringRef Op, bool AllowWholeOp = true); /// getFlattenedOperandNumber - Flatten a operand/suboperand pair into a @@ -211,7 +211,7 @@ template class ArrayRef; return false; } - void ProcessDisableEncoding(std::string Value); + void ProcessDisableEncoding(StringRef Value); };