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
This commit is contained in:
Chris Lattner 2011-01-03 01:10:08 +00:00
parent 832f61117d
commit d957c71791
2 changed files with 27 additions and 23 deletions

View File

@ -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;
unsigned Res = 0;
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();
} 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;
}
// 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->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 {
// 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();
}

View File

@ -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??).
//
//===----------------------------------------------------------------------===//