aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/EarlyCSE.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-01-03 01:10:08 +0000
committerChris Lattner <sabre@nondot.org>2011-01-03 01:10:08 +0000
commitd957c717918c412402157b85fc51b4c6d2631381 (patch)
tree08ce0ca6446b98c02850d122ad9d4f93f8ba00b7 /lib/Transforms/Scalar/EarlyCSE.cpp
parent832f61117d69019376c4aabedd4de3831279e288 (diff)
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
Diffstat (limited to 'lib/Transforms/Scalar/EarlyCSE.cpp')
-rw-r--r--lib/Transforms/Scalar/EarlyCSE.cpp42
1 files changed, 23 insertions, 19 deletions
diff --git a/lib/Transforms/Scalar/EarlyCSE.cpp b/lib/Transforms/Scalar/EarlyCSE.cpp
index 80daa5a4c6..4399e2ee1f 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<InstValue>::getHashValue(InstValue Val) {
Instruction *Inst = Val.Inst;
+
+ // 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<CastInst>(Inst))
- Res = getHash(CI->getOperand(0)) ^ getHash(CI->getType());
- else if (BinaryOperator *BO = dyn_cast<BinaryOperator>(Inst))
- Res = getHash(BO->getOperand(0)) ^ (getHash(BO->getOperand(1)) << 1);
- else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(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<CmpInst>(Inst)) {
- Res = getHash(CI->getOperand(0)) ^ (getHash(CI->getOperand(1)) << 1) ^
- CI->getPredicate();
+ Res ^= getHash(CI->getType());
+ else if (CmpInst *CI = dyn_cast<CmpInst>(Inst))
+ Res ^= CI->getPredicate();
+ else if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(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<InsertValueInst>(Inst)) {
+ for (InsertValueInst::idx_iterator I = IVI->idx_begin(),
+ E = IVI->idx_end(); I != E; ++I)
+ Res ^= *I;
} else {
- assert((isa<SelectInst>(Inst) || isa<ExtractElementInst>(Inst) ||
- isa<InsertElementInst>(Inst) || isa<ShuffleVectorInst>(Inst) ||
- isa<ExtractValueInst>(Inst) || isa<InsertValueInst>(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;
+ // nothing extra to hash in.
+ assert((isa<BinaryOperator>(Inst) || isa<GetElementPtrInst>(Inst) ||
+ isa<SelectInst>(Inst) || isa<ExtractElementInst>(Inst) ||
+ isa<InsertElementInst>(Inst) || isa<ShuffleVectorInst>(Inst)) &&
+ "Invalid/unknown instruction");
}
-
+
+ // Mix in the opcode.
return (Res << 1) ^ Inst->getOpcode();
}