Skip to content

Commit

Permalink
TableGen: Only fold when some operand made resolve progress
Browse files Browse the repository at this point in the history
Summary:
Make sure that we always fold immediately, so there's no point in
attempting to re-fold when nothing changes.

Change-Id: I069e1989455b6f2ca8606152f6adc1a5e817f1c8

Reviewers: arsenm, craig.topper, tra, MartinO

Subscribers: wdng, llvm-commits

Differential Revision: https://reviews.llvm.org/D44198

llvm-svn: 327847
  • Loading branch information
nhaehnle committed Mar 19, 2018
1 parent a43af64 commit 335c70f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions llvm/lib/TableGen/Record.cpp
Expand Up @@ -765,7 +765,7 @@ Init *UnOpInit::resolveReferences(Resolver &R) const {
if (LHS != lhs)
return (UnOpInit::get(getOpcode(), lhs, getType()))
->Fold(R.getCurrentRecord());
return Fold(R.getCurrentRecord());
return const_cast<UnOpInit *>(this);
}

std::string UnOpInit::getAsString() const {
Expand Down Expand Up @@ -948,7 +948,7 @@ Init *BinOpInit::resolveReferences(Resolver &R) const {
if (LHS != lhs || RHS != rhs)
return (BinOpInit::get(getOpcode(), lhs, rhs, getType()))
->Fold(R.getCurrentRecord());
return Fold(R.getCurrentRecord());
return const_cast<BinOpInit *>(this);
}

std::string BinOpInit::getAsString() const {
Expand Down Expand Up @@ -1173,7 +1173,7 @@ Init *TernOpInit::resolveReferences(Resolver &R) const {
if (LHS != lhs || MHS != mhs || RHS != rhs)
return (TernOpInit::get(getOpcode(), lhs, mhs, rhs, getType()))
->Fold(R.getCurrentRecord());
return Fold(R.getCurrentRecord());
return const_cast<TernOpInit *>(this);
}

std::string TernOpInit::getAsString() const {
Expand Down
18 changes: 16 additions & 2 deletions llvm/lib/TableGen/TGParser.cpp
Expand Up @@ -1961,7 +1961,14 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
}

if (LHS->getType() != StringRecTy::get()) {
LHS = UnOpInit::get(UnOpInit::CAST, LHS, StringRecTy::get());
LHS = dyn_cast<TypedInit>(
UnOpInit::get(UnOpInit::CAST, LHS, StringRecTy::get())
->Fold(CurRec));
if (!LHS) {
Error(PasteLoc, Twine("can't cast '") + LHS->getAsString() +
"' to string");
return nullptr;
}
}

TypedInit *RHS = nullptr;
Expand All @@ -1988,7 +1995,14 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
}

if (RHS->getType() != StringRecTy::get()) {
RHS = UnOpInit::get(UnOpInit::CAST, RHS, StringRecTy::get());
RHS = dyn_cast<TypedInit>(
UnOpInit::get(UnOpInit::CAST, RHS, StringRecTy::get())
->Fold(CurRec));
if (!RHS) {
Error(PasteLoc, Twine("can't cast '") + RHS->getAsString() +
"' to string");
return nullptr;
}
}

break;
Expand Down

0 comments on commit 335c70f

Please sign in to comment.