BlockGenerator: Simplify the old value searching code.
authorHongbin Zheng <etherzhhb@gmail.com>
Sat, 29 Jun 2013 13:22:15 +0000 (13:22 +0000)
committerHongbin Zheng <etherzhhb@gmail.com>
Sat, 29 Jun 2013 13:22:15 +0000 (13:22 +0000)
Orignally, we first test if a ValueMap contains a Value, and than use the
index operator to get the corresponding new value. This requires the ValueMap
to lookup the key (i.e. the old value) twice.

Now, we directly use the "lookup" function provided by DenseMap to implement
the same functionality.

llvm-svn: 185260

polly/lib/CodeGen/BlockGenerators.cpp

index a89de743a2c7b4ea975a2f576790f5a3f0ea22b9..6eb0a81d3adb7e802605e4ab540453968a53682b 100644 (file)
@@ -166,9 +166,7 @@ Value *BlockGenerator::getNewValue(const Value *Old, ValueMapT &BBMap,
   if (isa<Constant>(Old))
     return const_cast<Value *>(Old);
 
-  if (GlobalMap.count(Old)) {
-    Value *New = GlobalMap[Old];
-
+  if (Value *New = GlobalMap.lookup(Old)) {
     if (Old->getType()->getScalarSizeInBits() <
         New->getType()->getScalarSizeInBits())
       New = Builder.CreateTruncOrBitCast(New, Old->getType());
@@ -176,10 +174,8 @@ Value *BlockGenerator::getNewValue(const Value *Old, ValueMapT &BBMap,
     return New;
   }
 
-  if (BBMap.count(Old)) {
-    assert(BBMap[Old] && "BBMap[Old] should not be NULL!");
-    return BBMap[Old];
-  }
+  if (Value *New = BBMap.lookup(Old))
+    return New;
 
   if (SCEVCodegen && SE.isSCEVable(Old->getType()))
     if (const SCEV *Scev = SE.getSCEVAtScope(const_cast<Value *>(Old), L)) {
@@ -395,8 +391,8 @@ Value *VectorBlockGenerator::getVectorValue(const Value *Old,
                                             ValueMapT &VectorMap,
                                             VectorValueMapT &ScalarMaps,
                                             Loop *L) {
-  if (VectorMap.count(Old))
-    return VectorMap[Old];
+  if (Value *NewValue = VectorMap.lookup(Old))
+    return NewValue;
 
   int Width = getVectorWidth();