Skip to content

Commit

Permalink
[TableGen] Fix negation of simple predicates
Browse files Browse the repository at this point in the history
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

llvm-svn: 348034
  • Loading branch information
Evandro Menezes committed Nov 30, 2018
1 parent 3b6fb6e commit 58e94f9
Showing 1 changed file with 41 additions and 14 deletions.
55 changes: 41 additions & 14 deletions llvm/utils/TableGen/PredicateExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -53,16 +68,29 @@ 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())
OS << Str << "::";
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
Expand Down Expand Up @@ -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"));
Expand All @@ -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"),
Expand Down

0 comments on commit 58e94f9

Please sign in to comment.