From a60a8b0eb773eabb3ad83e610e737efda525a0da Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 3 Jan 2011 03:28:23 +0000 Subject: [PATCH] various cleanups, no functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122729 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/EarlyCSE.cpp | 43 +++++++++++++----------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/lib/Transforms/Scalar/EarlyCSE.cpp b/lib/Transforms/Scalar/EarlyCSE.cpp index 557cd6d2b53..e4cb7bd333a 100644 --- a/lib/Transforms/Scalar/EarlyCSE.cpp +++ b/lib/Transforms/Scalar/EarlyCSE.cpp @@ -26,9 +26,9 @@ #include "llvm/ADT/Statistic.h" using namespace llvm; -STATISTIC(NumSimplify, "Number of insts simplified or DCE'd"); -STATISTIC(NumCSE, "Number of insts CSE'd"); -STATISTIC(NumCSEMem, "Number of load and call insts CSE'd"); +STATISTIC(NumSimplify, "Number of instructions simplified or DCE'd"); +STATISTIC(NumCSE, "Number of instructions CSE'd"); +STATISTIC(NumCSEMem, "Number of load and call instructions CSE'd"); static unsigned getHash(const void *V) { return DenseMapInfo::getHashValue(V); @@ -44,6 +44,10 @@ namespace { struct SimpleValue { Instruction *Inst; + SimpleValue(Instruction *I) : Inst(I) { + assert((isSentinel() || canHandle(I)) && "Inst can't be handled!"); + } + bool isSentinel() const { return Inst == DenseMapInfo::getEmptyKey() || Inst == DenseMapInfo::getTombstoneKey(); @@ -56,12 +60,6 @@ namespace { isa(Inst) || isa(Inst) || isa(Inst) || isa(Inst); } - - static SimpleValue get(Instruction *I) { - SimpleValue X; X.Inst = I; - assert((X.isSentinel() || canHandle(I)) && "Inst can't be handled!"); - return X; - } }; } @@ -73,10 +71,10 @@ template<> struct isPodLike { template<> struct DenseMapInfo { static inline SimpleValue getEmptyKey() { - return SimpleValue::get(DenseMapInfo::getEmptyKey()); + return DenseMapInfo::getEmptyKey(); } static inline SimpleValue getTombstoneKey() { - return SimpleValue::get(DenseMapInfo::getTombstoneKey()); + return DenseMapInfo::getTombstoneKey(); } static unsigned getHashValue(SimpleValue Val); static bool isEqual(SimpleValue LHS, SimpleValue RHS); @@ -135,6 +133,10 @@ namespace { struct MemoryValue { Instruction *Inst; + MemoryValue(Instruction *I) : Inst(I) { + assert((isSentinel() || canHandle(I)) && "Inst can't be handled!"); + } + bool isSentinel() const { return Inst == DenseMapInfo::getEmptyKey() || Inst == DenseMapInfo::getTombstoneKey(); @@ -147,12 +149,6 @@ namespace { return CI->onlyReadsMemory(); return false; } - - static MemoryValue get(Instruction *I) { - MemoryValue X; X.Inst = I; - assert((X.isSentinel() || canHandle(I)) && "Inst can't be handled!"); - return X; - } }; } @@ -164,10 +160,10 @@ namespace llvm { template<> struct DenseMapInfo { static inline MemoryValue getEmptyKey() { - return MemoryValue::get(DenseMapInfo::getEmptyKey()); + return DenseMapInfo::getEmptyKey(); } static inline MemoryValue getTombstoneKey() { - return MemoryValue::get(DenseMapInfo::getTombstoneKey()); + return DenseMapInfo::getTombstoneKey(); } static unsigned getHashValue(MemoryValue Val); static bool isEqual(MemoryValue LHS, MemoryValue RHS); @@ -317,7 +313,7 @@ bool EarlyCSE::processNode(DomTreeNode *Node) { // If this is a simple instruction that we can value number, process it. if (SimpleValue::canHandle(Inst)) { // See if the instruction has an available value. If so, use it. - if (Value *V = AvailableValues->lookup(SimpleValue::get(Inst))) { + if (Value *V = AvailableValues->lookup(Inst)) { DEBUG(dbgs() << "EarlyCSE CSE: " << *Inst << " to: " << *V << '\n'); Inst->replaceAllUsesWith(V); Inst->eraseFromParent(); @@ -327,7 +323,7 @@ bool EarlyCSE::processNode(DomTreeNode *Node) { } // Otherwise, just remember that this value is available. - AvailableValues->insert(SimpleValue::get(Inst), Inst); + AvailableValues->insert(Inst, Inst); continue; } @@ -335,8 +331,7 @@ bool EarlyCSE::processNode(DomTreeNode *Node) { if (MemoryValue::canHandle(Inst)) { // If we have an available version of this value, and if it is the right // generation, replace this instruction. - std::pair InVal = - AvailableMemValues->lookup(MemoryValue::get(Inst)); + std::pair InVal = AvailableMemValues->lookup(Inst); if (InVal.first != 0 && InVal.second == CurrentGeneration) { DEBUG(dbgs() << "EarlyCSE CSE MEM: " << *Inst << " to: " << *InVal.first << '\n'); @@ -348,7 +343,7 @@ bool EarlyCSE::processNode(DomTreeNode *Node) { } // Otherwise, remember that we have this instruction. - AvailableMemValues->insert(MemoryValue::get(Inst), + AvailableMemValues->insert(Inst, std::pair(Inst, CurrentGeneration)); continue; } -- 2.34.1