LLVM  8.0.1
GISelWorkList.h
Go to the documentation of this file.
1 //===- GISelWorkList.h - Worklist for GISel passes ----*- 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_GISEL_WORKLIST_H
11 #define LLVM_GISEL_WORKLIST_H
12 
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/SmallVector.h"
17 #include "llvm/Support/Debug.h"
18 
19 namespace llvm {
20 
21 class MachineInstr;
22 class MachineFunction;
23 
24 // Worklist which mostly works similar to InstCombineWorkList, but on
25 // MachineInstrs. The main difference with something like a SetVector is that
26 // erasing an element doesn't move all elements over one place - instead just
27 // nulls out the element of the vector.
28 //
29 // FIXME: Does it make sense to factor out common code with the
30 // instcombinerWorkList?
31 template<unsigned N>
35 
36 public:
38 
39  bool empty() const { return WorklistMap.empty(); }
40 
41  unsigned size() const { return WorklistMap.size(); }
42 
43  /// Add the specified instruction to the worklist if it isn't already in it.
45  if (WorklistMap.try_emplace(I, Worklist.size()).second)
46  Worklist.push_back(I);
47  }
48 
49  /// Remove I from the worklist if it exists.
50  void remove(const MachineInstr *I) {
51  auto It = WorklistMap.find(I);
52  if (It == WorklistMap.end()) return; // Not in worklist.
53 
54  // Don't bother moving everything down, just null out the slot.
55  Worklist[It->second] = nullptr;
56 
57  WorklistMap.erase(It);
58  }
59 
60  void clear() {
61  Worklist.clear();
62  WorklistMap.clear();
63  }
64 
66  MachineInstr *I;
67  do {
68  I = Worklist.pop_back_val();
69  } while(!I);
70  assert(I && "Pop back on empty worklist");
71  WorklistMap.erase(I);
72  return I;
73  }
74 };
75 
76 } // end namespace llvm.
77 
78 #endif
This class represents lattice values for constants.
Definition: AllocatorList.h:24
bool empty() const
Definition: GISelWorkList.h:39
unsigned second
size_t size() const
Definition: SmallVector.h:53
unsigned size() const
Definition: GISelWorkList.h:41
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:381
MachineInstr * pop_back_val()
Definition: GISelWorkList.h:65
void insert(MachineInstr *I)
Add the specified instruction to the worklist if it isn&#39;t already in it.
Definition: GISelWorkList.h:44
Representation of each machine instruction.
Definition: MachineInstr.h:64
#define I(x, y, z)
Definition: MD5.cpp:58
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())