20 changes: 17 additions & 3 deletions llvm/test/CodeGen/X86/basic-block-sections-clusters.ll
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,30 @@
; Test1: Basic blocks #0 (entry) and #2 will be placed in the same section.
; Basic block 1 will be placed in a unique section.
; The rest will be placed in the cold section.
;;
;; Profile for version 0:
; RUN: echo '!foo' > %t1
; RUN: echo '!!0 2' >> %t1
; RUN: echo '!!1' >> %t1
;;
;; Profile for version 1:
; RUN: echo 'v1' > %t2
; RUN: echo 'f foo' >> %t2
; RUN: echo 'c 0 2' >> %t2
; RUN: echo 'c 1' >> %t2
;
; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t1 | FileCheck %s -check-prefix=LINUX-SECTIONS1
; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t2 | FileCheck %s -check-prefix=LINUX-SECTIONS1
;
; Test2: Basic blocks #1 and #3 will be placed in the same section.
; All other BBs (including the entry block) go into the function's section.
; RUN: echo '!foo' > %t2
; RUN: echo '!!1 3' >> %t2
; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t2 | FileCheck %s -check-prefix=LINUX-SECTIONS2
; RUN: echo '!foo' > %t3
; RUN: echo '!!1 3' >> %t3
; RUN: echo 'v1' > %t4
; RUN: echo 'f foo' >> %t4
; RUN: echo 'c 1 3' >> %t4
; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t3 | FileCheck %s -check-prefix=LINUX-SECTIONS2
; RUN: llc < %s -O0 -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t4 | FileCheck %s -check-prefix=LINUX-SECTIONS2

define void @foo(i1 zeroext) nounwind {
%2 = alloca i8, align 1
Expand Down
21 changes: 15 additions & 6 deletions llvm/test/CodeGen/X86/basic-block-sections-cold.ll
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
; Check if basic blocks that don't get unique sections are placed in cold sections.
; Basic block with id 1 and 2 must be in the cold section.
; RUN: echo '!_Z3bazb' > %t
; RUN: echo '!!0' >> %t
; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=%t -unique-basic-block-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS
; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=%t -unique-basic-block-section-names -bbsections-cold-text-prefix=".text.unlikely." | FileCheck %s -check-prefix=LINUX-SPLIT
;; Check if basic blocks that don't get unique sections are placed in cold sections.
;; Basic block with id 1 and 2 must be in the cold section.
;;
;; Profile for version 0
; RUN: echo '!_Z3bazb' > %t1
; RUN: echo '!!0' >> %t1
;;
;; Profile for version 1
; RUN: echo 'v1' > %t2
; RUN: echo 'f _Z3bazb' >> %t2
; RUN: echo 'c 0' >> %t2
;;
; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=%t1 -unique-basic-block-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS
; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=%t2 -unique-basic-block-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS
; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=%t1 -unique-basic-block-section-names -bbsections-cold-text-prefix=".text.unlikely." | FileCheck %s -check-prefix=LINUX-SPLIT

define void @_Z3bazb(i1 zeroext %0) nounwind {
br i1 %0, label %2, label %4
Expand Down
19 changes: 14 additions & 5 deletions llvm/test/CodeGen/X86/basic-block-sections-list.ll
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
; Check the basic block sections list option.
; RUN: echo '!_Z3foob' > %t
; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t -unique-basic-block-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS --check-prefix=LINUX-SECTIONS-FUNCTION-SECTION
; RUN: llc < %s -mtriple=x86_64-pc-linux -basic-block-sections=%t -unique-basic-block-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS --check-prefix=LINUX-SECTIONS-NO-FUNCTION-SECTION
; RUN: llc < %s -mtriple=x86_64-pc-linux -basic-block-sections=%t -unique-basic-block-section-names --bbsections-guided-section-prefix=false | FileCheck %s -check-prefix=LINUX-SECTIONS-NO-GUIDED-PREFIX
;; Check the basic block sections list option.
;; version 0 profile:
; RUN: echo '!_Z3foob' > %t1
;;
;; version 1 profile:
; RUN: echo 'v1' > %t2
; RUN: echo 'f _Z3foob' >> %t2
;;
; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t1 -unique-basic-block-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS --check-prefix=LINUX-SECTIONS-FUNCTION-SECTION
; RUN: llc < %s -mtriple=x86_64-pc-linux -basic-block-sections=%t1 -unique-basic-block-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS --check-prefix=LINUX-SECTIONS-NO-FUNCTION-SECTION
; RUN: llc < %s -mtriple=x86_64-pc-linux -basic-block-sections=%t1 -unique-basic-block-section-names --bbsections-guided-section-prefix=false | FileCheck %s -check-prefix=LINUX-SECTIONS-NO-GUIDED-PREFIX
; RUN: llc < %s -mtriple=x86_64-pc-linux -function-sections -basic-block-sections=%t2 -unique-basic-block-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS --check-prefix=LINUX-SECTIONS-FUNCTION-SECTION
; RUN: llc < %s -mtriple=x86_64-pc-linux -basic-block-sections=%t2 -unique-basic-block-section-names | FileCheck %s -check-prefix=LINUX-SECTIONS --check-prefix=LINUX-SECTIONS-NO-FUNCTION-SECTION
; RUN: llc < %s -mtriple=x86_64-pc-linux -basic-block-sections=%t2 -unique-basic-block-section-names --bbsections-guided-section-prefix=false | FileCheck %s -check-prefix=LINUX-SECTIONS-NO-GUIDED-PREFIX

define i32 @_Z3foob(i1 zeroext %0) nounwind {
%2 = alloca i32, align 4
Expand Down
24 changes: 24 additions & 0 deletions llvm/test/CodeGen/X86/basic-block-sections-module1.ll
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,30 @@
; RUN: echo '!test M=./path/to/dir/test_filename' > %t4
; RUN: echo '!!0' >> %t4
; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=%t4 | FileCheck %s -check-prefix=WRONG-MODULE
;; Version 1 profile.
;; Specify the right filename.
; RUN: echo 'v1' > %t5
; RUN: echo 'm /path/to/dir/test_filename' >> %t5
; RUN: echo 'f test' >> %t5
; RUN: echo 'c 0' >> %t5
; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=%t5 | FileCheck %s -check-prefix=RIGHT-MODULE
;; Specify no filename and verify that the profile is ingested.
; RUN: echo 'v1' > %t6
; RUN: echo 'f test' >> %t6
; RUN: echo 'c 0' >> %t6
; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=%t6 | FileCheck %s -check-prefix=NO-MODULE
;; Specify wrong filenames and verify that the profile is not ingested.
; RUN: echo 'v1' > %t7
; RUN: echo 'm test_filename' >> %t7
; RUN: echo 'f test' >> %t7
; RUN: echo 'c 0' >> %t7
; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=%t7 | FileCheck %s -check-prefix=WRONG-MODULE
; RUN: echo 'v1' > %t8
; RUN: echo 'm ./path/to/dir/test_filename' >> %t8
; RUN: echo 'f test' >> %t8
; RUN: echo 'c 0' >> %t8
; RUN: llc < %s -mtriple=x86_64 -function-sections -basic-block-sections=%t8 | FileCheck %s -check-prefix=WRONG-MODULE


define dso_local i32 @test(i32 noundef %0) #0 !dbg !10 {
%2 = alloca i32, align 4
Expand Down