Skip to content

Commit 1cc3ffa

Browse files
committed
clangCodeGen: Reformat and refactor. NFC.
1 parent 7ad566d commit 1cc3ffa

File tree

4 files changed

+18
-16
lines changed

4 files changed

+18
-16
lines changed

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace llvm {
3939
extern cl::opt<bool> EnableSingleByteCoverage;
4040
} // namespace llvm
4141

42-
namespace {
42+
namespace {
4343
class AggExprEmitter : public StmtVisitor<AggExprEmitter> {
4444
CodeGenFunction &CGF;
4545
CGBuilderTy &Builder;

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -801,10 +801,12 @@ void CodeGenFunction::EmitIndirectGotoStmt(const IndirectGotoStmt &S) {
801801
}
802802

803803
void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
804+
const Stmt *Else = S.getElse();
805+
804806
// The else branch of a consteval if statement is always the only branch that
805807
// can be runtime evaluated.
806808
if (S.isConsteval()) {
807-
const Stmt *Executed = S.isNegatedConsteval() ? S.getThen() : S.getElse();
809+
const Stmt *Executed = S.isNegatedConsteval() ? S.getThen() : Else;
808810
if (Executed) {
809811
RunCleanupsScope ExecutedScope(*this);
810812
EmitStmt(Executed);
@@ -830,8 +832,8 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
830832
S.isConstexpr())) {
831833
// Figure out which block (then or else) is executed.
832834
const Stmt *Executed = S.getThen();
833-
const Stmt *Skipped = S.getElse();
834-
if (!CondConstant) // Condition false?
835+
const Stmt *Skipped = Else;
836+
if (!CondConstant) // Condition false?
835837
std::swap(Executed, Skipped);
836838

837839
// If the skipped block has no labels in it, just emit the executed block.
@@ -852,7 +854,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
852854
llvm::BasicBlock *ThenBlock = createBasicBlock("if.then");
853855
llvm::BasicBlock *ContBlock = createBasicBlock("if.end");
854856
llvm::BasicBlock *ElseBlock = ContBlock;
855-
if (S.getElse())
857+
if (Else)
856858
ElseBlock = createBasicBlock("if.else");
857859

858860
// Prefer the PGO based weights over the likelihood attribute.
@@ -870,7 +872,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
870872
uint64_t ThenCount = getProfileCount(S.getThen());
871873
if (!ThenCount && !getCurrentProfileCount() &&
872874
CGM.getCodeGenOpts().OptimizationLevel)
873-
LH = Stmt::getLikelihood(S.getThen(), S.getElse());
875+
LH = Stmt::getLikelihood(S.getThen(), Else);
874876

875877
// When measuring MC/DC, always fully evaluate the condition up front using
876878
// EvaluateExprAsBool() so that the test vector bitmap can be updated prior to
@@ -898,7 +900,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
898900
EmitBranch(ContBlock);
899901

900902
// Emit the 'else' code if present.
901-
if (const Stmt *Else = S.getElse()) {
903+
if (Else) {
902904
{
903905
// There is no need to emit line number for an unconditional branch.
904906
auto NL = ApplyDebugLocation::CreateEmpty(*this);

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,8 @@ void CodeGenFunction::EmitBranchToCounterBlock(
17621762
if (!InstrumentRegions || !isInstrumentedCondition(Cond))
17631763
return EmitBranchOnBoolExpr(Cond, TrueBlock, FalseBlock, TrueCount, LH);
17641764

1765+
const Stmt *CntrStmt = (CntrIdx ? CntrIdx : Cond);
1766+
17651767
llvm::BasicBlock *ThenBlock = nullptr;
17661768
llvm::BasicBlock *ElseBlock = nullptr;
17671769
llvm::BasicBlock *NextBlock = nullptr;
@@ -1814,7 +1816,7 @@ void CodeGenFunction::EmitBranchToCounterBlock(
18141816
EmitBlock(CounterIncrBlock);
18151817

18161818
// Increment corresponding counter; if index not provided, use Cond as index.
1817-
incrementProfileCounter(CntrIdx ? CntrIdx : Cond);
1819+
incrementProfileCounter(CntrStmt);
18181820

18191821
// Go to the next block.
18201822
EmitBranch(NextBlock);

clang/lib/CodeGen/CodeGenPGO.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,14 +1206,12 @@ void CodeGenPGO::emitCounterSetOrIncrement(CGBuilderTy &Builder, const Stmt *S,
12061206
if (llvm::EnableSingleByteCoverage)
12071207
Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::instrprof_cover),
12081208
ArrayRef(Args, 4));
1209-
else {
1210-
if (!StepV)
1211-
Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::instrprof_increment),
1212-
ArrayRef(Args, 4));
1213-
else
1214-
Builder.CreateCall(
1215-
CGM.getIntrinsic(llvm::Intrinsic::instrprof_increment_step), Args);
1216-
}
1209+
else if (!StepV)
1210+
Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::instrprof_increment),
1211+
ArrayRef(Args, 4));
1212+
else
1213+
Builder.CreateCall(
1214+
CGM.getIntrinsic(llvm::Intrinsic::instrprof_increment_step), Args);
12171215
}
12181216

12191217
bool CodeGenPGO::canEmitMCDCCoverage(const CGBuilderTy &Builder) {

0 commit comments

Comments
 (0)