tp: DBv2 - MapToTableBitVector takes OverlayOp

Bug:283763282
Change-Id: I1d7aaa4b05dfe7cb3c976c8f1f3ba9f515d03ac7
diff --git a/src/trace_processor/db/overlays/null_overlay.cc b/src/trace_processor/db/overlays/null_overlay.cc
index c5f5f66..ca44204 100644
--- a/src/trace_processor/db/overlays/null_overlay.cc
+++ b/src/trace_processor/db/overlays/null_overlay.cc
@@ -16,6 +16,7 @@
 
 #include "src/trace_processor/db/overlays/null_overlay.h"
 #include "perfetto/ext/base/flat_hash_map.h"
+#include "src/trace_processor/db/overlays/types.h"
 
 namespace perfetto {
 namespace trace_processor {
@@ -30,9 +31,16 @@
   return StorageRange({Range(start, end)});
 }
 
-TableBitVector NullOverlay::MapToTableBitVector(StorageBitVector s_bv) const {
+TableBitVector NullOverlay::MapToTableBitVector(StorageBitVector s_bv,
+                                                OverlayOp op) const {
   BitVector res = non_null_->Copy();
   res.UpdateSetBits(s_bv.bv);
+
+  if (op != OverlayOp::kIsNull)
+    return {std::move(res)};
+
+  BitVector not_non_null = non_null_->Not();
+  res.Or(not_non_null);
   return {std::move(res)};
 }
 
diff --git a/src/trace_processor/db/overlays/null_overlay.h b/src/trace_processor/db/overlays/null_overlay.h
index 93da2c0..518bd07 100644
--- a/src/trace_processor/db/overlays/null_overlay.h
+++ b/src/trace_processor/db/overlays/null_overlay.h
@@ -31,7 +31,8 @@
 
   StorageRange MapToStorageRange(TableRange) const override;
 
-  TableBitVector MapToTableBitVector(StorageBitVector) const override;
+  TableBitVector MapToTableBitVector(StorageBitVector,
+                                     OverlayOp) const override;
 
   BitVector IsStorageLookupRequired(OverlayOp,
                                     const TableIndexVector&) const override;
diff --git a/src/trace_processor/db/overlays/null_overlay_unittest.cc b/src/trace_processor/db/overlays/null_overlay_unittest.cc
index 6f80eba..9bec414 100644
--- a/src/trace_processor/db/overlays/null_overlay_unittest.cc
+++ b/src/trace_processor/db/overlays/null_overlay_unittest.cc
@@ -46,13 +46,29 @@
 
   BitVector storage_bv{0, 1, 0, 1};
   TableBitVector table_bv =
-      overlay.MapToTableBitVector({std::move(storage_bv)});
+      overlay.MapToTableBitVector({std::move(storage_bv)}, OverlayOp::kOther);
 
   ASSERT_EQ(table_bv.bv.CountSetBits(), 2u);
   ASSERT_TRUE(table_bv.bv.IsSet(2));
   ASSERT_TRUE(table_bv.bv.IsSet(6));
 }
 
+TEST(NullOverlay, MapToTableBitVectorIsNull) {
+  BitVector bv{0, 1, 1, 0, 0, 1, 1, 0};
+  NullOverlay overlay(&bv);
+
+  BitVector storage_bv{0, 1, 0, 1};
+  TableBitVector table_bv =
+      overlay.MapToTableBitVector({std::move(storage_bv)}, OverlayOp::kIsNull);
+
+  // Result is all of the zeroes from |bv| and set bits from |storage_bv|
+  // 1, 0, 1, 1, 1, 0, 1, 1
+
+  ASSERT_EQ(table_bv.bv.CountSetBits(), 6u);
+  ASSERT_FALSE(table_bv.bv.IsSet(1));
+  ASSERT_FALSE(table_bv.bv.IsSet(5));
+}
+
 TEST(NullOverlay, IsStorageLookupRequiredNullOp) {
   BitVector bv{0, 1, 1, 0, 0, 1, 1, 0};
   NullOverlay overlay(&bv);
diff --git a/src/trace_processor/db/overlays/selector_overlay.cc b/src/trace_processor/db/overlays/selector_overlay.cc
index e501ddf..ddcb8c1 100644
--- a/src/trace_processor/db/overlays/selector_overlay.cc
+++ b/src/trace_processor/db/overlays/selector_overlay.cc
@@ -29,8 +29,8 @@
             selected_->IndexOfNthSet(t_range.range.end - 1) + 1)};
 }
 
-TableBitVector SelectorOverlay::MapToTableBitVector(
-    StorageBitVector s_bv) const {
+TableBitVector SelectorOverlay::MapToTableBitVector(StorageBitVector s_bv,
+                                                    OverlayOp) const {
   PERFETTO_DCHECK(s_bv.bv.size() == selected_->size());
   BitVector res(selected_->CountSetBits());
   // TODO(b/283763282): Implement this variation of |UpdateSetBits| in
diff --git a/src/trace_processor/db/overlays/selector_overlay.h b/src/trace_processor/db/overlays/selector_overlay.h
index 70be983..1cad92c 100644
--- a/src/trace_processor/db/overlays/selector_overlay.h
+++ b/src/trace_processor/db/overlays/selector_overlay.h
@@ -18,6 +18,7 @@
 #define SRC_TRACE_PROCESSOR_DB_OVERLAYS_SELECTOR_OVERLAY_H_
 
 #include "src/trace_processor/db/overlays/storage_overlay.h"
+#include "src/trace_processor/db/overlays/types.h"
 
 namespace perfetto {
 namespace trace_processor {
@@ -30,7 +31,8 @@
 
   StorageRange MapToStorageRange(TableRange) const override;
 
-  TableBitVector MapToTableBitVector(StorageBitVector) const override;
+  TableBitVector MapToTableBitVector(StorageBitVector,
+                                     OverlayOp) const override;
 
   BitVector IsStorageLookupRequired(OverlayOp,
                                     const TableIndexVector&) const override;
diff --git a/src/trace_processor/db/overlays/selector_overlay_unittest.cc b/src/trace_processor/db/overlays/selector_overlay_unittest.cc
index 6e14597..8c743e8 100644
--- a/src/trace_processor/db/overlays/selector_overlay_unittest.cc
+++ b/src/trace_processor/db/overlays/selector_overlay_unittest.cc
@@ -46,7 +46,7 @@
 
   BitVector storage_bv{1, 0, 1, 0, 1, 0, 1, 0};
   TableBitVector table_bv =
-      overlay.MapToTableBitVector({std::move(storage_bv)});
+      overlay.MapToTableBitVector({std::move(storage_bv)}, OverlayOp::kOther);
 
   ASSERT_EQ(table_bv.bv.size(), 4u);
   ASSERT_EQ(table_bv.bv.CountSetBits(), 2u);
diff --git a/src/trace_processor/db/overlays/storage_overlay.h b/src/trace_processor/db/overlays/storage_overlay.h
index 58dbf50..2c165de 100644
--- a/src/trace_processor/db/overlays/storage_overlay.h
+++ b/src/trace_processor/db/overlays/storage_overlay.h
@@ -52,7 +52,8 @@
 
   // Maps a BitVector of indices in storage space to an equivalent range of
   // indices in the table space.
-  virtual TableBitVector MapToTableBitVector(StorageBitVector) const = 0;
+  virtual TableBitVector MapToTableBitVector(StorageBitVector,
+                                             OverlayOp) const = 0;
 
   // Returns a BitVector where each boolean indicates if the corresponding index
   // in |indices| needs to be mapped and searched in the storage or if the