Skip to content

Commit 11c7bd3

Browse files
bicycle1885antoine-levitt
authored andcommitted
refactor BasicBlock counting (JuliaLang#39945)
1 parent d8cf10b commit 11c7bd3

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/jitlayers.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,11 @@ static void addPassesForOptLevel(legacy::PassManager &PM, TargetMachine &TM, raw
555555
llvm_unreachable("Target does not support MC emission.");
556556
}
557557

558+
static auto countBasicBlocks(const Function &F)
559+
{
560+
return std::distance(F.begin(), F.end());
561+
}
562+
558563
CompilerResultT JuliaOJIT::CompilerT::operator()(Module &M)
559564
{
560565
uint64_t start_time = 0;
@@ -569,17 +574,10 @@ CompilerResultT JuliaOJIT::CompilerT::operator()(Module &M)
569574
if (F.isDeclaration() || F.getName().startswith("jfptr_")) {
570575
continue;
571576
}
572-
// Count number of Basic Blocks
573-
int bbs = 0;
574-
for (auto &B : F.getBasicBlockList()) {
575-
std::ignore = B;
576-
++bbs;
577-
}
578-
579577
// Each function is printed as a YAML object with several attributes
580578
jl_printf(dump_llvm_opt_stream, " \"%s\":\n", F.getName().str().c_str());
581579
jl_printf(dump_llvm_opt_stream, " instructions: %u\n", F.getInstructionCount());
582-
jl_printf(dump_llvm_opt_stream, " basicblocks: %u\n", bbs);
580+
jl_printf(dump_llvm_opt_stream, " basicblocks: %lu\n", countBasicBlocks(F));
583581
}
584582

585583
start_time = jl_hrtime();
@@ -640,17 +638,9 @@ CompilerResultT JuliaOJIT::CompilerT::operator()(Module &M)
640638
if (F.isDeclaration() || F.getName().startswith("jfptr_")) {
641639
continue;
642640
}
643-
644-
// Count number of Basic Blocks
645-
int bbs = 0;
646-
for (auto &B : F.getBasicBlockList()) {
647-
std::ignore = B;
648-
++bbs;
649-
}
650-
651641
jl_printf(dump_llvm_opt_stream, " \"%s\":\n", F.getName().str().c_str());
652642
jl_printf(dump_llvm_opt_stream, " instructions: %u\n", F.getInstructionCount());
653-
jl_printf(dump_llvm_opt_stream, " basicblocks: %u\n", bbs);
643+
jl_printf(dump_llvm_opt_stream, " basicblocks: %lu\n", countBasicBlocks(F));
654644
}
655645
}
656646

0 commit comments

Comments
 (0)