LCOV - code coverage report
Current view: top level - lib/CodeGen - AntiDepBreaker.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 11 11 100.0 %
Date: 2017-09-14 15:23:50 Functions: 2 2 100.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/CodeGen/MachineBasicBlock.h"
      19             : #include "llvm/CodeGen/MachineFrameInfo.h"
      20             : #include "llvm/CodeGen/MachineFunction.h"
      21             : #include "llvm/CodeGen/MachineRegisterInfo.h"
      22             : #include "llvm/CodeGen/ScheduleDAG.h"
      23             : #include "llvm/Target/TargetRegisterInfo.h"
      24             : #include <vector>
      25             : 
      26             : namespace llvm {
      27             : 
      28             : /// This class works in conjunction with the post-RA scheduler to rename
      29             : /// registers to break register anti-dependencies (WAR hazards).
      30             : class LLVM_LIBRARY_VISIBILITY AntiDepBreaker {
      31             : public:
      32             :   typedef std::vector<std::pair<MachineInstr *, MachineInstr *> > 
      33             :     DbgValueVector;
      34             : 
      35             :   virtual ~AntiDepBreaker();
      36             : 
      37             :   /// Initialize anti-dep breaking for a new basic block.
      38             :   virtual void StartBlock(MachineBasicBlock *BB) =0;
      39             : 
      40             :   /// Identifiy anti-dependencies within a basic-block region and break them by
      41             :   /// renaming registers. Return the number of anti-dependencies broken.
      42             :   virtual unsigned BreakAntiDependencies(const std::vector<SUnit>& SUnits,
      43             :                                          MachineBasicBlock::iterator Begin,
      44             :                                          MachineBasicBlock::iterator End,
      45             :                                          unsigned InsertPosIndex,
      46             :                                          DbgValueVector &DbgValues) = 0;
      47             :   
      48             :   /// Update liveness information to account for the current
      49             :   /// instruction, which will not be scheduled.
      50             :   virtual void Observe(MachineInstr &MI, unsigned Count,
      51             :                        unsigned InsertPosIndex) = 0;
      52             : 
      53             :   /// Finish anti-dep breaking for a basic block.
      54             :   virtual void FinishBlock() =0;
      55             : 
      56             :   /// Update DBG_VALUE if dependency breaker is updating
      57             :   /// other machine instruction to use NewReg.
      58             :   void UpdateDbgValue(MachineInstr &MI, unsigned OldReg, unsigned NewReg) {
      59             :     assert(MI.isDebugValue() && "MI is not DBG_VALUE!");
      60           6 :     if (MI.getOperand(0).isReg() && MI.getOperand(0).getReg() == OldReg)
      61           2 :       MI.getOperand(0).setReg(NewReg);
      62             :   }
      63             : 
      64             :   /// Update all DBG_VALUE instructions that may be affected by the dependency
      65             :   /// breaker's update of ParentMI to use NewReg.
      66       81005 :   void UpdateDbgValues(const DbgValueVector &DbgValues, MachineInstr *ParentMI,
      67             :                        unsigned OldReg, unsigned NewReg) {
      68             :     // The following code is dependent on the order in which the DbgValues are
      69             :     // constructed in ScheduleDAGInstrs::buildSchedGraph.
      70       81005 :     MachineInstr *PrevDbgMI = nullptr;
      71      405195 :     for (const auto &DV : make_range(DbgValues.crbegin(), DbgValues.crend())) {
      72          85 :       MachineInstr *PrevMI = DV.second;
      73          85 :       if ((PrevMI == ParentMI) || (PrevMI == PrevDbgMI)) {
      74           3 :         MachineInstr *DbgMI = DV.first;
      75           3 :         UpdateDbgValue(*DbgMI, OldReg, NewReg);
      76             :         PrevDbgMI = DbgMI;
      77          82 :       } else if (PrevDbgMI) {
      78             :         break; // If no match and already found a DBG_VALUE, we're done.
      79             :       }
      80             :     }
      81       81005 :   }
      82             : };
      83             : 
      84             : }
      85             : 
      86             : #endif

Generated by: LCOV version 1.13