summaryrefslogtreecommitdiffstats
path: root/llvm/utils/TableGen/PredicateExpander.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/utils/TableGen/PredicateExpander.cpp')
-rw-r--r--llvm/utils/TableGen/PredicateExpander.cpp55
1 files changed, 41 insertions, 14 deletions
diff --git a/llvm/utils/TableGen/PredicateExpander.cpp b/llvm/utils/TableGen/PredicateExpander.cpp
index 4af544e6e25..2e01b7c3138 100644
--- a/llvm/utils/TableGen/PredicateExpander.cpp
+++ b/llvm/utils/TableGen/PredicateExpander.cpp
@@ -26,24 +26,39 @@ void PredicateExpander::expandCheckImmOperand(raw_ostream &OS, int OpIndex,
OS << FunctionMapper << "(";
OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
<< ").getImm()";
- OS << (FunctionMapper.empty() ? " " : ") ");
- OS << (shouldNegate() ? "!= " : "== ") << ImmVal;
+ if (!FunctionMapper.empty())
+ OS << ")";
+ OS << (shouldNegate() ? " != " : " == ") << ImmVal;
}
void PredicateExpander::expandCheckImmOperand(raw_ostream &OS, int OpIndex,
StringRef ImmVal,
StringRef FunctionMapper) {
+ if (ImmVal.empty())
+ expandCheckImmOperandSimple(OS, OpIndex, FunctionMapper);
+
if (!FunctionMapper.empty())
OS << FunctionMapper << "(";
OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
<< ").getImm()";
-
- OS << (FunctionMapper.empty() ? "" : ")");
- if (ImmVal.empty())
- return;
+ if (!FunctionMapper.empty())
+ OS << ")";
OS << (shouldNegate() ? " != " : " == ") << ImmVal;
}
+void PredicateExpander::expandCheckImmOperandSimple(raw_ostream &OS,
+ int OpIndex,
+ StringRef FunctionMapper) {
+ if (shouldNegate())
+ OS << "!";
+ if (!FunctionMapper.empty())
+ OS << FunctionMapper << "(";
+ OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
+ << ").getImm()";
+ if (!FunctionMapper.empty())
+ OS << ")";
+}
+
void PredicateExpander::expandCheckRegOperand(raw_ostream &OS, int OpIndex,
const Record *Reg,
StringRef FunctionMapper) {
@@ -53,9 +68,8 @@ void PredicateExpander::expandCheckRegOperand(raw_ostream &OS, int OpIndex,
OS << FunctionMapper << "(";
OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
<< ").getReg()";
- OS << (FunctionMapper.empty() ? "" : ")");
- if (!Reg)
- return;
+ if (!FunctionMapper.empty())
+ OS << ")";
OS << (shouldNegate() ? " != " : " == ");
const StringRef Str = Reg->getValueAsString("Namespace");
if (!Str.empty())
@@ -63,6 +77,20 @@ void PredicateExpander::expandCheckRegOperand(raw_ostream &OS, int OpIndex,
OS << Reg->getName();
}
+
+void PredicateExpander::expandCheckRegOperandSimple(raw_ostream &OS,
+ int OpIndex,
+ StringRef FunctionMapper) {
+ if (shouldNegate())
+ OS << "!";
+ if (!FunctionMapper.empty())
+ OS << FunctionMapper << "(";
+ OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
+ << ").getReg()";
+ if (!FunctionMapper.empty())
+ OS << ")";
+}
+
void PredicateExpander::expandCheckInvalidRegOperand(raw_ostream &OS,
int OpIndex) {
OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
@@ -290,9 +318,8 @@ void PredicateExpander::expandPredicate(raw_ostream &OS, const Record *Rec) {
Rec->getValueAsString("FunctionMapper"));
if (Rec->isSubClassOf("CheckRegOperandSimple"))
- return expandCheckRegOperand(OS, Rec->getValueAsInt("OpIndex"),
- nullptr,
- Rec->getValueAsString("FunctionMapper"));
+ return expandCheckRegOperandSimple(OS, Rec->getValueAsInt("OpIndex"),
+ Rec->getValueAsString("FunctionMapper"));
if (Rec->isSubClassOf("CheckInvalidRegOperand"))
return expandCheckInvalidRegOperand(OS, Rec->getValueAsInt("OpIndex"));
@@ -308,8 +335,8 @@ void PredicateExpander::expandPredicate(raw_ostream &OS, const Record *Rec) {
Rec->getValueAsString("FunctionMapper"));
if (Rec->isSubClassOf("CheckImmOperandSimple"))
- return expandCheckImmOperand(OS, Rec->getValueAsInt("OpIndex"), "",
- Rec->getValueAsString("FunctionMapper"));
+ return expandCheckImmOperandSimple(OS, Rec->getValueAsInt("OpIndex"),
+ Rec->getValueAsString("FunctionMapper"));
if (Rec->isSubClassOf("CheckSameRegOperand"))
return expandCheckSameRegOperand(OS, Rec->getValueAsInt("FirstIndex"),
OpenPOWER on IntegriCloud