2013-08-06 00:16:21 +00:00
|
|
|
//===- InstCombineWorklist.h - Worklist for InstCombine pass ----*- C++ -*-===//
|
2010-01-04 06:30:00 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#ifndef LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEWORKLIST_H
|
|
|
|
#define LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEWORKLIST_H
|
2010-01-04 06:30:00 +00:00
|
|
|
|
2012-12-04 07:12:27 +00:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Instruction.h"
|
2010-01-04 06:30:00 +00:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2012-12-04 07:12:27 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
2010-01-04 06:30:00 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
2014-04-22 02:55:47 +00:00
|
|
|
#define DEBUG_TYPE "instcombine"
|
|
|
|
|
2010-01-04 06:30:00 +00:00
|
|
|
namespace llvm {
|
2013-01-14 23:16:36 +00:00
|
|
|
|
2010-01-04 06:30:00 +00:00
|
|
|
/// InstCombineWorklist - This is the worklist management logic for
|
|
|
|
/// InstCombine.
|
2010-05-11 20:16:09 +00:00
|
|
|
class LLVM_LIBRARY_VISIBILITY InstCombineWorklist {
|
2010-01-04 06:30:00 +00:00
|
|
|
SmallVector<Instruction*, 256> Worklist;
|
|
|
|
DenseMap<Instruction*, unsigned> WorklistMap;
|
2013-01-14 23:16:36 +00:00
|
|
|
|
2012-09-15 17:09:36 +00:00
|
|
|
void operator=(const InstCombineWorklist&RHS) LLVM_DELETED_FUNCTION;
|
|
|
|
InstCombineWorklist(const InstCombineWorklist&) LLVM_DELETED_FUNCTION;
|
2010-01-04 06:30:00 +00:00
|
|
|
public:
|
|
|
|
InstCombineWorklist() {}
|
2013-01-14 23:16:36 +00:00
|
|
|
|
2010-01-04 06:30:00 +00:00
|
|
|
bool isEmpty() const { return Worklist.empty(); }
|
2013-01-14 23:16:36 +00:00
|
|
|
|
2010-01-04 06:30:00 +00:00
|
|
|
/// Add - Add the specified instruction to the worklist if it isn't already
|
|
|
|
/// in it.
|
|
|
|
void Add(Instruction *I) {
|
|
|
|
if (WorklistMap.insert(std::make_pair(I, Worklist.size())).second) {
|
2013-09-05 19:48:28 +00:00
|
|
|
DEBUG(dbgs() << "IC: ADD: " << *I << '\n');
|
2010-01-04 06:30:00 +00:00
|
|
|
Worklist.push_back(I);
|
|
|
|
}
|
|
|
|
}
|
2013-01-14 23:16:36 +00:00
|
|
|
|
2010-01-04 06:30:00 +00:00
|
|
|
void AddValue(Value *V) {
|
|
|
|
if (Instruction *I = dyn_cast<Instruction>(V))
|
|
|
|
Add(I);
|
|
|
|
}
|
2013-01-14 23:16:36 +00:00
|
|
|
|
2010-01-04 06:30:00 +00:00
|
|
|
/// AddInitialGroup - Add the specified batch of stuff in reverse order.
|
|
|
|
/// which should only be done when the worklist is empty and when the group
|
|
|
|
/// has no duplicates.
|
|
|
|
void AddInitialGroup(Instruction *const *List, unsigned NumEntries) {
|
|
|
|
assert(Worklist.empty() && "Worklist must be empty to add initial group");
|
|
|
|
Worklist.reserve(NumEntries+16);
|
2011-03-05 16:43:46 +00:00
|
|
|
WorklistMap.resize(NumEntries);
|
2013-09-05 19:48:28 +00:00
|
|
|
DEBUG(dbgs() << "IC: ADDING: " << NumEntries << " instrs to worklist\n");
|
2012-03-15 11:19:41 +00:00
|
|
|
for (unsigned Idx = 0; NumEntries; --NumEntries) {
|
2010-01-04 06:30:00 +00:00
|
|
|
Instruction *I = List[NumEntries-1];
|
2012-03-15 11:19:41 +00:00
|
|
|
WorklistMap.insert(std::make_pair(I, Idx++));
|
2010-01-04 06:30:00 +00:00
|
|
|
Worklist.push_back(I);
|
|
|
|
}
|
|
|
|
}
|
2013-01-14 23:16:36 +00:00
|
|
|
|
2010-01-04 06:30:00 +00:00
|
|
|
// Remove - remove I from the worklist if it exists.
|
|
|
|
void Remove(Instruction *I) {
|
|
|
|
DenseMap<Instruction*, unsigned>::iterator It = WorklistMap.find(I);
|
|
|
|
if (It == WorklistMap.end()) return; // Not in worklist.
|
2013-01-14 23:16:36 +00:00
|
|
|
|
2010-01-04 06:30:00 +00:00
|
|
|
// Don't bother moving everything down, just null out the slot.
|
2014-04-28 04:05:08 +00:00
|
|
|
Worklist[It->second] = nullptr;
|
2013-01-14 23:16:36 +00:00
|
|
|
|
2010-01-04 06:30:00 +00:00
|
|
|
WorklistMap.erase(It);
|
|
|
|
}
|
2013-01-14 23:16:36 +00:00
|
|
|
|
2010-01-04 06:30:00 +00:00
|
|
|
Instruction *RemoveOne() {
|
2013-08-19 22:47:55 +00:00
|
|
|
Instruction *I = Worklist.pop_back_val();
|
2010-01-04 06:30:00 +00:00
|
|
|
WorklistMap.erase(I);
|
|
|
|
return I;
|
|
|
|
}
|
2013-01-14 23:16:36 +00:00
|
|
|
|
2010-01-04 06:30:00 +00:00
|
|
|
/// AddUsersToWorkList - When an instruction is simplified, add all users of
|
|
|
|
/// the instruction to the work lists because they might get more simplified
|
|
|
|
/// now.
|
|
|
|
///
|
|
|
|
void AddUsersToWorkList(Instruction &I) {
|
2014-03-09 03:16:01 +00:00
|
|
|
for (User *U : I.users())
|
|
|
|
Add(cast<Instruction>(U));
|
2010-01-04 06:30:00 +00:00
|
|
|
}
|
2013-01-14 23:16:36 +00:00
|
|
|
|
|
|
|
|
2010-01-04 06:30:00 +00:00
|
|
|
/// Zap - check that the worklist is empty and nuke the backing store for
|
|
|
|
/// the map if it is large.
|
|
|
|
void Zap() {
|
|
|
|
assert(WorklistMap.empty() && "Worklist empty, but map not?");
|
2013-01-14 23:16:36 +00:00
|
|
|
|
2010-01-04 06:30:00 +00:00
|
|
|
// Do an explicit clear, this shrinks the map if needed.
|
|
|
|
WorklistMap.clear();
|
|
|
|
}
|
|
|
|
};
|
2013-01-14 23:16:36 +00:00
|
|
|
|
2010-01-04 06:30:00 +00:00
|
|
|
} // end namespace llvm.
|
|
|
|
|
2014-04-22 02:55:47 +00:00
|
|
|
#undef DEBUG_TYPE
|
|
|
|
|
2010-01-04 06:30:00 +00:00
|
|
|
#endif
|