summaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/CodeGenInstruction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/utils/TableGen/CodeGenInstruction.cpp')
-rw-r--r--llvm/utils/TableGen/CodeGenInstruction.cpp62
1 files changed, 37 insertions, 25 deletions
diff --git a/llvm/utils/TableGen/CodeGenInstruction.cpp b/llvm/utils/TableGen/CodeGenInstruction.cpp
index 6bb4dbb511b65..1df5902b081e1 100644
--- a/llvm/utils/TableGen/CodeGenInstruction.cpp
+++ b/llvm/utils/TableGen/CodeGenInstruction.cpp
@@ -56,6 +56,7 @@ CGIOperandList::CGIOperandList(Record *R) : TheDef(R) {
std::set<std::string> OperandNames;
unsigned e = InDI->getNumArgs() + OutDI->getNumArgs();
OperandList.reserve(e);
+ bool VariadicOuts = false;
for (unsigned i = 0; i != e; ++i){
Init *ArgInit;
StringRef ArgName;
@@ -80,16 +81,16 @@ CGIOperandList::CGIOperandList(Record *R) : TheDef(R) {
unsigned NumOps = 1;
DagInit *MIOpInfo = nullptr;
if (Rec->isSubClassOf("RegisterOperand")) {
- PrintMethod = Rec->getValueAsString("PrintMethod");
- OperandType = Rec->getValueAsString("OperandType");
- OperandNamespace = Rec->getValueAsString("OperandNamespace");
- EncoderMethod = Rec->getValueAsString("EncoderMethod");
+ PrintMethod = std::string(Rec->getValueAsString("PrintMethod"));
+ OperandType = std::string(Rec->getValueAsString("OperandType"));
+ OperandNamespace = std::string(Rec->getValueAsString("OperandNamespace"));
+ EncoderMethod = std::string(Rec->getValueAsString("EncoderMethod"));
} else if (Rec->isSubClassOf("Operand")) {
- PrintMethod = Rec->getValueAsString("PrintMethod");
- OperandType = Rec->getValueAsString("OperandType");
- OperandNamespace = Rec->getValueAsString("OperandNamespace");
+ PrintMethod = std::string(Rec->getValueAsString("PrintMethod"));
+ OperandType = std::string(Rec->getValueAsString("OperandType"));
+ OperandNamespace = std::string(Rec->getValueAsString("OperandNamespace"));
// If there is an explicit encoder method, use it.
- EncoderMethod = Rec->getValueAsString("EncoderMethod");
+ EncoderMethod = std::string(Rec->getValueAsString("EncoderMethod"));
MIOpInfo = Rec->getValueAsDag("MIOperandInfo");
// Verify that MIOpInfo has an 'ops' root value.
@@ -109,6 +110,8 @@ CGIOperandList::CGIOperandList(Record *R) : TheDef(R) {
else if (Rec->isSubClassOf("OptionalDefOperand"))
hasOptionalDef = true;
} else if (Rec->getName() == "variable_ops") {
+ if (i < NumDefs)
+ VariadicOuts = true;
isVariadic = true;
continue;
} else if (Rec->isSubClassOf("RegisterClass")) {
@@ -124,18 +127,21 @@ CGIOperandList::CGIOperandList(Record *R) : TheDef(R) {
PrintFatalError(R->getLoc(), "In instruction '" + R->getName() +
"', operand #" + Twine(i) +
" has no name!");
- if (!OperandNames.insert(ArgName).second)
+ if (!OperandNames.insert(std::string(ArgName)).second)
PrintFatalError(R->getLoc(),
"In instruction '" + R->getName() + "', operand #" +
Twine(i) +
" has the same name as a previous operand!");
- OperandList.emplace_back(Rec, ArgName, PrintMethod, EncoderMethod,
- OperandNamespace + "::" + OperandType, MIOperandNo,
- NumOps, MIOpInfo);
+ OperandList.emplace_back(
+ Rec, std::string(ArgName), std::string(PrintMethod),
+ std::string(EncoderMethod), OperandNamespace + "::" + OperandType,
+ MIOperandNo, NumOps, MIOpInfo);
MIOperandNo += NumOps;
}
+ if (VariadicOuts)
+ --NumDefs;
// Make sure the constraints list for each operand is large enough to hold
// constraint info, even if none is present.
@@ -265,7 +271,8 @@ static void ParseConstraint(const std::string &CStr, CGIOperandList &Ops,
PrintFatalError(
Rec->getLoc(), "Illegal format for tied-to constraint in '" +
Rec->getName() + "': '" + CStr + "'");
- std::string LHSOpName = StringRef(CStr).substr(start, wpos - start);
+ std::string LHSOpName =
+ std::string(StringRef(CStr).substr(start, wpos - start));
std::pair<unsigned,unsigned> LHSOp = Ops.ParseOperandName(LHSOpName, false);
wpos = CStr.find_first_not_of(" \t", pos + 1);
@@ -273,7 +280,7 @@ static void ParseConstraint(const std::string &CStr, CGIOperandList &Ops,
PrintFatalError(
Rec->getLoc(), "Illegal format for tied-to constraint: '" + CStr + "'");
- std::string RHSOpName = StringRef(CStr).substr(wpos);
+ std::string RHSOpName = std::string(StringRef(CStr).substr(wpos));
std::pair<unsigned,unsigned> RHSOp = Ops.ParseOperandName(RHSOpName, false);
// Sort the operands into order, which should put the output one
@@ -339,8 +346,8 @@ static void ParseConstraints(const std::string &CStr, CGIOperandList &Ops,
void CGIOperandList::ProcessDisableEncoding(std::string DisableEncoding) {
while (1) {
std::pair<StringRef, StringRef> P = getToken(DisableEncoding, " ,\t");
- std::string OpName = P.first;
- DisableEncoding = P.second;
+ std::string OpName = std::string(P.first);
+ DisableEncoding = std::string(P.second);
if (OpName.empty()) break;
// Figure out which operand this is.
@@ -361,7 +368,7 @@ void CGIOperandList::ProcessDisableEncoding(std::string DisableEncoding) {
CodeGenInstruction::CodeGenInstruction(Record *R)
: TheDef(R), Operands(R), InferredFrom(nullptr) {
Namespace = R->getValueAsString("Namespace");
- AsmString = R->getValueAsString("AsmString");
+ AsmString = std::string(R->getValueAsString("AsmString"));
isPreISelOpcode = R->getValueAsBit("isPreISelOpcode");
isReturn = R->getValueAsBit("isReturn");
@@ -420,15 +427,18 @@ CodeGenInstruction::CodeGenInstruction(Record *R)
hasChain_Inferred = false;
// Parse Constraints.
- ParseConstraints(R->getValueAsString("Constraints"), Operands, R);
+ ParseConstraints(std::string(R->getValueAsString("Constraints")), Operands,
+ R);
// Parse the DisableEncoding field.
- Operands.ProcessDisableEncoding(R->getValueAsString("DisableEncoding"));
+ Operands.ProcessDisableEncoding(
+ std::string(R->getValueAsString("DisableEncoding")));
// First check for a ComplexDeprecationPredicate.
if (R->getValue("ComplexDeprecationPredicate")) {
HasComplexDeprecationPredicate = true;
- DeprecatedReason = R->getValueAsString("ComplexDeprecationPredicate");
+ DeprecatedReason =
+ std::string(R->getValueAsString("ComplexDeprecationPredicate"));
} else if (RecordVal *Dep = R->getValue("DeprecatedFeatureMask")) {
// Check if we have a Subtarget feature mask.
HasComplexDeprecationPredicate = false;
@@ -541,7 +551,8 @@ bool CodeGenInstAlias::tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo,
if (!Result->getArgName(AliasOpNo))
PrintFatalError(Loc, "result argument #" + Twine(AliasOpNo) +
" must have a name!");
- ResOp = ResultOperand(Result->getArgNameStr(AliasOpNo), ResultRecord);
+ ResOp = ResultOperand(std::string(Result->getArgNameStr(AliasOpNo)),
+ ResultRecord);
return true;
}
@@ -559,7 +570,8 @@ bool CodeGenInstAlias::tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo,
if (!T.getRegisterClass(InstOpRec)
.hasSubClass(&T.getRegisterClass(ADI->getDef())))
return false;
- ResOp = ResultOperand(Result->getArgNameStr(AliasOpNo), ResultRecord);
+ ResOp = ResultOperand(std::string(Result->getArgNameStr(AliasOpNo)),
+ ResultRecord);
return true;
}
@@ -641,7 +653,8 @@ bool CodeGenInstAlias::tryAliasOpMatch(DagInit *Result, unsigned AliasOpNo,
// MIOperandInfo perhaps?
if (InstOpRec->getValueInit("Type") != ADI->getDef()->getValueInit("Type"))
return false;
- ResOp = ResultOperand(Result->getArgNameStr(AliasOpNo), ADI->getDef());
+ ResOp = ResultOperand(std::string(Result->getArgNameStr(AliasOpNo)),
+ ADI->getDef());
return true;
}
@@ -668,8 +681,7 @@ unsigned CodeGenInstAlias::ResultOperand::getMINumOperands() const {
CodeGenInstAlias::CodeGenInstAlias(Record *R, CodeGenTarget &T)
: TheDef(R) {
Result = R->getValueAsDag("ResultInst");
- AsmString = R->getValueAsString("AsmString");
-
+ AsmString = std::string(R->getValueAsString("AsmString"));
// Verify that the root of the result is an instruction.
DefInit *DI = dyn_cast<DefInit>(Result->getOperator());