Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h
Line
Count
Source
1
//===- InstCombineWorklist.h - Worklist for InstCombine pass ----*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINEWORKLIST_H
10
#define LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINEWORKLIST_H
11
12
#include "llvm/ADT/DenseMap.h"
13
#include "llvm/ADT/STLExtras.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"
18
#include "llvm/Support/raw_ostream.h"
19
20
#define DEBUG_TYPE "instcombine"
21
22
namespace llvm {
23
24
/// InstCombineWorklist - This is the worklist management logic for
25
/// InstCombine.
26
class InstCombineWorklist {
27
  SmallVector<Instruction*, 256> Worklist;
28
  DenseMap<Instruction*, unsigned> WorklistMap;
29
30
public:
31
108k
  InstCombineWorklist() = default;
32
33
2.77k
  InstCombineWorklist(InstCombineWorklist &&) = default;
34
  InstCombineWorklist &operator=(InstCombineWorklist &&) = default;
35
36
170M
  bool isEmpty() const { return Worklist.empty(); }
37
38
  /// Add - Add the specified instruction to the worklist if it isn't already
39
  /// in it.
40
11.2M
  void Add(Instruction *I) {
41
11.2M
    if (WorklistMap.insert(std::make_pair(I, Worklist.size())).second) {
42
7.23M
      LLVM_DEBUG(dbgs() << "IC: ADD: " << *I << '\n');
43
7.23M
      Worklist.push_back(I);
44
7.23M
    }
45
11.2M
  }
46
47
6.03k
  void AddValue(Value *V) {
48
6.03k
    if (Instruction *I = dyn_cast<Instruction>(V))
49
6.02k
      Add(I);
50
6.03k
  }
51
52
  /// AddInitialGroup - Add the specified batch of stuff in reverse order.
53
  /// which should only be done when the worklist is empty and when the group
54
  /// has no duplicates.
55
3.72M
  void AddInitialGroup(ArrayRef<Instruction *> List) {
56
3.72M
    assert(Worklist.empty() && "Worklist must be empty to add initial group");
57
3.72M
    Worklist.reserve(List.size()+16);
58
3.72M
    WorklistMap.reserve(List.size());
59
3.72M
    LLVM_DEBUG(dbgs() << "IC: ADDING: " << List.size()
60
3.72M
                      << " instrs to worklist\n");
61
3.72M
    unsigned Idx = 0;
62
159M
    for (Instruction *I : reverse(List)) {
63
159M
      WorklistMap.insert(std::make_pair(I, Idx++));
64
159M
      Worklist.push_back(I);
65
159M
    }
66
3.72M
  }
67
68
  // Remove - remove I from the worklist if it exists.
69
2.87M
  void Remove(Instruction *I) {
70
2.87M
    DenseMap<Instruction*, unsigned>::iterator It = WorklistMap.find(I);
71
2.87M
    if (It == WorklistMap.end()) 
return2.67M
; // Not in worklist.
72
203k
73
203k
    // Don't bother moving everything down, just null out the slot.
74
203k
    Worklist[It->second] = nullptr;
75
203k
76
203k
    WorklistMap.erase(It);
77
203k
  }
78
79
166M
  Instruction *RemoveOne() {
80
166M
    Instruction *I = Worklist.pop_back_val();
81
166M
    WorklistMap.erase(I);
82
166M
    return I;
83
166M
  }
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
4.15M
  void AddUsersToWorkList(Instruction &I) {
90
4.15M
    for (User *U : I.users())
91
4.27M
      Add(cast<Instruction>(U));
92
4.15M
  }
93
94
95
  /// Zap - check that the worklist is empty and nuke the backing store for
96
  /// the map if it is large.
97
3.72M
  void Zap() {
98
3.72M
    assert(WorklistMap.empty() && "Worklist empty, but map not?");
99
3.72M
100
3.72M
    // Do an explicit clear, this shrinks the map if needed.
101
3.72M
    WorklistMap.clear();
102
3.72M
  }
103
};
104
105
} // end namespace llvm.
106
107
#undef DEBUG_TYPE
108
109
#endif