alanphipps updated this revision to Diff 290301. alanphipps added a comment.
- Rename isLeafCondition() to isInstrumentedCondition() and rephrase associated comments - Add branch regions on C++ range-based loops CHANGES SINCE LAST ACTION https://reviews.llvm.org/D84467/new/ https://reviews.llvm.org/D84467 Files: clang/lib/CodeGen/CGExprScalar.cpp clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/CodeGenFunction.h clang/lib/CodeGen/CodeGenPGO.cpp clang/lib/CodeGen/CoverageMappingGen.cpp clang/test/CoverageMapping/loops.cpp clang/test/CoverageMapping/macro-expressions.cpp
Index: clang/test/CoverageMapping/macro-expressions.cpp =================================================================== --- clang/test/CoverageMapping/macro-expressions.cpp +++ clang/test/CoverageMapping/macro-expressions.cpp @@ -79,7 +79,8 @@ // CHECK-NEXT: File 0, [[@LINE+2]]:6 -> [[@LINE+2]]:8 = (#0 + #6) // CHECK-NEXT: Expansion,File 0, [[@LINE+1]]:16 -> [[@LINE+1]]:21 = (#0 + #6) do {} while (NEXPR(i)); - // CHECK-NEXT: Expansion,File 0, [[@LINE+3]]:8 -> [[@LINE+3]]:12 = #0 + // CHECK-NEXT: Expansion,File 0, [[@LINE+4]]:8 -> [[@LINE+4]]:12 = #0 + // CHECK-NEXT: Branch,File 0, [[@LINE+3]]:21 -> [[@LINE+3]]:22 = #7, #0 // CHECK-NEXT: Expansion,File 0, [[@LINE+2]]:23 -> [[@LINE+2]]:26 = #0 // CHECK: File 0, [[@LINE+1]]:42 -> [[@LINE+1]]:44 = #7 for (DECL(int, j) : ARR(int, 1, 2, 3)) {} Index: clang/test/CoverageMapping/loops.cpp =================================================================== --- clang/test/CoverageMapping/loops.cpp +++ clang/test/CoverageMapping/loops.cpp @@ -4,7 +4,9 @@ // CHECK: rangedFor void rangedFor() { // CHECK-NEXT: File 0, [[@LINE]]:18 -> {{[0-9]+}}:2 = #0 int arr[] = { 1, 2, 3, 4, 5 }; - int sum = 0; // CHECK: Gap,File 0, [[@LINE+1]]:20 -> [[@LINE+1]]:21 = #1 + int sum = 0; + // CHECK-NEXT: Branch,File 0, [[@LINE+2]]:14 -> [[@LINE+2]]:15 = #1, (#0 - #3) + // CHECK: Gap,File 0, [[@LINE+1]]:20 -> [[@LINE+1]]:21 = #1 for(auto i : arr) { // CHECK: File 0, [[@LINE]]:21 -> [[@LINE+6]]:4 = #1 if (i == 3) continue; // CHECK: File 0, [[@LINE]]:7 -> [[@LINE]]:15 = #2 Index: clang/lib/CodeGen/CoverageMappingGen.cpp =================================================================== --- clang/lib/CodeGen/CoverageMappingGen.cpp +++ clang/lib/CodeGen/CoverageMappingGen.cpp @@ -792,20 +792,20 @@ return (Cond->EvaluateAsInt(Result, CVM.getCodeGenModule().getContext())); } - /// Create a Branch Region around a leaf-level condition for code coverage + /// Create a Branch Region around an instrumentable condition for coverage /// and add it to the function's SourceRegions. A branch region tracks a - /// "True" counter and a "False" counter for all leaf-level boolean - /// expressions that result in the generation of a branch. + /// "True" counter and a "False" counter for boolean expressions that + /// result in the generation of a branch. void createBranchRegion(const Expr *C, Counter TrueCnt, Counter FalseCnt) { // Check for NULL conditions. if (!C) return; - // Ensure we are a leaf-level condition (i.e. no "&&" or "||"). Push + // Ensure we are an instrumentable condition (i.e. no "&&" or "||"). Push // region onto RegionStack but immediately pop it (which adds it to the // function's SourceRegions) because it doesn't apply to any other source // code other than the Condition. - if (CodeGenFunction::isLeafCondition(C)) { + if (CodeGenFunction::isInstrumentedCondition(C)) { // If a condition can fold to true or false, the corresponding branch // will be removed. Create a region with both counters hard-coded to // zero. This allows us to visualize them in a special way. @@ -1250,6 +1250,10 @@ addCounters(BC.BreakCount, subtractCounters(LoopCount, BodyCount)); if (OutCount != ParentCount) pushRegion(OutCount); + + // Create Branch Region around condition. + createBranchRegion(S->getCond(), BodyCount, + subtractCounters(LoopCount, BodyCount)); } void VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) { Index: clang/lib/CodeGen/CodeGenPGO.cpp =================================================================== --- clang/lib/CodeGen/CodeGenPGO.cpp +++ clang/lib/CodeGen/CodeGenPGO.cpp @@ -212,7 +212,8 @@ /// version so that we facilitate backward compatibility. bool VisitBinaryOperator(BinaryOperator *S) { if (ProfileVersion >= llvm::IndexedInstrProf::Version7) - if (S->isLogicalOp() && CodeGenFunction::isLeafCondition(S->getRHS())) + if (S->isLogicalOp() && + CodeGenFunction::isInstrumentedCondition(S->getRHS())) CounterMap[S->getRHS()] = NextCounter++; return Base::VisitBinaryOperator(S); } Index: clang/lib/CodeGen/CodeGenFunction.h =================================================================== --- clang/lib/CodeGen/CodeGenFunction.h +++ clang/lib/CodeGen/CodeGenFunction.h @@ -4354,9 +4354,9 @@ bool ConstantFoldsToSimpleInteger(const Expr *Cond, llvm::APSInt &Result, bool AllowLabels = false); - /// isLeafCondition - Determine whether the given condition is a leaf-level - /// condition (i.e. no "&&" or "||"). - static bool isLeafCondition(const Expr *C); + /// isInstrumentedCondition - Determine whether the given condition is an + /// instrumentable condition (i.e. no "&&" or "||"). + static bool isInstrumentedCondition(const Expr *C); /// EmitBranchToCounterBlock - Emit a conditional branch to a new block that /// increments a profile counter based on the semantics of the given logical Index: clang/lib/CodeGen/CodeGenFunction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenFunction.cpp +++ clang/lib/CodeGen/CodeGenFunction.cpp @@ -1462,9 +1462,9 @@ return true; } -/// Determine whether the given condition is a leaf-level condition +/// Determine whether the given condition is an instrumentable condition /// (i.e. no "&&" or "||"). -bool CodeGenFunction::isLeafCondition(const Expr *C) { +bool CodeGenFunction::isInstrumentedCondition(const Expr *C) { // Bypass simplistic logical-NOT operator before determining whether the // condition contains any other logical operator. if (const UnaryOperator *UnOp = dyn_cast<UnaryOperator>(C->IgnoreParens())) @@ -1485,9 +1485,9 @@ llvm::BasicBlock *FalseBlock, uint64_t TrueCount /* = 0 */, const Expr *CntrIdx /*=NULL*/) { - // If not instrumenting or this isn't a leaf condition, just emit a branch. + // If not instrumenting, just emit a branch. bool InstrumentRegions = CGM.getCodeGenOpts().hasProfileClangInstr(); - if (!InstrumentRegions || !isLeafCondition(Cond)) + if (!InstrumentRegions || !isInstrumentedCondition(Cond)) return EmitBranchOnBoolExpr(Cond, TrueBlock, FalseBlock, TrueCount); llvm::BasicBlock *ThenBlock = NULL; Index: clang/lib/CodeGen/CGExprScalar.cpp =================================================================== --- clang/lib/CodeGen/CGExprScalar.cpp +++ clang/lib/CodeGen/CGExprScalar.cpp @@ -4236,7 +4236,8 @@ // block that increments the RHS counter needed to track branch condition // coverage. In this case, use "FBlock" as the final "TrueBlock" and // "FalseBlock" after the increment is done. - if (InstrumentRegions && CodeGenFunction::isLeafCondition(E->getRHS())) { + if (InstrumentRegions && + CodeGenFunction::isInstrumentedCondition(E->getRHS())) { llvm::BasicBlock *FBlock = CGF.createBasicBlock("land.end"); CGF.EmitBranchToCounterBlock(E->getRHS(), BO_LAnd, FBlock, FBlock); CGF.EmitBlock(FBlock); @@ -4282,7 +4283,8 @@ // If we're generating for profiling or coverage, generate a branch on the // RHS to a block that increments the RHS true counter needed to track branch // condition coverage. - if (InstrumentRegions && CodeGenFunction::isLeafCondition(E->getRHS())) { + if (InstrumentRegions && + CodeGenFunction::isInstrumentedCondition(E->getRHS())) { llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("land.rhscnt"); Builder.CreateCondBr(RHSCond, RHSBlockCnt, ContBlock); CGF.EmitBlock(RHSBlockCnt); @@ -4345,7 +4347,8 @@ // block that increments the RHS counter need to track branch condition // coverage. In this case, use "FBlock" as the final "TrueBlock" and // "FalseBlock" after the increment is done. - if (InstrumentRegions && CodeGenFunction::isLeafCondition(E->getRHS())) { + if (InstrumentRegions && + CodeGenFunction::isInstrumentedCondition(E->getRHS())) { llvm::BasicBlock *FBlock = CGF.createBasicBlock("lor.end"); CGF.EmitBranchToCounterBlock(E->getRHS(), BO_LOr, FBlock, FBlock); CGF.EmitBlock(FBlock); @@ -4394,7 +4397,8 @@ // If we're generating for profiling or coverage, generate a branch on the // RHS to a block that increments the RHS true counter needed to track branch // condition coverage. - if (InstrumentRegions && CodeGenFunction::isLeafCondition(E->getRHS())) { + if (InstrumentRegions && + CodeGenFunction::isInstrumentedCondition(E->getRHS())) { llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("lor.rhscnt"); Builder.CreateCondBr(RHSCond, ContBlock, RHSBlockCnt); CGF.EmitBlock(RHSBlockCnt);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits