2013-08-06 02:16:21 +02:00
|
|
|
//===- InstCombineWorklist.h - Worklist for InstCombine pass ----*- C++ -*-===//
|
2010-01-04 07:30:00 +01: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 18:26:38 +02:00
|
|
|
#ifndef LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEWORKLIST_H
|
|
|
|
#define LLVM_LIB_TRANSFORMS_INSTCOMBINE_INSTCOMBINEWORKLIST_H
|
2010-01-04 07:30:00 +01:00
|
|
|
|
2012-12-04 08:12:27 +01:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Instruction.h"
|
2010-01-04 07:30:00 +01:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2012-12-04 08:12:27 +01:00
|
|
|
#include "llvm/Support/Debug.h"
|
2010-01-04 07:30:00 +01:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
2014-04-22 04:55:47 +02:00
|
|
|
#define DEBUG_TYPE "instcombine"
|
|
|
|
|
2010-01-04 07:30:00 +01:00
|
|
|
namespace llvm {
|
2013-01-15 00:16:36 +01:00
|
|
|
|
2010-01-04 07:30:00 +01:00
|
|
|
/// InstCombineWorklist - This is the worklist management logic for
|
|
|
|
/// InstCombine.
|
2010-05-11 22:16:09 +02:00
|
|
|
class LLVM_LIBRARY_VISIBILITY InstCombineWorklist {
|
2010-01-04 07:30:00 +01:00
|
|
|
SmallVector<Instruction*, 256> Worklist;
|
|
|
|
DenseMap<Instruction*, unsigned> WorklistMap;
|
2013-01-15 00:16:36 +01:00
|
|
|
|
2012-09-15 19:09:36 +02:00
|
|
|
void operator=(const InstCombineWorklist&RHS) LLVM_DELETED_FUNCTION;
|
|
|
|
InstCombineWorklist(const InstCombineWorklist&) LLVM_DELETED_FUNCTION;
|
2010-01-04 07:30:00 +01:00
|
|
|
public:
|
|
|
|
InstCombineWorklist() {}
|
2013-01-15 00:16:36 +01:00
|
|
|
|
2010-01-04 07:30:00 +01:00
|
|
|
bool isEmpty() const { return Worklist.empty(); }
|
2013-01-15 00:16:36 +01:00
|
|
|
|
2010-01-04 07:30:00 +01: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 21:48:28 +02:00
|
|
|
DEBUG(dbgs() << "IC: ADD: " << *I << '\n');
|
2010-01-04 07:30:00 +01:00
|
|
|
Worklist.push_back(I);
|
|
|
|
}
|
|
|
|
}
|
2013-01-15 00:16:36 +01:00
|
|
|
|
2010-01-04 07:30:00 +01:00
|
|
|
void AddValue(Value *V) {
|
|
|
|
if (Instruction *I = dyn_cast<Instruction>(V))
|
|
|
|
Add(I);
|
|
|
|
}
|
2013-01-15 00:16:36 +01:00
|
|
|
|
2010-01-04 07:30:00 +01: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 17:43:46 +01:00
|
|
|
WorklistMap.resize(NumEntries);
|
2013-09-05 21:48:28 +02:00
|
|
|
DEBUG(dbgs() << "IC: ADDING: " << NumEntries << " instrs to worklist\n");
|
2012-03-15 12:19:41 +01:00
|
|
|
for (unsigned Idx = 0; NumEntries; --NumEntries) {
|
2010-01-04 07:30:00 +01:00
|
|
|
Instruction *I = List[NumEntries-1];
|
2012-03-15 12:19:41 +01:00
|
|
|
WorklistMap.insert(std::make_pair(I, Idx++));
|
2010-01-04 07:30:00 +01:00
|
|
|
Worklist.push_back(I);
|
|
|
|
}
|
|
|
|
}
|
2013-01-15 00:16:36 +01:00
|
|
|
|
2010-01-04 07:30:00 +01: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-15 00:16:36 +01:00
|
|
|
|
2010-01-04 07:30:00 +01:00
|
|
|
// Don't bother moving everything down, just null out the slot.
|
2014-04-28 06:05:08 +02:00
|
|
|
Worklist[It->second] = nullptr;
|
2013-01-15 00:16:36 +01:00
|
|
|
|
2010-01-04 07:30:00 +01:00
|
|
|
WorklistMap.erase(It);
|
|
|
|
}
|
2013-01-15 00:16:36 +01:00
|
|
|
|
2010-01-04 07:30:00 +01:00
|
|
|
Instruction *RemoveOne() {
|
2013-08-20 00:47:55 +02:00
|
|
|
Instruction *I = Worklist.pop_back_val();
|
2010-01-04 07:30:00 +01:00
|
|
|
WorklistMap.erase(I);
|
|
|
|
return I;
|
|
|
|
}
|
2013-01-15 00:16:36 +01:00
|
|
|
|
2010-01-04 07:30:00 +01: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 04:16:01 +01:00
|
|
|
for (User *U : I.users())
|
|
|
|
Add(cast<Instruction>(U));
|
2010-01-04 07:30:00 +01:00
|
|
|
}
|
2013-01-15 00:16:36 +01:00
|
|
|
|
|
|
|
|
2010-01-04 07:30:00 +01: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-15 00:16:36 +01:00
|
|
|
|
2010-01-04 07:30:00 +01:00
|
|
|
// Do an explicit clear, this shrinks the map if needed.
|
|
|
|
WorklistMap.clear();
|
|
|
|
}
|
|
|
|
};
|
2013-01-15 00:16:36 +01:00
|
|
|
|
2010-01-04 07:30:00 +01:00
|
|
|
} // end namespace llvm.
|
|
|
|
|
2014-04-22 04:55:47 +02:00
|
|
|
#undef DEBUG_TYPE
|
|
|
|
|
2010-01-04 07:30:00 +01:00
|
|
|
#endif
|