LLVM  3.7.0
InstCombineWorklist.h
Go to the documentation of this file.
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/SmallVector.h"
15 #include "llvm/IR/Instruction.h"
16 #include "llvm/Support/Compiler.h"
17 #include "llvm/Support/Debug.h"
19 
20 #define DEBUG_TYPE "instcombine"
21 
22 namespace llvm {
23 
24 /// InstCombineWorklist - This is the worklist management logic for
25 /// InstCombine.
29 
30  void operator=(const InstCombineWorklist&RHS) = delete;
32 public:
34 
36  : Worklist(std::move(Arg.Worklist)),
37  WorklistMap(std::move(Arg.WorklistMap)) {}
39  Worklist = std::move(RHS.Worklist);
40  WorklistMap = std::move(RHS.WorklistMap);
41  return *this;
42  }
43 
44  bool isEmpty() const { return Worklist.empty(); }
45 
46  /// Add - Add the specified instruction to the worklist if it isn't already
47  /// in it.
48  void Add(Instruction *I) {
49  if (WorklistMap.insert(std::make_pair(I, Worklist.size())).second) {
50  DEBUG(dbgs() << "IC: ADD: " << *I << '\n');
51  Worklist.push_back(I);
52  }
53  }
54 
55  void AddValue(Value *V) {
56  if (Instruction *I = dyn_cast<Instruction>(V))
57  Add(I);
58  }
59 
60  /// AddInitialGroup - Add the specified batch of stuff in reverse order.
61  /// which should only be done when the worklist is empty and when the group
62  /// has no duplicates.
63  void AddInitialGroup(Instruction *const *List, unsigned NumEntries) {
64  assert(Worklist.empty() && "Worklist must be empty to add initial group");
65  Worklist.reserve(NumEntries+16);
66  WorklistMap.resize(NumEntries);
67  DEBUG(dbgs() << "IC: ADDING: " << NumEntries << " instrs to worklist\n");
68  for (unsigned Idx = 0; NumEntries; --NumEntries) {
69  Instruction *I = List[NumEntries-1];
70  WorklistMap.insert(std::make_pair(I, Idx++));
71  Worklist.push_back(I);
72  }
73  }
74 
75  // Remove - remove I from the worklist if it exists.
76  void Remove(Instruction *I) {
77  DenseMap<Instruction*, unsigned>::iterator It = WorklistMap.find(I);
78  if (It == WorklistMap.end()) return; // Not in worklist.
79 
80  // Don't bother moving everything down, just null out the slot.
81  Worklist[It->second] = nullptr;
82 
83  WorklistMap.erase(It);
84  }
85 
87  Instruction *I = Worklist.pop_back_val();
88  WorklistMap.erase(I);
89  return I;
90  }
91 
92  /// AddUsersToWorkList - When an instruction is simplified, add all users of
93  /// the instruction to the work lists because they might get more simplified
94  /// now.
95  ///
97  for (User *U : I.users())
98  Add(cast<Instruction>(U));
99  }
100 
101 
102  /// Zap - check that the worklist is empty and nuke the backing store for
103  /// the map if it is large.
104  void Zap() {
105  assert(WorklistMap.empty() && "Worklist empty, but map not?");
106 
107  // Do an explicit clear, this shrinks the map if needed.
108  WorklistMap.clear();
109  }
110 };
111 
112 } // end namespace llvm.
113 
114 #undef DEBUG_TYPE
115 
116 #endif
void Remove(Instruction *I)
void Add(Instruction *I)
Add - Add the specified instruction to the worklist if it isn't already in it.
InstCombineWorklist & operator=(InstCombineWorklist &&RHS)
InstCombineWorklist(InstCombineWorklist &&Arg)
void AddUsersToWorkList(Instruction &I)
AddUsersToWorkList - When an instruction is simplified, add all users of the instruction to the work ...
InstCombineWorklist - This is the worklist management logic for InstCombine.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:123
iterator_range< user_iterator > users()
Definition: Value.h:300
void AddInitialGroup(Instruction *const *List, unsigned NumEntries)
AddInitialGroup - Add the specified batch of stuff in reverse order.
#define I(x, y, z)
Definition: MD5.cpp:54
LLVM Value Representation.
Definition: Value.h:69
#define DEBUG(X)
Definition: Debug.h:92
void Zap()
Zap - check that the worklist is empty and nuke the backing store for the map if it is large...