[PATCH] D16795: WholeProgramDevirt: introduce.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 8 15:22:49 PST 2016


pete added inline comments.

================
Comment at: lib/Transforms/IPO/WholeProgramDevirt.cpp:331-347
@@ +330,19 @@
+    auto OpGlobal = dyn_cast<GlobalVariable>(OpConst);
+    if (!OpGlobal)
+      continue;
+
+    uint64_t Offset =
+        cast<ConstantInt>(
+            cast<ConstantAsMetadata>(Op->getOperand(2))->getValue())
+            ->getZExtValue();
+
+    VTableBits *&BitsPtr = GVToBits[OpGlobal];
+    if (!BitsPtr) {
+      Bits.emplace_back();
+      Bits.back().GV = OpGlobal;
+      Bits.back().ObjectSize = M.getDataLayout().getTypeAllocSize(
+          OpGlobal->getInitializer()->getType());
+      BitsPtr = &Bits.back();
+    }
+    BitSets[BitSetID].insert({BitsPtr, Offset});
+  }
----------------
Sorry, don't know how to reply to this point correctly in Phab, but here goes:

So this is the current code to add an entry to BitSets[].  This is where I think we could move the following checks, as that way we know that all elements in BitSets have valid GlobalValue's according to these checks.  I don't think thats too bad so long as we can move the checks here.  Obviously if for some reason we had to duplicate the checks then your current code is better.

These are the checks I'm thinking of:

 if (!BS.Bits->GV->isConstant())
     return false;

   auto Init = dyn_cast<ConstantArray>(BS.Bits->GV->getInitializer());
   if (!Init)
     return false;


http://reviews.llvm.org/D16795





More information about the llvm-commits mailing list