From d957c717918c412402157b85fc51b4c6d2631381 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 3 Jan 2011 01:10:08 +0000 Subject: [PATCH] reduce redundancy in the hashing code and other misc cleanups. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@122720 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/EarlyCSE.cpp | 48 +++++++++++--------- lib/Transforms/Scalar/LoopIdiomRecognize.cpp | 2 +- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/lib/Transforms/Scalar/EarlyCSE.cpp b/lib/Transforms/Scalar/EarlyCSE.cpp index 80daa5a4c66..4399e2ee1fd 100644 --- a/lib/Transforms/Scalar/EarlyCSE.cpp +++ b/lib/Transforms/Scalar/EarlyCSE.cpp @@ -18,7 +18,6 @@ #include "llvm/Pass.h" #include "llvm/Analysis/Dominators.h" #include "llvm/Analysis/InstructionSimplify.h" -#include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Target/TargetData.h" #include "llvm/Transforms/Utils/Local.h" #include "llvm/Support/Debug.h" @@ -80,28 +79,33 @@ unsigned getHash(const void *V) { unsigned DenseMapInfo::getHashValue(InstValue Val) { Instruction *Inst = Val.Inst; - unsigned Res = 0; - if (CastInst *CI = dyn_cast(Inst)) - Res = getHash(CI->getOperand(0)) ^ getHash(CI->getType()); - else if (BinaryOperator *BO = dyn_cast(Inst)) - Res = getHash(BO->getOperand(0)) ^ (getHash(BO->getOperand(1)) << 1); - else if (GetElementPtrInst *GEP = dyn_cast(Inst)) { - Res = getHash(GEP->getOperand(0)); - for (unsigned i = 1, e = GEP->getNumOperands(); i != e; ++i) - Res ^= getHash(GEP->getOperand(i)) << i; - } else if (CmpInst *CI = dyn_cast(Inst)) { - Res = getHash(CI->getOperand(0)) ^ (getHash(CI->getOperand(1)) << 1) ^ - CI->getPredicate(); - } else { - assert((isa(Inst) || isa(Inst) || - isa(Inst) || isa(Inst) || - isa(Inst) || isa(Inst)) && - "Unhandled instruction kind"); - Res = getHash(Inst->getType()) << 4; - for (unsigned i = 0, e = Inst->getNumOperands(); i != e; ++i) - Res ^= getHash(Inst->getOperand(i)) << i; - } + // Hash in all of the operands as pointers. + unsigned Res = 0; + for (unsigned i = 0, e = Inst->getNumOperands(); i != e; ++i) + Res ^= getHash(Inst->getOperand(i)) << i; + + if (CastInst *CI = dyn_cast(Inst)) + Res ^= getHash(CI->getType()); + else if (CmpInst *CI = dyn_cast(Inst)) + Res ^= CI->getPredicate(); + else if (const ExtractValueInst *EVI = dyn_cast(Inst)) { + for (ExtractValueInst::idx_iterator I = EVI->idx_begin(), + E = EVI->idx_end(); I != E; ++I) + Res ^= *I; + } else if (const InsertValueInst *IVI = dyn_cast(Inst)) { + for (InsertValueInst::idx_iterator I = IVI->idx_begin(), + E = IVI->idx_end(); I != E; ++I) + Res ^= *I; + } else { + // nothing extra to hash in. + assert((isa(Inst) || isa(Inst) || + isa(Inst) || isa(Inst) || + isa(Inst) || isa(Inst)) && + "Invalid/unknown instruction"); + } + + // Mix in the opcode. return (Res << 1) ^ Inst->getOpcode(); } diff --git a/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index 086afb14b29..dc55848d35f 100644 --- a/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -32,7 +32,7 @@ // for (i) { __real__(*P) = 0; __imag__(*P) = 0; } // this is also "Example 2" from http://blog.regehr.org/archives/320 // -// This could regognize common matrix multiplies and dot product idioms and +// This could recognize common matrix multiplies and dot product idioms and // replace them with calls to BLAS (if linked in??). // //===----------------------------------------------------------------------===//