Skip to content

Commit e08a5dc

Browse files
committed
[InstCombine] Move InstCombineWorklist to Utils to allow reuse (NFC).
InstCombine's worklist can be re-used by other passes like VectorCombine. Move it to llvm/Transform/Utils and rename it to InstructionWorklist. Reviewed By: lebedev.ri Differential Revision: https://reviews.llvm.org/D110181
1 parent abbb0f9 commit e08a5dc

File tree

9 files changed

+45
-45
lines changed

9 files changed

+45
-45
lines changed

llvm/include/llvm/Transforms/InstCombine/InstCombine.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818

1919
#include "llvm/IR/Function.h"
2020
#include "llvm/IR/PassManager.h"
21-
#include "llvm/Transforms/InstCombine/InstCombineWorklist.h"
21+
22+
#define DEBUG_TYPE "instcombine"
23+
#include "llvm/Transforms/Utils/InstructionWorklist.h"
2224

2325
namespace llvm {
2426

2527
class InstCombinePass : public PassInfoMixin<InstCombinePass> {
26-
InstCombineWorklist Worklist;
28+
InstructionWorklist Worklist;
2729
const unsigned MaxIterations;
2830

2931
public:
@@ -38,7 +40,7 @@ class InstCombinePass : public PassInfoMixin<InstCombinePass> {
3840
/// This is a basic whole-function wrapper around the instcombine utility. It
3941
/// will try to combine all instructions in the function.
4042
class InstructionCombiningPass : public FunctionPass {
41-
InstCombineWorklist Worklist;
43+
InstructionWorklist Worklist;
4244
const unsigned MaxIterations;
4345

4446
public:
@@ -67,4 +69,6 @@ FunctionPass *createInstructionCombiningPass();
6769
FunctionPass *createInstructionCombiningPass(unsigned MaxIterations);
6870
}
6971

72+
#undef DEBUG_TYPE
73+
7074
#endif

llvm/include/llvm/Transforms/InstCombine/InstCombiner.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
#include "llvm/IR/PatternMatch.h"
2626
#include "llvm/Support/Debug.h"
2727
#include "llvm/Support/KnownBits.h"
28-
#include "llvm/Transforms/InstCombine/InstCombineWorklist.h"
2928
#include <cassert>
3029

3130
#define DEBUG_TYPE "instcombine"
31+
#include "llvm/Transforms/Utils/InstructionWorklist.h"
3232

3333
namespace llvm {
3434

@@ -57,7 +57,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
5757

5858
protected:
5959
/// A worklist of the instructions that need to be simplified.
60-
InstCombineWorklist &Worklist;
60+
InstructionWorklist &Worklist;
6161

6262
// Mode in which we are running the combiner.
6363
const bool MinimizeSize;
@@ -81,7 +81,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombiner {
8181
bool MadeIRChange = false;
8282

8383
public:
84-
InstCombiner(InstCombineWorklist &Worklist, BuilderTy &Builder,
84+
InstCombiner(InstructionWorklist &Worklist, BuilderTy &Builder,
8585
bool MinimizeSize, AAResults *AA, AssumptionCache &AC,
8686
TargetLibraryInfo &TLI, TargetTransformInfo &TTI,
8787
DominatorTree &DT, OptimizationRemarkEmitter &ORE,

llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h renamed to llvm/include/llvm/Transforms/Utils/InstructionWorklist.h

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
//===- InstCombineWorklist.h - Worklist for InstCombine pass ----*- C++ -*-===//
1+
//=== InstructionWorklist.h - Worklist for InstCombine & others -*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINEWORKLIST_H
10-
#define LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINEWORKLIST_H
9+
#ifndef LLVM_TRANSFORMS_UTILS_INSTRUCTIONWORKLIST_H
10+
#define LLVM_TRANSFORMS_UTILS_INSTRUCTIONWORKLIST_H
1111

1212
#include "llvm/ADT/DenseMap.h"
1313
#include "llvm/ADT/STLExtras.h"
@@ -18,13 +18,11 @@
1818
#include "llvm/Support/Debug.h"
1919
#include "llvm/Support/raw_ostream.h"
2020

21-
#define DEBUG_TYPE "instcombine"
22-
2321
namespace llvm {
2422

25-
/// InstCombineWorklist - This is the worklist management logic for
26-
/// InstCombine.
27-
class InstCombineWorklist {
23+
/// InstructionWorklist - This is the worklist management logic for
24+
/// InstCombine and other simplification passes.
25+
class InstructionWorklist {
2826
SmallVector<Instruction *, 256> Worklist;
2927
DenseMap<Instruction *, unsigned> WorklistMap;
3028
/// These instructions will be added in reverse order after the current
@@ -33,10 +31,10 @@ class InstCombineWorklist {
3331
SmallSetVector<Instruction *, 16> Deferred;
3432

3533
public:
36-
InstCombineWorklist() = default;
34+
InstructionWorklist() = default;
3735

38-
InstCombineWorklist(InstCombineWorklist &&) = default;
39-
InstCombineWorklist &operator=(InstCombineWorklist &&) = default;
36+
InstructionWorklist(InstructionWorklist &&) = default;
37+
InstructionWorklist &operator=(InstructionWorklist &&) = default;
4038

4139
bool isEmpty() const { return Worklist.empty() && Deferred.empty(); }
4240

@@ -45,7 +43,7 @@ class InstCombineWorklist {
4543
/// You likely want to use this method.
4644
void add(Instruction *I) {
4745
if (Deferred.insert(I))
48-
LLVM_DEBUG(dbgs() << "IC: ADD DEFERRED: " << *I << '\n');
46+
LLVM_DEBUG(dbgs() << "ADD DEFERRED: " << *I << '\n');
4947
}
5048

5149
/// Add value to the worklist if it is an instruction.
@@ -62,7 +60,7 @@ class InstCombineWorklist {
6260
assert(I->getParent() && "Instruction not inserted yet?");
6361

6462
if (WorklistMap.insert(std::make_pair(I, Worklist.size())).second) {
65-
LLVM_DEBUG(dbgs() << "IC: ADD: " << *I << '\n');
63+
LLVM_DEBUG(dbgs() << "ADD: " << *I << '\n');
6664
Worklist.push_back(I);
6765
}
6866
}
@@ -85,7 +83,7 @@ class InstCombineWorklist {
8583

8684
/// Remove I from the worklist if it exists.
8785
void remove(Instruction *I) {
88-
DenseMap<Instruction*, unsigned>::iterator It = WorklistMap.find(I);
86+
DenseMap<Instruction *, unsigned>::iterator It = WorklistMap.find(I);
8987
if (It != WorklistMap.end()) {
9088
// Don't bother moving everything down, just null out the slot.
9189
Worklist[It->second] = nullptr;
@@ -110,7 +108,6 @@ class InstCombineWorklist {
110108
push(cast<Instruction>(U));
111109
}
112110

113-
114111
/// Check that the worklist is empty and nuke the backing store for the map.
115112
void zap() {
116113
assert(WorklistMap.empty() && "Worklist empty, but map not?");
@@ -123,6 +120,4 @@ class InstCombineWorklist {
123120

124121
} // end namespace llvm.
125122

126-
#undef DEBUG_TYPE
127-
128123
#endif

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
#include "llvm/Support/KnownBits.h"
6868
#include "llvm/Support/MathExtras.h"
6969
#include "llvm/Support/raw_ostream.h"
70-
#include "llvm/Transforms/InstCombine/InstCombineWorklist.h"
7170
#include "llvm/Transforms/InstCombine/InstCombiner.h"
7271
#include "llvm/Transforms/Utils/AssumeBundleBuilder.h"
7372
#include "llvm/Transforms/Utils/Local.h"
@@ -79,11 +78,12 @@
7978
#include <utility>
8079
#include <vector>
8180

81+
#define DEBUG_TYPE "instcombine"
82+
#include "llvm/Transforms/Utils/InstructionWorklist.h"
83+
8284
using namespace llvm;
8385
using namespace PatternMatch;
8486

85-
#define DEBUG_TYPE "instcombine"
86-
8787
STATISTIC(NumSimplified, "Number of library calls simplified");
8888

8989
static cl::opt<unsigned> GuardWideningWindow(

llvm/lib/Transforms/InstCombine/InstCombineInternal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
#include "llvm/IR/Value.h"
2626
#include "llvm/Support/Debug.h"
2727
#include "llvm/Support/KnownBits.h"
28-
#include "llvm/Transforms/InstCombine/InstCombineWorklist.h"
2928
#include "llvm/Transforms/InstCombine/InstCombiner.h"
3029
#include "llvm/Transforms/Utils/Local.h"
3130
#include <cassert>
3231

3332
#define DEBUG_TYPE "instcombine"
33+
#include "llvm/Transforms/Utils/InstructionWorklist.h"
3434

3535
using namespace llvm::PatternMatch;
3636

@@ -62,7 +62,7 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
6262
: public InstCombiner,
6363
public InstVisitor<InstCombinerImpl, Instruction *> {
6464
public:
65-
InstCombinerImpl(InstCombineWorklist &Worklist, BuilderTy &Builder,
65+
InstCombinerImpl(InstructionWorklist &Worklist, BuilderTy &Builder,
6666
bool MinimizeSize, AAResults *AA, AssumptionCache &AC,
6767
TargetLibraryInfo &TLI, TargetTransformInfo &TTI,
6868
DominatorTree &DT, OptimizationRemarkEmitter &ORE,

llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@
3131
#include "llvm/Support/Casting.h"
3232
#include "llvm/Support/ErrorHandling.h"
3333
#include "llvm/Support/KnownBits.h"
34-
#include "llvm/Transforms/InstCombine/InstCombineWorklist.h"
3534
#include "llvm/Transforms/InstCombine/InstCombiner.h"
3635
#include "llvm/Transforms/Utils/BuildLibCalls.h"
3736
#include <cassert>
3837
#include <cstddef>
3938
#include <cstdint>
4039
#include <utility>
4140

41+
#define DEBUG_TYPE "instcombine"
42+
#include "llvm/Transforms/Utils/InstructionWorklist.h"
43+
4244
using namespace llvm;
4345
using namespace PatternMatch;
4446

45-
#define DEBUG_TYPE "instcombine"
46-
4747
/// The specific integer value is used in a context where it is known to be
4848
/// non-zero. If this allows us to simplify the computation, do so and return
4949
/// the new operand, otherwise return null.

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,16 @@
3838
#include "llvm/Support/Casting.h"
3939
#include "llvm/Support/ErrorHandling.h"
4040
#include "llvm/Support/KnownBits.h"
41-
#include "llvm/Transforms/InstCombine/InstCombineWorklist.h"
4241
#include "llvm/Transforms/InstCombine/InstCombiner.h"
4342
#include <cassert>
4443
#include <utility>
4544

45+
#define DEBUG_TYPE "instcombine"
46+
#include "llvm/Transforms/Utils/InstructionWorklist.h"
47+
4648
using namespace llvm;
4749
using namespace PatternMatch;
4850

49-
#define DEBUG_TYPE "instcombine"
5051

5152
static Value *createMinMax(InstCombiner::BuilderTy &Builder,
5253
SelectPatternFlavor SPF, Value *A, Value *B) {

llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@
3535
#include "llvm/IR/Value.h"
3636
#include "llvm/Support/Casting.h"
3737
#include "llvm/Support/ErrorHandling.h"
38-
#include "llvm/Transforms/InstCombine/InstCombineWorklist.h"
3938
#include "llvm/Transforms/InstCombine/InstCombiner.h"
4039
#include <cassert>
4140
#include <cstdint>
4241
#include <iterator>
4342
#include <utility>
4443

44+
#define DEBUG_TYPE "instcombine"
45+
#include "llvm/Transforms/Utils/InstructionWorklist.h"
46+
4547
using namespace llvm;
4648
using namespace PatternMatch;
4749

48-
#define DEBUG_TYPE "instcombine"
49-
5050
STATISTIC(NumAggregateReconstructionsSimplified,
5151
"Number of aggregate reconstructions turned into reuse of the "
5252
"original aggregate");

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
#include "llvm/Support/KnownBits.h"
101101
#include "llvm/Support/raw_ostream.h"
102102
#include "llvm/Transforms/InstCombine/InstCombine.h"
103-
#include "llvm/Transforms/InstCombine/InstCombineWorklist.h"
104103
#include "llvm/Transforms/Utils/Local.h"
105104
#include <algorithm>
106105
#include <cassert>
@@ -109,11 +108,12 @@
109108
#include <string>
110109
#include <utility>
111110

111+
#define DEBUG_TYPE "instcombine"
112+
#include "llvm/Transforms/Utils/InstructionWorklist.h"
113+
112114
using namespace llvm;
113115
using namespace llvm::PatternMatch;
114116

115-
#define DEBUG_TYPE "instcombine"
116-
117117
STATISTIC(NumWorklistIterations,
118118
"Number of instruction combining iterations performed");
119119

@@ -3975,13 +3975,13 @@ class AliasScopeTracker {
39753975
/// whose condition is a known constant, we only visit the reachable successors.
39763976
static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
39773977
const TargetLibraryInfo *TLI,
3978-
InstCombineWorklist &ICWorklist) {
3978+
InstructionWorklist &ICWorklist) {
39793979
bool MadeIRChange = false;
39803980
SmallPtrSet<BasicBlock *, 32> Visited;
39813981
SmallVector<BasicBlock*, 256> Worklist;
39823982
Worklist.push_back(&F.front());
39833983

3984-
SmallVector<Instruction*, 128> InstrsForInstCombineWorklist;
3984+
SmallVector<Instruction *, 128> InstrsForInstructionWorklist;
39853985
DenseMap<Constant *, Constant *> FoldedConstants;
39863986
AliasScopeTracker SeenAliasScopes;
39873987

@@ -4030,7 +4030,7 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
40304030
// these call instructions consumes non-trivial amount of time and
40314031
// provides no value for the optimization.
40324032
if (!Inst.isDebugOrPseudoInst()) {
4033-
InstrsForInstCombineWorklist.push_back(&Inst);
4033+
InstrsForInstructionWorklist.push_back(&Inst);
40344034
SeenAliasScopes.analyse(&Inst);
40354035
}
40364036
}
@@ -4076,8 +4076,8 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
40764076
// of the function down. This jives well with the way that it adds all uses
40774077
// of instructions to the worklist after doing a transformation, thus avoiding
40784078
// some N^2 behavior in pathological cases.
4079-
ICWorklist.reserve(InstrsForInstCombineWorklist.size());
4080-
for (Instruction *Inst : reverse(InstrsForInstCombineWorklist)) {
4079+
ICWorklist.reserve(InstrsForInstructionWorklist.size());
4080+
for (Instruction *Inst : reverse(InstrsForInstructionWorklist)) {
40814081
// DCE instruction if trivially dead. As we iterate in reverse program
40824082
// order here, we will clean up whole chains of dead instructions.
40834083
if (isInstructionTriviallyDead(Inst, TLI) ||
@@ -4097,7 +4097,7 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
40974097
}
40984098

40994099
static bool combineInstructionsOverFunction(
4100-
Function &F, InstCombineWorklist &Worklist, AliasAnalysis *AA,
4100+
Function &F, InstructionWorklist &Worklist, AliasAnalysis *AA,
41014101
AssumptionCache &AC, TargetLibraryInfo &TLI, TargetTransformInfo &TTI,
41024102
DominatorTree &DT, OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI,
41034103
ProfileSummaryInfo *PSI, unsigned MaxIterations, LoopInfo *LI) {

0 commit comments

Comments
 (0)