This is an archive of the discontinued LLVM Phabricator instance.

[Tablegen][SubtargetEmitter] Improve expansion of predicates of a variant scheduling class.
ClosedPublic

Authored by andreadb on Aug 10 2018, 9:55 AM.

Details

Summary

This patch refactors the logic that expands predicates of a variant scheduling class.

The idea is to improve the readability of the auto-generated code by removing redundant parentheses around predicate expressions, and by removing redundant if(true) statements.

This patch replaces the definition of NoSchedPred in TargetSchedule.td with an instance of MCSchedPredicate. The new definition is sematically equivalent to the previous one. The main difference is that now SubtargetEmitter knows that it represents predicate "true".

Before this patch, we always generated an if (true) for the default transition of a variant scheduling class.

Example (taken from AArch64GenSubtargetInfo.inc) :

if (SchedModel->getProcessorID() == 3) { // CycloneModel
  if ((TII->isScaledAddr(*MI)))
    return 927; // (WriteIS_WriteLD)_ReadBaseRS
  if ((true))
    return 928; // WriteLD_ReadDefault
}

Extra parentheses were also generated around the predicate expressions.

With this patch, we get this:

if (SchedModel->getProcessorID() == 3) { // CycloneModel
  if (TII->isScaledAddr(*MI))
    return 927; // (WriteIS_WriteLD)_ReadBaseRS
  return 928; // WriteLD_ReadDefault
}

The new auto-generated code behaves exactly the same as before. So, technically this is a NFC(I).

Please let me know if okay to commit.

-Andrea

Diff Detail

Repository
rL LLVM

Event Timeline

andreadb created this revision.Aug 10 2018, 9:55 AM
craig.topper accepted this revision.Aug 11 2018, 10:52 PM

LGTM

utils/TableGen/SubtargetEmitter.cpp
1487 ↗(On Diff #160126)

Not related to this patch, but is formatted_raw_ostream really needed here? Can we use indent instead of PadToColumn? formatted_raw_ostream has to do internal tracking of column and thus scans every print for a new line character.

This revision is now accepted and ready to land.Aug 11 2018, 10:52 PM
andreadb added inline comments.Aug 13 2018, 4:02 AM
utils/TableGen/SubtargetEmitter.cpp
1487 ↗(On Diff #160126)

Good point.
We can definitely use PadToColumn in this function.
We can also change the PredicateExpander, so that method expandPredicate() doesn't require a formatted_raw_ostream.
I'll think about it and see if I can send it as a follow-up NFC patch.

Thanks!

This revision was automatically updated to reflect the committed changes.