diff --git a/llvm/test/Examples/ThinLtoJIT/Inputs/main.ll b/llvm/test/Examples/ThinLtoJIT/Inputs/main.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Examples/ThinLtoJIT/Inputs/main.ll @@ -0,0 +1,56 @@ +; ModuleID = 'main.s' +source_filename = "main.c" + +define i32 @main(i32 %0, i8** nocapture readonly %1) { + %3 = alloca i8*, align 8 + %4 = icmp sgt i32 %0, 1 + br i1 %4, label %5, label %14 + +5: + %6 = bitcast i8** %3 to i8* + call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull %6) + %7 = getelementptr inbounds i8*, i8** %1, i64 1 + %8 = load i8*, i8** %7, align 8 + %9 = call i64 @strtol(i8* %8, i8** nonnull %3, i32 10) + %10 = load i8*, i8** %3, align 8 + %11 = load i8, i8* %10, align 1 + %12 = icmp eq i8 %11, 0 + %13 = xor i1 %12, true + call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull %6) + br i1 %12, label %14, label %24 + +14: + %15 = phi i64 [ %9, %5 ], [ 40, %2 ] + %16 = call i32 @sub1(i32 3) + %17 = call i32 @max(i32 0, i32 %16) + %18 = trunc i64 %15 to i32 + %19 = call i32 @workload(i32 %18) + %20 = call i32 @max(i32 %17, i32 %19) + %21 = call i32 @sub2(i32 4) + %22 = call i32 @max(i32 %20, i32 %21) + %23 = icmp slt i32 %22, 1 + br label %24 + +24: + %25 = phi i1 [ %23, %14 ], [ %13, %5 ] + %26 = zext i1 %25 to i32 + ret i32 %26 +} + +declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) +declare i64 @strtol(i8* readonly, i8** nocapture, i32) +declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) +declare i32 @max(i32, i32) +declare i32 @sub1(i32) +declare i32 @workload(i32) +declare i32 @sub2(i32) + +^0 = module: (path: "main.s", hash: (527116715, 3332069392, 338859151, 688235912, 2536759033)) +^1 = gv: (name: "workload") ; guid = 2904160244401423009 +^2 = gv: (name: "llvm.lifetime.start.p0i8") ; guid = 3657761528566682672 +^3 = gv: (name: "sub1") ; guid = 6667511020869341723 +^4 = gv: (name: "max") ; guid = 8185957744030711343 +^5 = gv: (name: "strtol") ; guid = 10216030853587034628 +^6 = gv: (name: "llvm.lifetime.end.p0i8") ; guid = 14311549039910520616 +^7 = gv: (name: "main", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 27, calls: ((callee: ^5), (callee: ^3), (callee: ^4), (callee: ^1), (callee: ^8))))) ; guid = 15822663052811949562 +^8 = gv: (name: "sub2") ; guid = 15968543173600788063 diff --git a/llvm/test/Examples/ThinLtoJIT/Inputs/sub1.ll b/llvm/test/Examples/ThinLtoJIT/Inputs/sub1.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Examples/ThinLtoJIT/Inputs/sub1.ll @@ -0,0 +1,13 @@ +; ModuleID = 'sub1.s' +source_filename = "sub1.c" + +define i32 @sub1(i32 %0) { + %2 = call i32 @workload(i32 %0) + ret i32 %2 +} + +declare i32 @workload(i32) + +^0 = module: (path: "sub1.s", hash: (716800708, 1140043336, 1672117802, 4083982944, 497481660)) +^1 = gv: (name: "workload") ; guid = 2904160244401423009 +^2 = gv: (name: "sub1", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 2, calls: ((callee: ^1))))) ; guid = 6667511020869341723 diff --git a/llvm/test/Examples/ThinLtoJIT/Inputs/sub2.ll b/llvm/test/Examples/ThinLtoJIT/Inputs/sub2.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Examples/ThinLtoJIT/Inputs/sub2.ll @@ -0,0 +1,25 @@ +; ModuleID = 'sub2.s' +source_filename = "sub2.c" + +define i32 @sub2(i32 %0) { + %2 = call i32 @sub21(i32 %0) + %3 = call i32 @max(i32 0, i32 %2) + %4 = add nsw i32 %0, 1 + %5 = call i32 @sub22(i32 %4) + %6 = call i32 @max(i32 %3, i32 %5) + %7 = add nsw i32 %0, 2 + %8 = call i32 @sub23(i32 %7) + %9 = call i32 @max(i32 %6, i32 %8) + ret i32 %9 +} +declare i32 @max(i32, i32) +declare i32 @sub21(i32) +declare i32 @sub22(i32) +declare i32 @sub23(i32) + +^0 = module: (path: "sub2.s", hash: (1967678436, 1954842929, 2113549141, 2651172409, 3315993195)) +^1 = gv: (name: "sub23") ; guid = 1031837926433398383 +^2 = gv: (name: "max") ; guid = 8185957744030711343 +^3 = gv: (name: "sub22") ; guid = 8601446283390290348 +^4 = gv: (name: "sub21") ; guid = 12793086811415836454 +^5 = gv: (name: "sub2", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 9, calls: ((callee: ^4), (callee: ^2), (callee: ^3), (callee: ^1))))) ; guid = 15968543173600788063 diff --git a/llvm/test/Examples/ThinLtoJIT/Inputs/sub21.ll b/llvm/test/Examples/ThinLtoJIT/Inputs/sub21.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Examples/ThinLtoJIT/Inputs/sub21.ll @@ -0,0 +1,13 @@ +; ModuleID = 'sub21.s' +source_filename = "sub21.c" + +define i32 @sub21(i32 %0) { + %2 = call i32 @workload(i32 %0) + ret i32 %2 +} + +declare i32 @workload(i32) + +^0 = module: (path: "sub21.s", hash: (2324013215, 2786549134, 2291471355, 584671689, 2308799624)) +^1 = gv: (name: "workload") ; guid = 2904160244401423009 +^2 = gv: (name: "sub21", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 2, calls: ((callee: ^1))))) ; guid = 12793086811415836454 diff --git a/llvm/test/Examples/ThinLtoJIT/Inputs/sub22.ll b/llvm/test/Examples/ThinLtoJIT/Inputs/sub22.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Examples/ThinLtoJIT/Inputs/sub22.ll @@ -0,0 +1,13 @@ +; ModuleID = 'sub22.s' +source_filename = "sub22.c" + +define i32 @sub22(i32 %0) { + %2 = call i32 @workload(i32 %0) + ret i32 %2 +} + +declare i32 @workload(i32) + +^0 = module: (path: "sub22.s", hash: (4057258347, 3191877851, 3120355814, 3202334300, 790339932)) +^1 = gv: (name: "workload") ; guid = 2904160244401423009 +^2 = gv: (name: "sub22", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 2, calls: ((callee: ^1))))) ; guid = 8601446283390290348 diff --git a/llvm/test/Examples/ThinLtoJIT/Inputs/sub23.ll b/llvm/test/Examples/ThinLtoJIT/Inputs/sub23.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Examples/ThinLtoJIT/Inputs/sub23.ll @@ -0,0 +1,13 @@ +; ModuleID = 'sub23.s' +source_filename = "sub23.c" + +define i32 @sub23(i32 %0) { + %2 = call i32 @workload(i32 %0) + ret i32 %2 +} + +declare i32 @workload(i32) + +^0 = module: (path: "sub23.s", hash: (1187217899, 2239201331, 3030240015, 3752221195, 912650771)) +^1 = gv: (name: "sub23", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 2, calls: ((callee: ^2))))) ; guid = 1031837926433398383 +^2 = gv: (name: "workload") ; guid = 2904160244401423009 diff --git a/llvm/test/Examples/ThinLtoJIT/Inputs/workload.ll b/llvm/test/Examples/ThinLtoJIT/Inputs/workload.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Examples/ThinLtoJIT/Inputs/workload.ll @@ -0,0 +1,78 @@ +; ModuleID = 'workload.s' +source_filename = "workload.c" + +define i32 @max(i32 %0, i32 %1) { + %3 = icmp sgt i32 %0, %1 + %4 = select i1 %3, i32 %0, i32 %1 + ret i32 %4 +} + +define i32 @workload(i32 %0) { + %2 = icmp slt i32 %0, 64 + %3 = select i1 %2, i32 %0, i32 64 + %4 = icmp sgt i32 %3, 1 + br i1 %4, label %5, label %12 + +5: + %6 = phi i32 [ %10, %5 ], [ 1, %1 ] + %7 = phi i64 [ %9, %5 ], [ 1, %1 ] + %8 = phi i64 [ %7, %5 ], [ 0, %1 ] + %9 = add i64 %7, %8 + %10 = add nuw nsw i32 %6, 1 + %11 = icmp slt i32 %10, %3 + br i1 %11, label %5, label %12 + +12: + %13 = phi i64 [ 1, %1 ], [ %9, %5 ] + %14 = call fastcc i32 @fact(i64 %13) + ret i32 %14 +} + +define internal fastcc i32 @fact(i64 %0) { + %2 = icmp ult i64 %0, 2 + br i1 %2, label %26, label %3 + +3: + %4 = phi i32 [ %23, %22 ], [ 0, %1 ] + %5 = phi i64 [ %24, %22 ], [ 2, %1 ] + %6 = urem i64 %0, %5 + %7 = icmp eq i64 %6, 0 + br i1 %7, label %8, label %22 + +8: + %9 = lshr i64 %5, 1 + %10 = icmp ult i64 %5, 4 + br i1 %10, label %18, label %14 + +11: + %12 = add nuw i64 %15, 1 + %13 = icmp ult i64 %15, %9 + br i1 %13, label %14, label %18 + +14: + %15 = phi i64 [ %12, %11 ], [ 2, %8 ] + %16 = urem i64 %5, %15 + %17 = icmp eq i64 %16, 0 + br i1 %17, label %18, label %11 + +18: + %19 = phi i1 [ true, %8 ], [ true, %11 ], [ false, %14 ] + %20 = trunc i64 %5 to i32 + %21 = select i1 %19, i32 %20, i32 %4 + br label %22 + +22: + %23 = phi i32 [ %21, %18 ], [ %4, %3 ] + %24 = add i64 %5, 1 + %25 = icmp ugt i64 %24, %0 + br i1 %25, label %26, label %3 + +26: + %27 = phi i32 [ 0, %1 ], [ %23, %22 ] + ret i32 %27 +} + +^0 = module: (path: "workload.s", hash: (3100996161, 646883963, 3338709300, 3710134105, 1603428348)) +^1 = gv: (name: "workload", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 14, funcFlags: (readNone: 1, readOnly: 0, noRecurse: 1, returnDoesNotAlias: 0, noInline: 0, alwaysInline: 0), calls: ((callee: ^3))))) ; guid = 2904160244401423009 +^2 = gv: (name: "max", summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 0, dsoLocal: 0, canAutoHide: 0), insts: 3, funcFlags: (readNone: 1, readOnly: 0, noRecurse: 1, returnDoesNotAlias: 0, noInline: 0, alwaysInline: 0)))) ; guid = 8185957744030711343 +^3 = gv: (name: "fact", summaries: (function: (module: ^0, flags: (linkage: internal, notEligibleToImport: 0, live: 0, dsoLocal: 1, canAutoHide: 0), insts: 27, funcFlags: (readNone: 1, readOnly: 0, noRecurse: 1, returnDoesNotAlias: 0, noInline: 0, alwaysInline: 0)))) ; guid = 17650377645318605574 diff --git a/llvm/test/Examples/ThinLtoJIT/minimal.test b/llvm/test/Examples/ThinLtoJIT/minimal.test new file mode 100644 --- /dev/null +++ b/llvm/test/Examples/ThinLtoJIT/minimal.test @@ -0,0 +1,12 @@ +# RUN: llvm-as %S/Inputs/main.ll -o main.bc +# RUN: llvm-as %S/Inputs/sub1.ll -o sub1.bc +# RUN: llvm-as %S/Inputs/sub2.ll -o sub2.bc +# RUN: llvm-as %S/Inputs/sub21.ll -o sub21.bc +# RUN: llvm-as %S/Inputs/sub22.ll -o sub22.bc +# RUN: llvm-as %S/Inputs/sub23.ll -o sub23.bc +# RUN: llvm-as %S/Inputs/workload.ll -o workload.bc +# RUN: llvm-lto --thinlto -o index main.bc sub1.bc sub2.bc sub21.bc sub22.bc sub23.bc workload.bc +# RUN: ThinLtoJIT -print-stats index.thinlto.bc 2>&1 | FileCheck %s + +# CHECK: Modules submitted asynchronously: [[#ASYNC:]] +# CHECK: Modules submitted synchronously: [[#6-ASYNC]] diff --git a/llvm/test/Examples/lit.local.cfg b/llvm/test/Examples/lit.local.cfg --- a/llvm/test/Examples/lit.local.cfg +++ b/llvm/test/Examples/lit.local.cfg @@ -1,2 +1,5 @@ if not config.build_examples or sys.platform in ['win32']: - config.unsupported = True \ No newline at end of file + config.unsupported = True + +# Test discovery should ignore subdirectories that contain auxiliary inputs. +config.excludes = ['Inputs']