diff --git a/llvm/include/llvm/Transforms/InstCombine/InstCombine.h b/llvm/include/llvm/Transforms/InstCombine/InstCombine.h --- a/llvm/include/llvm/Transforms/InstCombine/InstCombine.h +++ b/llvm/include/llvm/Transforms/InstCombine/InstCombine.h @@ -18,12 +18,14 @@ #include "llvm/IR/Function.h" #include "llvm/IR/PassManager.h" -#include "llvm/Transforms/InstCombine/InstCombineWorklist.h" + +#define DEBUG_TYPE "instcombine" +#include "llvm/Transforms/Utils/InstructionWorklist.h" namespace llvm { class InstCombinePass : public PassInfoMixin { - InstCombineWorklist Worklist; + InstructionWorklist Worklist; const unsigned MaxIterations; public: @@ -38,7 +40,7 @@ /// This is a basic whole-function wrapper around the instcombine utility. It /// will try to combine all instructions in the function. class InstructionCombiningPass : public FunctionPass { - InstCombineWorklist Worklist; + InstructionWorklist Worklist; const unsigned MaxIterations; public: @@ -67,4 +69,6 @@ FunctionPass *createInstructionCombiningPass(unsigned MaxIterations); } +#undef DEBUG_TYPE + #endif diff --git a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h --- a/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h +++ b/llvm/include/llvm/Transforms/InstCombine/InstCombiner.h @@ -25,10 +25,10 @@ #include "llvm/IR/PatternMatch.h" #include "llvm/Support/Debug.h" #include "llvm/Support/KnownBits.h" -#include "llvm/Transforms/InstCombine/InstCombineWorklist.h" #include #define DEBUG_TYPE "instcombine" +#include "llvm/Transforms/Utils/InstructionWorklist.h" namespace llvm { @@ -57,7 +57,7 @@ protected: /// A worklist of the instructions that need to be simplified. - InstCombineWorklist &Worklist; + InstructionWorklist &Worklist; // Mode in which we are running the combiner. const bool MinimizeSize; @@ -81,7 +81,7 @@ bool MadeIRChange = false; public: - InstCombiner(InstCombineWorklist &Worklist, BuilderTy &Builder, + InstCombiner(InstructionWorklist &Worklist, BuilderTy &Builder, bool MinimizeSize, AAResults *AA, AssumptionCache &AC, TargetLibraryInfo &TLI, TargetTransformInfo &TTI, DominatorTree &DT, OptimizationRemarkEmitter &ORE, diff --git a/llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h b/llvm/include/llvm/Transforms/Utils/InstructionWorklist.h rename from llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h rename to llvm/include/llvm/Transforms/Utils/InstructionWorklist.h --- a/llvm/include/llvm/Transforms/InstCombine/InstCombineWorklist.h +++ b/llvm/include/llvm/Transforms/Utils/InstructionWorklist.h @@ -1,4 +1,4 @@ -//===- InstCombineWorklist.h - Worklist for InstCombine pass ----*- C++ -*-===// +//=== InstructionWorklist.h - Worklist for InstCombine & others -*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINEWORKLIST_H -#define LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINEWORKLIST_H +#ifndef LLVM_TRANSFORMS_UTILS_INSTRUCTIONWORKLIST_H +#define LLVM_TRANSFORMS_UTILS_INSTRUCTIONWORKLIST_H #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/STLExtras.h" @@ -18,13 +18,11 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/raw_ostream.h" -#define DEBUG_TYPE "instcombine" - namespace llvm { -/// InstCombineWorklist - This is the worklist management logic for -/// InstCombine. -class InstCombineWorklist { +/// InstructionWorklist - This is the worklist management logic for +/// InstCombine and other simplification passes. +class InstructionWorklist { SmallVector Worklist; DenseMap WorklistMap; /// These instructions will be added in reverse order after the current @@ -32,11 +30,13 @@ /// in the order they have been added. SmallSetVector Deferred; + const char *DbgPrefix = "IC"; + public: - InstCombineWorklist() = default; + InstructionWorklist() = default; - InstCombineWorklist(InstCombineWorklist &&) = default; - InstCombineWorklist &operator=(InstCombineWorklist &&) = default; + InstructionWorklist(InstructionWorklist &&) = default; + InstructionWorklist &operator=(InstructionWorklist &&) = default; bool isEmpty() const { return Worklist.empty() && Deferred.empty(); } @@ -45,7 +45,7 @@ /// You likely want to use this method. void add(Instruction *I) { if (Deferred.insert(I)) - LLVM_DEBUG(dbgs() << "IC: ADD DEFERRED: " << *I << '\n'); + LLVM_DEBUG(dbgs() << DbgPrefix << ": ADD DEFERRED: " << *I << '\n'); } /// Add value to the worklist if it is an instruction. @@ -62,7 +62,7 @@ assert(I->getParent() && "Instruction not inserted yet?"); if (WorklistMap.insert(std::make_pair(I, Worklist.size())).second) { - LLVM_DEBUG(dbgs() << "IC: ADD: " << *I << '\n'); + LLVM_DEBUG(dbgs() << ": ADD: " << *I << '\n'); Worklist.push_back(I); } } @@ -85,7 +85,7 @@ /// Remove I from the worklist if it exists. void remove(Instruction *I) { - DenseMap::iterator It = WorklistMap.find(I); + DenseMap::iterator It = WorklistMap.find(I); if (It != WorklistMap.end()) { // Don't bother moving everything down, just null out the slot. Worklist[It->second] = nullptr; @@ -110,7 +110,6 @@ push(cast(U)); } - /// Check that the worklist is empty and nuke the backing store for the map. void zap() { assert(WorklistMap.empty() && "Worklist empty, but map not?"); @@ -123,6 +122,4 @@ } // end namespace llvm. -#undef DEBUG_TYPE - #endif diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -67,7 +67,6 @@ #include "llvm/Support/KnownBits.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Transforms/InstCombine/InstCombineWorklist.h" #include "llvm/Transforms/InstCombine/InstCombiner.h" #include "llvm/Transforms/Utils/AssumeBundleBuilder.h" #include "llvm/Transforms/Utils/Local.h" @@ -79,11 +78,12 @@ #include #include +#define DEBUG_TYPE "instcombine" +#include "llvm/Transforms/Utils/InstructionWorklist.h" + using namespace llvm; using namespace PatternMatch; -#define DEBUG_TYPE "instcombine" - STATISTIC(NumSimplified, "Number of library calls simplified"); static cl::opt GuardWideningWindow( diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h --- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h +++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h @@ -25,12 +25,12 @@ #include "llvm/IR/Value.h" #include "llvm/Support/Debug.h" #include "llvm/Support/KnownBits.h" -#include "llvm/Transforms/InstCombine/InstCombineWorklist.h" #include "llvm/Transforms/InstCombine/InstCombiner.h" #include "llvm/Transforms/Utils/Local.h" #include #define DEBUG_TYPE "instcombine" +#include "llvm/Transforms/Utils/InstructionWorklist.h" using namespace llvm::PatternMatch; @@ -62,7 +62,7 @@ : public InstCombiner, public InstVisitor { public: - InstCombinerImpl(InstCombineWorklist &Worklist, BuilderTy &Builder, + InstCombinerImpl(InstructionWorklist &Worklist, BuilderTy &Builder, bool MinimizeSize, AAResults *AA, AssumptionCache &AC, TargetLibraryInfo &TLI, TargetTransformInfo &TTI, DominatorTree &DT, OptimizationRemarkEmitter &ORE, diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp @@ -31,7 +31,6 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/KnownBits.h" -#include "llvm/Transforms/InstCombine/InstCombineWorklist.h" #include "llvm/Transforms/InstCombine/InstCombiner.h" #include "llvm/Transforms/Utils/BuildLibCalls.h" #include @@ -39,11 +38,12 @@ #include #include +#define DEBUG_TYPE "instcombine" +#include "llvm/Transforms/Utils/InstructionWorklist.h" + using namespace llvm; using namespace PatternMatch; -#define DEBUG_TYPE "instcombine" - /// The specific integer value is used in a context where it is known to be /// non-zero. If this allows us to simplify the computation, do so and return /// the new operand, otherwise return null. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -38,15 +38,16 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/KnownBits.h" -#include "llvm/Transforms/InstCombine/InstCombineWorklist.h" #include "llvm/Transforms/InstCombine/InstCombiner.h" #include #include +#define DEBUG_TYPE "instcombine" +#include "llvm/Transforms/Utils/InstructionWorklist.h" + using namespace llvm; using namespace PatternMatch; -#define DEBUG_TYPE "instcombine" static Value *createMinMax(InstCombiner::BuilderTy &Builder, SelectPatternFlavor SPF, Value *A, Value *B) { diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -35,18 +35,18 @@ #include "llvm/IR/Value.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Transforms/InstCombine/InstCombineWorklist.h" #include "llvm/Transforms/InstCombine/InstCombiner.h" #include #include #include #include +#define DEBUG_TYPE "instcombine" +#include "llvm/Transforms/Utils/InstructionWorklist.h" + using namespace llvm; using namespace PatternMatch; -#define DEBUG_TYPE "instcombine" - STATISTIC(NumAggregateReconstructionsSimplified, "Number of aggregate reconstructions turned into reuse of the " "original aggregate"); diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -100,7 +100,6 @@ #include "llvm/Support/KnownBits.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/InstCombine/InstCombine.h" -#include "llvm/Transforms/InstCombine/InstCombineWorklist.h" #include "llvm/Transforms/Utils/Local.h" #include #include @@ -109,11 +108,12 @@ #include #include +#define DEBUG_TYPE "instcombine" +#include "llvm/Transforms/Utils/InstructionWorklist.h" + using namespace llvm; using namespace llvm::PatternMatch; -#define DEBUG_TYPE "instcombine" - STATISTIC(NumWorklistIterations, "Number of instruction combining iterations performed"); @@ -3959,13 +3959,13 @@ /// whose condition is a known constant, we only visit the reachable successors. static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL, const TargetLibraryInfo *TLI, - InstCombineWorklist &ICWorklist) { + InstructionWorklist &ICWorklist) { bool MadeIRChange = false; SmallPtrSet Visited; SmallVector Worklist; Worklist.push_back(&F.front()); - SmallVector InstrsForInstCombineWorklist; + SmallVector InstrsForInstructionWorklist; DenseMap FoldedConstants; AliasScopeTracker SeenAliasScopes; @@ -4014,7 +4014,7 @@ // these call instructions consumes non-trivial amount of time and // provides no value for the optimization. if (!Inst.isDebugOrPseudoInst()) { - InstrsForInstCombineWorklist.push_back(&Inst); + InstrsForInstructionWorklist.push_back(&Inst); SeenAliasScopes.analyse(&Inst); } } @@ -4060,8 +4060,8 @@ // of the function down. This jives well with the way that it adds all uses // of instructions to the worklist after doing a transformation, thus avoiding // some N^2 behavior in pathological cases. - ICWorklist.reserve(InstrsForInstCombineWorklist.size()); - for (Instruction *Inst : reverse(InstrsForInstCombineWorklist)) { + ICWorklist.reserve(InstrsForInstructionWorklist.size()); + for (Instruction *Inst : reverse(InstrsForInstructionWorklist)) { // DCE instruction if trivially dead. As we iterate in reverse program // order here, we will clean up whole chains of dead instructions. if (isInstructionTriviallyDead(Inst, TLI) || @@ -4081,7 +4081,7 @@ } static bool combineInstructionsOverFunction( - Function &F, InstCombineWorklist &Worklist, AliasAnalysis *AA, + Function &F, InstructionWorklist &Worklist, AliasAnalysis *AA, AssumptionCache &AC, TargetLibraryInfo &TLI, TargetTransformInfo &TTI, DominatorTree &DT, OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI, unsigned MaxIterations, LoopInfo *LI) {