[clang] [llvm] [clang][CoverageMapping] Refactor when setting MC/DC True/False (PR #78202)

NAKAMURA Takumi via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 16 22:57:39 PST 2024


================
@@ -663,9 +663,12 @@ struct MCDCCoverageBuilder {
 private:
   CodeGenModule &CGM;
 
-  llvm::SmallVector<MCDCConditionID> AndRHS;
-  llvm::SmallVector<MCDCConditionID> OrRHS;
-  llvm::SmallVector<const BinaryOperator *> NestLevel;
+  struct DecisionIDPair {
+    MCDCConditionID TrueID = 0;
+    MCDCConditionID FalseID = 0;
+  };
+
+  llvm::SmallVector<DecisionIDPair, 1> DecisionStack;
----------------
chapuni wrote:

The background why the number of inline elements is 1:
`DecisionStack`  is initialized with one `[0,0]` value as the sentinel (immutable, readonly). I thought most conditions will not grow up the stack since they don't meet logical ops. The stack may be reallocated when at least one logical op was found.

In contrast, possibly the maximum number of stack depth might be at most 6, I guess. The default number of inline elements is 6 on `llvm::SmallVector<DecisionIDPair>` in this case. The size is `16 + 8 * n` in general.

Which is better with `default(n=6)`: 64 bytes or `n=1`, 24 bytes?

https://github.com/llvm/llvm-project/pull/78202


More information about the cfe-commits mailing list