llvm-project/llvm/test/Other/functionpropertiesanalysis.ll
Iñaki V Arrechea 701040d48f
[LLVM] Successor count added to InstCount (#171670)
Counts the number of Basic Block successors when stats are enabled
We want to track this metric for a project in which we analyze the
effects of having LLVM Intermediate Representation (IR) code with a high
number of branches. We plan to use these capabilities to learn how
enabling memory safety features increases the branchiness in LLVM IR and
further how it affects binary compilation time and the resulting binary
performance.
2026-01-06 12:41:25 -08:00

71 lines
2.2 KiB
LLVM

; Testing with all of the below run lines that the pass gets added to the appropriate pipelines
; REQUIRES: asserts
; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes=func-properties-stats < %s 2>&1 | FileCheck %s
; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto<O3>'< %s 2>&1 | FileCheck %s
; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='thinlto-pre-link<O2>' < %s 2>&1 | FileCheck %s
; RUN: opt -stats -enable-detailed-function-properties -disable-output -passes='lto<O1>' < %s 2>&1 | FileCheck %s
; RUN: opt -stats -enable-detailed-function-properties -disable-output -O3 < %s 2>&1 | FileCheck %s
; RUN: opt -stats -enable-detailed-function-properties -disable-output -O0 < %s 2>&1 | FileCheck %s
; CHECK-DAG: 10 func-properties-stats - Number of basic blocks
; CHECK-DAG: 8 func-properties-stats - Number of branch instructions
; CHECK-DAG: 10 func-properties-stats - Number of branch successors
; CHECK-DAG: 2 func-properties-stats - Number of conditional branch instructions
; CHECK-DAG: 6 func-properties-stats - Number of unconditional branch instructions
; CHECK-DAG: 18 func-properties-stats - Number of instructions (of all types)
; CHECK-DAG: 14 func-properties-stats - Number of basic block successors
; CHECK-DAG: 1 func-properties-stats - Number of switch instructions
; CHECK-DAG: 4 func-properties-stats - Number of switch successors
define void @foo(i32 %i, i32 %j, i32 %n) {
entry:
%cmp = icmp slt i32 %i, %j
br i1 %cmp, label %if.then, label %if.end
if.then:
call void @f()
br label %if.end
if.end:
switch i32 %i, label %sw.default [
i32 1, label %sw.bb
i32 2, label %sw.bb1
i32 3, label %sw.bb1
]
sw.bb:
call void @g()
br label %sw.epilog
sw.bb1:
call void @h()
br label %sw.epilog
sw.default:
call void @k()
br label %sw.epilog
sw.epilog:
%cmp2 = icmp sgt i32 %i, %n
br i1 %cmp2, label %if.then3, label %if.else
if.then3:
call void @l()
br label %if.end4
if.else:
call void @m()
br label %if.end4
if.end4:
ret void
}
declare void @f()
declare void @g()
declare void @h()
declare void @k()
declare void @l()
declare void @m()