diff options
author | Chris Lattner <sabre@nondot.org> | 2007-02-03 00:08:31 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-02-03 00:08:31 +0000 |
commit | 5e665f559419c7f58a4fd9360cd488f065505c44 (patch) | |
tree | b0b885dc43015823c992923bd3a03b0cb4defa7b /lib/Transforms/Utils/ValueMapper.cpp | |
parent | 4642ca6589d3002861963744a157169f15d1ee90 (diff) |
Switch inliner over to use DenseMap instead of std::map for ValueMap. This
speeds up the inliner 16%.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33801 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils/ValueMapper.cpp')
-rw-r--r-- | lib/Transforms/Utils/ValueMapper.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp index 371bee195a..f90716ca26 100644 --- a/lib/Transforms/Utils/ValueMapper.cpp +++ b/lib/Transforms/Utils/ValueMapper.cpp @@ -18,9 +18,12 @@ #include "llvm/Instruction.h" using namespace llvm; -Value *llvm::MapValue(const Value *V, std::map<const Value*, Value*> &VM) { +Value *llvm::MapValue(const Value *V, ValueMapTy &VM) { Value *&VMSlot = VM[V]; if (VMSlot) return VMSlot; // Does it exist in the map yet? + + // NOTE: VMSlot can be invalidated by any reference to VM, which can grow the + // DenseMap. This includes any recursive calls to MapValue. // Global values do not need to be seeded into the ValueMap if they are using // the identity mapping. @@ -46,10 +49,10 @@ Value *llvm::MapValue(const Value *V, std::map<const Value*, Value*> &VM) { Values.push_back(cast<Constant>(MV)); for (++i; i != e; ++i) Values.push_back(cast<Constant>(MapValue(CA->getOperand(i), VM))); - return VMSlot = ConstantArray::get(CA->getType(), Values); + return VM[V] = ConstantArray::get(CA->getType(), Values); } } - return VMSlot = C; + return VM[V] = C; } else if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) { for (unsigned i = 0, e = CS->getNumOperands(); i != e; ++i) { @@ -65,16 +68,16 @@ Value *llvm::MapValue(const Value *V, std::map<const Value*, Value*> &VM) { Values.push_back(cast<Constant>(MV)); for (++i; i != e; ++i) Values.push_back(cast<Constant>(MapValue(CS->getOperand(i), VM))); - return VMSlot = ConstantStruct::get(CS->getType(), Values); + return VM[V] = ConstantStruct::get(CS->getType(), Values); } } - return VMSlot = C; + return VM[V] = C; } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) { std::vector<Constant*> Ops; for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i) Ops.push_back(cast<Constant>(MapValue(CE->getOperand(i), VM))); - return VMSlot = CE->getWithOperands(Ops); + return VM[V] = CE->getWithOperands(Ops); } else if (ConstantPacked *CP = dyn_cast<ConstantPacked>(C)) { for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i) { Value *MV = MapValue(CP->getOperand(i), VM); @@ -89,7 +92,7 @@ Value *llvm::MapValue(const Value *V, std::map<const Value*, Value*> &VM) { Values.push_back(cast<Constant>(MV)); for (++i; i != e; ++i) Values.push_back(cast<Constant>(MapValue(CP->getOperand(i), VM))); - return VMSlot = ConstantPacked::get(Values); + return VM[V] = ConstantPacked::get(Values); } } return VMSlot = C; @@ -105,8 +108,7 @@ Value *llvm::MapValue(const Value *V, std::map<const Value*, Value*> &VM) { /// RemapInstruction - Convert the instruction operands from referencing the /// current values into those specified by ValueMap. /// -void llvm::RemapInstruction(Instruction *I, - std::map<const Value *, Value*> &ValueMap) { +void llvm::RemapInstruction(Instruction *I, ValueMapTy &ValueMap) { for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) { const Value *Op = I->getOperand(op); Value *V = MapValue(Op, ValueMap); |