[PATCH] D67167: [MachinePipeliner] Improve the TargetInstrInfo API analyzeLoop/reduceLoopCount

James Molloy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 06:27:07 PDT 2019


jmolloy created this revision.
jmolloy added reviewers: bcahoon, jsji, ThomasRaoux.
Herald added subscribers: llvm-commits, MaskRay, kbarton, hiraditya, nemanjai.
Herald added a project: LLVM.

The way MachinePipeliner uses these target hooks is stateful - we reduce trip
count by one per call to reduceLoopCount. It's a little overfit for hardware
loops, where we don't have to worry about stitching a loop induction variable
across prologs and epilogs (the induction variable is implicit).

This patch introduces a new API:

  /// Analyze loop L, which must be a single-basic-block loop, and if the
  /// conditions can be understood enough produce a PipelinerLoopInfo object.
  virtual std::unique_ptr<PipelinerLoopInfo>
  analyzeLoopForPipelining(MachineBasicBlock *LoopBB) const;

The return value is expected to be an implementation of the abstract class:

  /// Object returned by analyzeLoopForPipelining. Allows software pipelining
  /// implementations to query attributes of the loop being pipelined.
  class PipelinerLoopInfo {
  public:
    virtual ~PipelinerLoopInfo();
    /// Return true if the given instruction should not be pipelined and should
    /// be ignored. An example could be a loop comparison, or induction variable
    /// update with no users being pipelined.
    virtual bool shouldIgnoreForPipelining(const MachineInstr *MI) const = 0;
  
    /// Create a condition to determine if the trip count of the loop is greater
    /// than TC.
    ///
    /// If the trip count is statically known to be greater than TC, return
    /// true. If the trip count is statically known to be not greater than TC,
    /// return false. Otherwise return nullopt and fill out Cond with the test
    /// condition.
    virtual Optional<bool>
    getTripCountGreaterCondition(int TC, MachineBasicBlock &MBB,
                                 SmallVectorImpl<MachineOperand> &Cond) = 0;
  
    /// Modify the loop such that the trip count is
    /// OriginalTC + TripCountAdjust.
    /// Additionally the loop's preheader is now NewPreheader.
    virtual void adjust(int TripCountAdjust,
                        MachineBasicBlock *NewPreheader) = 0;
  
    /// Called when the loop is being removed. Any instructions in the preheader
    /// should be removed.
    virtual void disposed() = 0;
  };

The Pipeliner (ModuloSchedule.cpp) can use this object to modify the loop while
allowing the target to hold its own state across all calls. This API, in
particular the disjunction of creating a trip count check condition and
adjusting the loop, improves the code quality in ModuloSchedule.cpp.


Repository:
  rL LLVM

https://reviews.llvm.org/D67167

Files:
  llvm/include/llvm/CodeGen/TargetInstrInfo.h
  llvm/lib/CodeGen/MachinePipeliner.cpp
  llvm/lib/CodeGen/ModuloSchedule.cpp
  llvm/lib/CodeGen/TargetInstrInfo.cpp
  llvm/lib/Target/Hexagon/HexagonInstrInfo.cpp
  llvm/lib/Target/Hexagon/HexagonInstrInfo.h
  llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
  llvm/lib/Target/PowerPC/PPCInstrInfo.h
  llvm/test/CodeGen/Hexagon/swp-epilog-phi7.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67167.218678.patch
Type: text/x-patch
Size: 24957 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190904/df527f3c/attachment.bin>


More information about the llvm-commits mailing list