Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 5f1a766

Browse files
author
Evandro Menezes
committed
[TableGen] Fix negation of simple predicates
Simple predicates, such as those defined by `CheckRegOperandSimple` or `CheckImmOperandSimple`, were not being negated when used with `CheckNot`. This change fixes this issue by defining the previously declared methods to handle simple predicates. Differential revision: https://reviews.llvm.org/D55089 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348034 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c446570 commit 5f1a766

File tree

1 file changed

+41
-14
lines changed

1 file changed

+41
-14
lines changed

utils/TableGen/PredicateExpander.cpp

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,39 @@ void PredicateExpander::expandCheckImmOperand(raw_ostream &OS, int OpIndex,
2626
OS << FunctionMapper << "(";
2727
OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
2828
<< ").getImm()";
29-
OS << (FunctionMapper.empty() ? " " : ") ");
30-
OS << (shouldNegate() ? "!= " : "== ") << ImmVal;
29+
if (!FunctionMapper.empty())
30+
OS << ")";
31+
OS << (shouldNegate() ? " != " : " == ") << ImmVal;
3132
}
3233

3334
void PredicateExpander::expandCheckImmOperand(raw_ostream &OS, int OpIndex,
3435
StringRef ImmVal,
3536
StringRef FunctionMapper) {
37+
if (ImmVal.empty())
38+
expandCheckImmOperandSimple(OS, OpIndex, FunctionMapper);
39+
3640
if (!FunctionMapper.empty())
3741
OS << FunctionMapper << "(";
3842
OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
3943
<< ").getImm()";
40-
41-
OS << (FunctionMapper.empty() ? "" : ")");
42-
if (ImmVal.empty())
43-
return;
44+
if (!FunctionMapper.empty())
45+
OS << ")";
4446
OS << (shouldNegate() ? " != " : " == ") << ImmVal;
4547
}
4648

49+
void PredicateExpander::expandCheckImmOperandSimple(raw_ostream &OS,
50+
int OpIndex,
51+
StringRef FunctionMapper) {
52+
if (shouldNegate())
53+
OS << "!";
54+
if (!FunctionMapper.empty())
55+
OS << FunctionMapper << "(";
56+
OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
57+
<< ").getImm()";
58+
if (!FunctionMapper.empty())
59+
OS << ")";
60+
}
61+
4762
void PredicateExpander::expandCheckRegOperand(raw_ostream &OS, int OpIndex,
4863
const Record *Reg,
4964
StringRef FunctionMapper) {
@@ -53,16 +68,29 @@ void PredicateExpander::expandCheckRegOperand(raw_ostream &OS, int OpIndex,
5368
OS << FunctionMapper << "(";
5469
OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
5570
<< ").getReg()";
56-
OS << (FunctionMapper.empty() ? "" : ")");
57-
if (!Reg)
58-
return;
71+
if (!FunctionMapper.empty())
72+
OS << ")";
5973
OS << (shouldNegate() ? " != " : " == ");
6074
const StringRef Str = Reg->getValueAsString("Namespace");
6175
if (!Str.empty())
6276
OS << Str << "::";
6377
OS << Reg->getName();
6478
}
6579

80+
81+
void PredicateExpander::expandCheckRegOperandSimple(raw_ostream &OS,
82+
int OpIndex,
83+
StringRef FunctionMapper) {
84+
if (shouldNegate())
85+
OS << "!";
86+
if (!FunctionMapper.empty())
87+
OS << FunctionMapper << "(";
88+
OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
89+
<< ").getReg()";
90+
if (!FunctionMapper.empty())
91+
OS << ")";
92+
}
93+
6694
void PredicateExpander::expandCheckInvalidRegOperand(raw_ostream &OS,
6795
int OpIndex) {
6896
OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
@@ -290,9 +318,8 @@ void PredicateExpander::expandPredicate(raw_ostream &OS, const Record *Rec) {
290318
Rec->getValueAsString("FunctionMapper"));
291319

292320
if (Rec->isSubClassOf("CheckRegOperandSimple"))
293-
return expandCheckRegOperand(OS, Rec->getValueAsInt("OpIndex"),
294-
nullptr,
295-
Rec->getValueAsString("FunctionMapper"));
321+
return expandCheckRegOperandSimple(OS, Rec->getValueAsInt("OpIndex"),
322+
Rec->getValueAsString("FunctionMapper"));
296323

297324
if (Rec->isSubClassOf("CheckInvalidRegOperand"))
298325
return expandCheckInvalidRegOperand(OS, Rec->getValueAsInt("OpIndex"));
@@ -308,8 +335,8 @@ void PredicateExpander::expandPredicate(raw_ostream &OS, const Record *Rec) {
308335
Rec->getValueAsString("FunctionMapper"));
309336

310337
if (Rec->isSubClassOf("CheckImmOperandSimple"))
311-
return expandCheckImmOperand(OS, Rec->getValueAsInt("OpIndex"), "",
312-
Rec->getValueAsString("FunctionMapper"));
338+
return expandCheckImmOperandSimple(OS, Rec->getValueAsInt("OpIndex"),
339+
Rec->getValueAsString("FunctionMapper"));
313340

314341
if (Rec->isSubClassOf("CheckSameRegOperand"))
315342
return expandCheckSameRegOperand(OS, Rec->getValueAsInt("FirstIndex"),

0 commit comments

Comments
 (0)