LCOV - code coverage report
Current view: top level - lib/CodeGen - AntiDepBreaker.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 9 11 81.8 %
Date: 2018-10-20 13:21:21 Functions: 1 2 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- llvm/CodeGen/AntiDepBreaker.h - Anti-Dependence Breaking -*- C++ -*-===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : // This file implements the AntiDepBreaker class, which implements
      11             : // anti-dependence breaking heuristics for post-register-allocation scheduling.
      12             : //
      13             : //===----------------------------------------------------------------------===//
      14             : 
      15             : #ifndef LLVM_LIB_CODEGEN_ANTIDEPBREAKER_H
      16             : #define LLVM_LIB_CODEGEN_ANTIDEPBREAKER_H
      17             : 
      18             : #include "llvm/ADT/iterator_range.h"
      19             : #include "llvm/CodeGen/MachineBasicBlock.h"
      20             : #include "llvm/CodeGen/MachineInstr.h"
      21             : #include "llvm/CodeGen/MachineOperand.h"
      22             : #include "llvm/CodeGen/ScheduleDAG.h"
      23             : #include "llvm/Support/Compiler.h"
      24             : #include <cassert>
      25             : #include <utility>
      26             : #include <vector>
      27             : 
      28             : namespace llvm {
      29             : 
      30             : /// This class works in conjunction with the post-RA scheduler to rename
      31             : /// registers to break register anti-dependencies (WAR hazards).
      32             : class LLVM_LIBRARY_VISIBILITY AntiDepBreaker {
      33             : public:
      34             :   using DbgValueVector =
      35             :       std::vector<std::pair<MachineInstr *, MachineInstr *>>;
      36             : 
      37             :   virtual ~AntiDepBreaker();
      38             : 
      39             :   /// Initialize anti-dep breaking for a new basic block.
      40             :   virtual void StartBlock(MachineBasicBlock *BB) = 0;
      41             : 
      42             :   /// Identifiy anti-dependencies within a basic-block region and break them by
      43             :   /// renaming registers. Return the number of anti-dependencies broken.
      44             :   virtual unsigned BreakAntiDependencies(const std::vector<SUnit> &SUnits,
      45             :                                          MachineBasicBlock::iterator Begin,
      46             :                                          MachineBasicBlock::iterator End,
      47             :                                          unsigned InsertPosIndex,
      48             :                                          DbgValueVector &DbgValues) = 0;
      49             : 
      50             :   /// Update liveness information to account for the current
      51             :   /// instruction, which will not be scheduled.
      52             :   virtual void Observe(MachineInstr &MI, unsigned Count,
      53             :                        unsigned InsertPosIndex) = 0;
      54             : 
      55             :   /// Finish anti-dep breaking for a basic block.
      56             :   virtual void FinishBlock() = 0;
      57             : 
      58             :   /// Update DBG_VALUE if dependency breaker is updating
      59             :   /// other machine instruction to use NewReg.
      60           0 :   void UpdateDbgValue(MachineInstr &MI, unsigned OldReg, unsigned NewReg) {
      61             :     assert(MI.isDebugValue() && "MI is not DBG_VALUE!");
      62           3 :     if (MI.getOperand(0).isReg() && MI.getOperand(0).getReg() == OldReg)
      63           2 :       MI.getOperand(0).setReg(NewReg);
      64           0 :   }
      65             : 
      66             :   /// Update all DBG_VALUE instructions that may be affected by the dependency
      67             :   /// breaker's update of ParentMI to use NewReg.
      68       96670 :   void UpdateDbgValues(const DbgValueVector &DbgValues, MachineInstr *ParentMI,
      69             :                        unsigned OldReg, unsigned NewReg) {
      70             :     // The following code is dependent on the order in which the DbgValues are
      71             :     // constructed in ScheduleDAGInstrs::buildSchedGraph.
      72             :     MachineInstr *PrevDbgMI = nullptr;
      73       96755 :     for (const auto &DV : make_range(DbgValues.crbegin(), DbgValues.crend())) {
      74          85 :       MachineInstr *PrevMI = DV.second;
      75          85 :       if ((PrevMI == ParentMI) || (PrevMI == PrevDbgMI)) {
      76           3 :         MachineInstr *DbgMI = DV.first;
      77             :         UpdateDbgValue(*DbgMI, OldReg, NewReg);
      78             :         PrevDbgMI = DbgMI;
      79          82 :       } else if (PrevDbgMI) {
      80             :         break; // If no match and already found a DBG_VALUE, we're done.
      81             :       }
      82             :     }
      83       96670 :   }
      84             : };
      85             : 
      86             : } // end namespace llvm
      87             : 
      88             : #endif // LLVM_LIB_CODEGEN_ANTIDEPBREAKER_H

Generated by: LCOV version 1.13