LCOV - code coverage report
Current view: top level - include/llvm/Transforms/InstCombine - InstCombineWorklist.h (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 31 31 100.0 %
Date: 2017-09-14 15:23:50 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- InstCombineWorklist.h - Worklist for InstCombine pass ----*- 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             : #ifndef LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINEWORKLIST_H
      11             : #define LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINEWORKLIST_H
      12             : 
      13             : #include "llvm/ADT/DenseMap.h"
      14             : #include "llvm/ADT/STLExtras.h"
      15             : #include "llvm/ADT/SmallVector.h"
      16             : #include "llvm/IR/Instruction.h"
      17             : #include "llvm/Support/Compiler.h"
      18             : #include "llvm/Support/Debug.h"
      19             : #include "llvm/Support/raw_ostream.h"
      20             : 
      21             : #define DEBUG_TYPE "instcombine"
      22             : 
      23             : namespace llvm {
      24             : 
      25             : /// InstCombineWorklist - This is the worklist management logic for
      26             : /// InstCombine.
      27       31086 : class InstCombineWorklist {
      28             :   SmallVector<Instruction*, 256> Worklist;
      29             :   DenseMap<Instruction*, unsigned> WorklistMap;
      30             : 
      31             : public:
      32       28428 :   InstCombineWorklist() = default;
      33             : 
      34        2658 :   InstCombineWorklist(InstCombineWorklist &&) = default;
      35             :   InstCombineWorklist &operator=(InstCombineWorklist &&) = default;
      36             : 
      37    19468732 :   bool isEmpty() const { return Worklist.empty(); }
      38             : 
      39             :   /// Add - Add the specified instruction to the worklist if it isn't already
      40             :   /// in it.
      41      960366 :   void Add(Instruction *I) {
      42     4801830 :     if (WorklistMap.insert(std::make_pair(I, Worklist.size())).second) {
      43             :       DEBUG(dbgs() << "IC: ADD: " << *I << '\n');
      44      670649 :       Worklist.push_back(I);
      45             :     }
      46      960366 :   }
      47             : 
      48             :   void AddValue(Value *V) {
      49           5 :     if (Instruction *I = dyn_cast<Instruction>(V))
      50           5 :       Add(I);
      51             :   }
      52             : 
      53             :   /// AddInitialGroup - Add the specified batch of stuff in reverse order.
      54             :   /// which should only be done when the worklist is empty and when the group
      55             :   /// has no duplicates.
      56      253942 :   void AddInitialGroup(ArrayRef<Instruction *> List) {
      57             :     assert(Worklist.empty() && "Worklist must be empty to add initial group");
      58      253942 :     Worklist.reserve(List.size()+16);
      59      253942 :     WorklistMap.reserve(List.size());
      60             :     DEBUG(dbgs() << "IC: ADDING: " << List.size() << " instrs to worklist\n");
      61      253942 :     unsigned Idx = 0;
      62    38104050 :     for (Instruction *I : reverse(List)) {
      63    55632423 :       WorklistMap.insert(std::make_pair(I, Idx++));
      64    18544141 :       Worklist.push_back(I);
      65             :     }
      66      253942 :   }
      67             : 
      68             :   // Remove - remove I from the worklist if it exists.
      69      178516 :   void Remove(Instruction *I) {
      70      178516 :     DenseMap<Instruction*, unsigned>::iterator It = WorklistMap.find(I);
      71      705635 :     if (It == WorklistMap.end()) return; // Not in worklist.
      72             : 
      73             :     // Don't bother moving everything down, just null out the slot.
      74       16858 :     Worklist[It->second] = nullptr;
      75             : 
      76       16858 :     WorklistMap.erase(It);
      77             :   }
      78             : 
      79             :   Instruction *RemoveOne() {
      80    38429580 :     Instruction *I = Worklist.pop_back_val();
      81    19214790 :     WorklistMap.erase(I);
      82    19214790 :     return I;
      83             :   }
      84             : 
      85             :   /// AddUsersToWorkList - When an instruction is simplified, add all users of
      86             :   /// the instruction to the work lists because they might get more simplified
      87             :   /// now.
      88             :   ///
      89      363363 :   void AddUsersToWorkList(Instruction &I) {
      90     1672143 :     for (User *U : I.users())
      91      291027 :       Add(cast<Instruction>(U));
      92      363363 :   }
      93             : 
      94             : 
      95             :   /// Zap - check that the worklist is empty and nuke the backing store for
      96             :   /// the map if it is large.
      97             :   void Zap() {
      98             :     assert(WorklistMap.empty() && "Worklist empty, but map not?");
      99             : 
     100             :     // Do an explicit clear, this shrinks the map if needed.
     101      253942 :     WorklistMap.clear();
     102             :   }
     103             : };
     104             : 
     105             : } // end namespace llvm.
     106             : 
     107             : #undef DEBUG_TYPE
     108             : 
     109             : #endif

Generated by: LCOV version 1.13