diff --git a/sources/lib/llvm/tests/llvm-builder-test.dylan b/sources/lib/llvm/tests/llvm-builder-test.dylan index 404f47a5ad..72eb066de8 100644 --- a/sources/lib/llvm/tests/llvm-builder-test.dylan +++ b/sources/lib/llvm/tests/llvm-builder-test.dylan @@ -1028,60 +1028,58 @@ define test test-ins--phi () //---*** Fill this in... end test; -define test test-ins--phi* () - with-test-unit ("ins--phi valid") - let builder = make-builder-with-test-function(); - let entry = builder.llvm-builder-basic-block; - let loop = make(, name: "Loop"); - ins--br(builder, loop); - - ins--block(builder, loop); - let indvar0 - = ins--phi*(builder, - 0, entry, - llvm-builder-local(builder, "nextindvar0"), loop); - let indvar1 - = ins--phi*(builder, - 40, entry, - llvm-builder-local(builder, "nextindvar1"), loop); - ins--local(builder, "nextindvar0", ins--add(builder, indvar0, 1)); - ins--local(builder, "nextindvar1", ins--add(builder, indvar1, 1)); - ins--br(builder, loop); - check-equal("ins--phi disassembly", - #("entry:", - "br label %Loop", - "Loop:", - "%0 = phi i32 [ 0, %entry ], [ %nextindvar0, %Loop ]", - "%1 = phi i32 [ 40, %entry ], [ %nextindvar1, %Loop ]", - "%nextindvar0 = add i32 %0, 1", - "%nextindvar1 = add i32 %1, 1", - "br label %Loop"), - builder-test-function-disassembly(builder)); - end; - - with-test-unit ("ins--phi* invalid") - check-condition - ("ins--phi must be grouped at basic block beginning", - , - begin - let builder = make-builder-with-test-function(); - let entry = builder.llvm-builder-basic-block; - let loop = make(, name: "Loop"); - ins--br(builder, loop); - ins--block(builder, loop); - let indvar0 - = ins--phi*(builder, - 0, entry, - llvm-builder-local(builder, "nextindvar0"), loop); - ins--local(builder, "nextindvar0", ins--add(builder, indvar0, 1)); - let indvar1 - = ins--phi*(builder, - 40, entry, - llvm-builder-local(builder, "nextindvar1"), loop); - ins--local(builder, "nextindvar1", ins--add(builder, indvar1, 1)); - ins--br(builder, loop); - end); - end; +define test test-ins--phi*-valid () + let builder = make-builder-with-test-function(); + let entry = builder.llvm-builder-basic-block; + let loop = make(, name: "Loop"); + ins--br(builder, loop); + + ins--block(builder, loop); + let indvar0 + = ins--phi*(builder, + 0, entry, + llvm-builder-local(builder, "nextindvar0"), loop); + let indvar1 + = ins--phi*(builder, + 40, entry, + llvm-builder-local(builder, "nextindvar1"), loop); + ins--local(builder, "nextindvar0", ins--add(builder, indvar0, 1)); + ins--local(builder, "nextindvar1", ins--add(builder, indvar1, 1)); + ins--br(builder, loop); + check-equal("ins--phi disassembly", + #("entry:", + "br label %Loop", + "Loop:", + "%0 = phi i32 [ 0, %entry ], [ %nextindvar0, %Loop ]", + "%1 = phi i32 [ 40, %entry ], [ %nextindvar1, %Loop ]", + "%nextindvar0 = add i32 %0, 1", + "%nextindvar1 = add i32 %1, 1", + "br label %Loop"), + builder-test-function-disassembly(builder)); +end test; + +define test test-ins--phi*-invalid () + check-condition + ("ins--phi must be grouped at basic block beginning", + , + begin + let builder = make-builder-with-test-function(); + let entry = builder.llvm-builder-basic-block; + let loop = make(, name: "Loop"); + ins--br(builder, loop); + ins--block(builder, loop); + let indvar0 + = ins--phi*(builder, + 0, entry, + llvm-builder-local(builder, "nextindvar0"), loop); + ins--local(builder, "nextindvar0", ins--add(builder, indvar0, 1)); + let indvar1 + = ins--phi*(builder, + 40, entry, + llvm-builder-local(builder, "nextindvar1"), loop); + ins--local(builder, "nextindvar1", ins--add(builder, indvar1, 1)); + ins--br(builder, loop); + end); end test; define test test-ins--call () @@ -1092,59 +1090,59 @@ define test test-ins--tail-call () //---*** Fill this in... end test; -define test test-ins--call-intrinsic () - with-test-unit ("ins--call-intrinsic @llvm.prefetch") - let builder = make-builder-with-test-function(); - let ptr = ins--alloca(builder, $llvm-float-type, 1); - let address = ins--bitcast(builder, ptr, $llvm-i8*-type); - ins--call-intrinsic(builder, "llvm.prefetch", vector(address, 0, 3, 1)); - ins--load(builder, ptr); - ins--ret(builder); - check-equal("ins--call-intrinsic @llvm.prefetch disassembly", - #("entry:", - "%0 = alloca float", - "%1 = bitcast float* %0 to i8*", - "call void @llvm.prefetch(i8* nocapture %1, i32 0, i32 3, i32 1)", - "%2 = load float, float* %0", - "ret void"), - builder-test-function-disassembly(builder)); - end; - with-test-unit ("ins--call-intrinsic float @llvm.sqrt") - let builder = make-builder-with-test-function(); - ins--call-intrinsic(builder, "llvm.sqrt", vector(2.0s0)); - ins--ret(builder); - check-equal("ins--call-intrinsic @llvm.sqrt disassembly", - #("entry:", - "%0 = call float @llvm.sqrt.f32(float 2.000000e+00)" - " nounwind readonly", - "ret void"), - builder-test-function-disassembly(builder)); - end; - with-test-unit ("ins--call-intrinsic i8 @llvm.memcpy") - let builder = make-builder-with-test-function(); - let ptr1 = ins--alloca(builder, $llvm-i8-type, 20); - let ptr2 = ins--alloca(builder, $llvm-i8-type, 20); - let ptr3 = ins--alloca(builder, $llvm-i8-type, 20); - ins--call-intrinsic(builder, "llvm.memcpy", - vector(ptr1, ptr2, 20, $llvm-false)); - ins--call-intrinsic(builder, "llvm.memcpy", - vector(ptr2, ptr3, 20, $llvm-false)); - ins--ret(builder); - - check-equal("ins--call-intrinsic @llvm.memcpy disassembly", - #("entry:", - "%0 = alloca i8, i32 20", - "%1 = alloca i8, i32 20", - "%2 = alloca i8, i32 20", - "call void @llvm.memcpy.p0i8.p0i8.i32" - "(i8* nocapture %0, i8* nocapture %1, i32 20," - " i1 false) nounwind", - "call void @llvm.memcpy.p0i8.p0i8.i32" - "(i8* nocapture %1, i8* nocapture %2, i32 20," - " i1 false) nounwind", - "ret void"), - builder-test-function-disassembly(builder)); - end; +define test test-ins--call-intrinsic-@llvm-prefetch () + let builder = make-builder-with-test-function(); + let ptr = ins--alloca(builder, $llvm-float-type, 1); + let address = ins--bitcast(builder, ptr, $llvm-i8*-type); + ins--call-intrinsic(builder, "llvm.prefetch", vector(address, 0, 3, 1)); + ins--load(builder, ptr); + ins--ret(builder); + check-equal("ins--call-intrinsic @llvm.prefetch disassembly", + #("entry:", + "%0 = alloca float", + "%1 = bitcast float* %0 to i8*", + "call void @llvm.prefetch(i8* nocapture %1, i32 0, i32 3, i32 1)", + "%2 = load float, float* %0", + "ret void"), + builder-test-function-disassembly(builder)); +end test; + +define test test-ins--call-intrinsic-float-@llvm-sqrt () + let builder = make-builder-with-test-function(); + ins--call-intrinsic(builder, "llvm.sqrt", vector(2.0s0)); + ins--ret(builder); + check-equal("ins--call-intrinsic @llvm.sqrt disassembly", + #("entry:", + "%0 = call float @llvm.sqrt.f32(float 2.000000e+00)" + " nounwind readonly", + "ret void"), + builder-test-function-disassembly(builder)); +end test; + +define test test-ins--call-intrinsic-i8-@llvm-memcpy () + let builder = make-builder-with-test-function(); + let ptr1 = ins--alloca(builder, $llvm-i8-type, 20); + let ptr2 = ins--alloca(builder, $llvm-i8-type, 20); + let ptr3 = ins--alloca(builder, $llvm-i8-type, 20); + ins--call-intrinsic(builder, "llvm.memcpy", + vector(ptr1, ptr2, 20, $llvm-false)); + ins--call-intrinsic(builder, "llvm.memcpy", + vector(ptr2, ptr3, 20, $llvm-false)); + ins--ret(builder); + + check-equal("ins--call-intrinsic @llvm.memcpy disassembly", + #("entry:", + "%0 = alloca i8, i32 20", + "%1 = alloca i8, i32 20", + "%2 = alloca i8, i32 20", + "call void @llvm.memcpy.p0i8.p0i8.i32" + "(i8* nocapture %0, i8* nocapture %1, i32 20," + " i1 false) nounwind", + "call void @llvm.memcpy.p0i8.p0i8.i32" + "(i8* nocapture %1, i8* nocapture %2, i32 20," + " i1 false) nounwind", + "ret void"), + builder-test-function-disassembly(builder)); end test; define test test-ins--alloca () @@ -1514,201 +1512,196 @@ define test test-ins--landingpad () builder-test-function-disassembly(builder)); end test; -define test test-ins--if () - with-test-unit ("ins--if, no else, no value") - let builder = make-builder-with-test-function(); +define test test-ins--if--no-else-no-value () + let builder = make-builder-with-test-function(); + + let float-type = make(, kind: #"FLOAT"); + let ptr = ins--alloca(builder, float-type, 1, alignment: 4); + + let cmp = ins--icmp-uge(builder, 1, 2); + ins--if(builder, cmp) + ins--store(builder, 1.0s0, ptr, alignment: 4); + end ins--if; - let float-type = make(, kind: #"FLOAT"); - let ptr = ins--alloca(builder, float-type, 1, alignment: 4); + check-equal("ins--if disassembly", + #("entry:", + "%0 = alloca float, align 4", + "%1 = icmp uge i32 1, 2", + "br i1 %1, label %2, label %3", + "store float 1.000000e+00, float* %0, align 4", + "br label %3"), + builder-test-function-disassembly(builder)); +end test; - let cmp = ins--icmp-uge(builder, 1, 2); - ins--if(builder, cmp) - ins--store(builder, 1.0s0, ptr, alignment: 4); - end ins--if; +define test test-ins--if--with-else-no-value () + let builder = make-builder-with-test-function(); - check-equal("ins--if disassembly", - #("entry:", - "%0 = alloca float, align 4", - "%1 = icmp uge i32 1, 2", - "br i1 %1, label %2, label %3", - "store float 1.000000e+00, float* %0, align 4", - "br label %3"), - builder-test-function-disassembly(builder)); - end; + let float-type = make(, kind: #"FLOAT"); + let ptr = ins--alloca(builder, float-type, 1, alignment: 4); - with-test-unit ("ins--if with else, no value") - let builder = make-builder-with-test-function(); + let cmp = ins--icmp-uge(builder, 1, 2); + ins--if(builder, cmp) + ins--store(builder, 1.0s0, ptr, alignment: 4); + ins--else + ins--store(builder, 2.0s0, ptr, alignment: 4); + end ins--if; - let float-type = make(, kind: #"FLOAT"); - let ptr = ins--alloca(builder, float-type, 1, alignment: 4); + check-equal("ins--if disassembly", + #("entry:", + "%0 = alloca float, align 4", + "%1 = icmp uge i32 1, 2", + "br i1 %1, label %2, label %3", + "store float 1.000000e+00, float* %0, align 4", + "br label %4", + "store float 2.000000e+00, float* %0, align 4", + "br label %4"), + builder-test-function-disassembly(builder)); +end test; - let cmp = ins--icmp-uge(builder, 1, 2); - ins--if(builder, cmp) - ins--store(builder, 1.0s0, ptr, alignment: 4); - ins--else - ins--store(builder, 2.0s0, ptr, alignment: 4); - end ins--if; - - check-equal("ins--if disassembly", - #("entry:", - "%0 = alloca float, align 4", - "%1 = icmp uge i32 1, 2", - "br i1 %1, label %2, label %3", - "store float 1.000000e+00, float* %0, align 4", - "br label %4", - "store float 2.000000e+00, float* %0, align 4", - "br label %4"), - builder-test-function-disassembly(builder)); - end; - - with-test-unit ("ins--if, no else, with value") - let builder = make-builder-with-test-function(); - - let cmp = ins--icmp-uge(builder, 1, 2); - ins--if(builder, cmp) - ins--add(builder, 1111, 2222); - end ins--if; - - check-equal("ins--if disassembly", - #("entry:", - "%0 = icmp uge i32 1, 2", - "br i1 %0, label %1, label %3", - "%2 = add i32 1111, 2222", - "br label %3", - "%4 = phi i32 [ %2, %1 ], [ undef, %entry ]"), - builder-test-function-disassembly(builder)); - end; - - with-test-unit ("ins--if with else, with value") - let builder = make-builder-with-test-function(); - - let cmp = ins--icmp-uge(builder, 1, 2); - ins--if(builder, cmp) - ins--add(builder, 1111, 2222); - ins--else - ins--add(builder, 3333, 4444); - end ins--if; - - check-equal("ins--if disassembly", - #("entry:", - "%0 = icmp uge i32 1, 2", - "br i1 %0, label %1, label %3", - "%2 = add i32 1111, 2222", - "br label %5", - "%4 = add i32 3333, 4444", - "br label %5", - "%6 = phi i32 [ %2, %1 ], [ %4, %3 ]"), - builder-test-function-disassembly(builder)); - end; - - with-test-unit ("ins--if with else, no fall-through") - let builder = make-builder-with-test-function(); - - let cmp = ins--icmp-uge(builder, 1, 2); - ins--if(builder, cmp) - ins--add(builder, 1111, 2222); - ins--else - ins--call-intrinsic(builder, "llvm.trap", vector()); - ins--unreachable(builder); - end ins--if; - - check-equal("ins--if disassembly", - #("entry:", - "%0 = icmp uge i32 1, 2", - "br i1 %0, label %1, label %3", - "%2 = add i32 1111, 2222", - "br label %4", - "call void @llvm.trap() #1", - "unreachable"), - builder-test-function-disassembly(builder)); - end; - - with-test-unit ("ins--if with else, no successor block") - let builder = make-builder-with-test-function(); - - let cmp = ins--icmp-uge(builder, 1, 2); - ins--if(builder, cmp) - ins--call-intrinsic(builder, "llvm.trap", vector()); - ins--unreachable(builder); +define test test-ins--if--no-else-with-value () + let builder = make-builder-with-test-function(); + + let cmp = ins--icmp-uge(builder, 1, 2); + ins--if(builder, cmp) + ins--add(builder, 1111, 2222); + end ins--if; + + check-equal("ins--if disassembly", + #("entry:", + "%0 = icmp uge i32 1, 2", + "br i1 %0, label %1, label %3", + "%2 = add i32 1111, 2222", + "br label %3", + "%4 = phi i32 [ %2, %1 ], [ undef, %entry ]"), + builder-test-function-disassembly(builder)); +end test; + +define test test-ins--if--with-else-with-value () + let builder = make-builder-with-test-function(); + + let cmp = ins--icmp-uge(builder, 1, 2); + ins--if(builder, cmp) + ins--add(builder, 1111, 2222); + ins--else + ins--add(builder, 3333, 4444); + end ins--if; + + check-equal("ins--if disassembly", + #("entry:", + "%0 = icmp uge i32 1, 2", + "br i1 %0, label %1, label %3", + "%2 = add i32 1111, 2222", + "br label %5", + "%4 = add i32 3333, 4444", + "br label %5", + "%6 = phi i32 [ %2, %1 ], [ %4, %3 ]"), + builder-test-function-disassembly(builder)); +end test; + +define test test-ins--if--with-else-no-fall-through () + let builder = make-builder-with-test-function(); + + let cmp = ins--icmp-uge(builder, 1, 2); + ins--if(builder, cmp) + ins--add(builder, 1111, 2222); + ins--else + ins--call-intrinsic(builder, "llvm.trap", vector()); + ins--unreachable(builder); + end ins--if; + + check-equal("ins--if disassembly", + #("entry:", + "%0 = icmp uge i32 1, 2", + "br i1 %0, label %1, label %3", + "%2 = add i32 1111, 2222", + "br label %4", + "call void @llvm.trap() #1", + "unreachable"), + builder-test-function-disassembly(builder)); +end test; + +define test test-ins--if--with-else-no-successor-block () + let builder = make-builder-with-test-function(); + + let cmp = ins--icmp-uge(builder, 1, 2); + ins--if(builder, cmp) + ins--call-intrinsic(builder, "llvm.trap", vector()); + ins--unreachable(builder); + ins--else + ins--call-intrinsic(builder, "llvm.trap", vector()); + ins--unreachable(builder); + end ins--if; + check-false("no active block", builder.llvm-builder-basic-block); + + check-equal("ins--if disassembly", + #("entry:", + "%0 = icmp uge i32 1, 2", + "br i1 %0, label %1, label %2", + "call void @llvm.trap() #1", + "unreachable", + "call void @llvm.trap() #1", + "unreachable"), + builder-test-function-disassembly(builder)); +end test; + +define test test-ins--iterate--no-loop-variables() + let builder = make-builder-with-test-function(); + + ins--iterate loop (builder) + ins--call-intrinsic(builder, "llvm.trap", vector()); + loop(); + end ins--iterate; + + check-equal("ins--iterate disassembly", + #("entry:", + "br label %0", + "call void @llvm.trap() #1", + "br label %0"), + builder-test-function-disassembly(builder)); +end test; + +define test test-ins--iterate--one-loop-variable () + let builder = make-builder-with-test-function(); + + ins--iterate loop (builder, a = 0) + loop(ins--add(builder, a, 1)); + end ins--iterate; + + check-equal("ins--iterate disassembly", + #("entry:", + "br label %0", + "%1 = phi i32 [ 0, %entry ], [ %2, %0 ]", + "%2 = add i32 %1, 1", + "br label %0"), + builder-test-function-disassembly(builder)); +end test; + +define test test-ins--iterate--two-loop-variables-and-complex-control-flow () + let builder = make-builder-with-test-function(); + + ins--iterate loop (builder, sum = 0, i = 0) + let cmp = ins--icmp-ult(builder, i, 14); + ins--if (builder, cmp) + let sum = ins--add(builder, sum, i); + let inc = ins--add(builder, i, 1); + loop(sum, inc) ins--else - ins--call-intrinsic(builder, "llvm.trap", vector()); - ins--unreachable(builder); - end ins--if; - check-false("no active block", builder.llvm-builder-basic-block); - - check-equal("ins--if disassembly", - #("entry:", - "%0 = icmp uge i32 1, 2", - "br i1 %0, label %1, label %2", - "call void @llvm.trap() #1", - "unreachable", - "call void @llvm.trap() #1", - "unreachable"), - builder-test-function-disassembly(builder)); - end; -end test; - -define test test-ins--iterate() - with-test-unit ("ins--iterate with no loop variables") - let builder = make-builder-with-test-function(); - - ins--iterate loop (builder) - ins--call-intrinsic(builder, "llvm.trap", vector()); - loop(); - end ins--iterate; - - check-equal("ins--iterate disassembly", - #("entry:", - "br label %0", - "call void @llvm.trap() #1", - "br label %0"), - builder-test-function-disassembly(builder)); - end; - - with-test-unit ("ins--iterate with one loop variable") - let builder = make-builder-with-test-function(); - - ins--iterate loop (builder, a = 0) - loop(ins--add(builder, a, 1)); - end ins--iterate; - - check-equal("ins--iterate disassembly", - #("entry:", - "br label %0", - "%1 = phi i32 [ 0, %entry ], [ %2, %0 ]", - "%2 = add i32 %1, 1", - "br label %0"), - builder-test-function-disassembly(builder)); - end; - - with-test-unit ("ins--iterate with two loop variable and complex control flow") - let builder = make-builder-with-test-function(); - - ins--iterate loop (builder, sum = 0, i = 0) - let cmp = ins--icmp-ult(builder, i, 14); - ins--if (builder, cmp) - let sum = ins--add(builder, sum, i); - let inc = ins--add(builder, i, 1); - loop(sum, inc) - ins--else - sum - end ins--if - end ins--iterate; - - check-equal("ins--iterate disassembly", - #("entry:", - "br label %0", - "%1 = phi i32 [ 0, %entry ], [ %5, %4 ]", - "%2 = phi i32 [ 0, %entry ], [ %6, %4 ]", - "%3 = icmp ult i32 %2, 14", - "br i1 %3, label %4, label %7", - "%5 = add i32 %1, %2", - "%6 = add i32 %2, 1", - "br label %0", - "br label %8"), - builder-test-function-disassembly(builder)); - end; + sum + end ins--if + end ins--iterate; + check-equal("ins--iterate disassembly", + #("entry:", + "br label %0", + "%1 = phi i32 [ 0, %entry ], [ %5, %4 ]", + "%2 = phi i32 [ 0, %entry ], [ %6, %4 ]", + "%3 = icmp ult i32 %2, 14", + "br i1 %3, label %4, label %7", + "%5 = add i32 %1, %2", + "%6 = add i32 %2, 1", + "br label %0", + "br label %8"), + builder-test-function-disassembly(builder)); end test; define suite llvm-builder-test-suite () @@ -1791,10 +1784,13 @@ define suite llvm-builder-test-suite () test test-ins--insertelement; test test-ins--shufflevector; test test-ins--phi; - test test-ins--phi*; + test test-ins--phi*-valid; + test test-ins--phi*-invalid; test test-ins--call; test test-ins--tail-call; - test test-ins--call-intrinsic; + test test-ins--call-intrinsic-@llvm-prefetch + test test-ins--call-intrinsic-float-@llvm-sqrt + test test-ins--call-intrinsic-i8-@llvm-memcpy; test test-ins--alloca; test test-ins--load; test test-ins--store; @@ -1821,6 +1817,13 @@ define suite llvm-builder-test-suite () test test-ins--resume; test test-ins--unreachable; test test-ins--landingpad; - test test-ins--if; - test test-ins--iterate; + test test-ins--if--no-else-no-value; + test test-ins--if--with-else-no-value; + test test-ins--if--no-else-with-value; + test test-ins--if--with-else-with-value; + test test-ins--if--with-else-no-fall-through; + test test-ins--if--with-else-no-successor-block; + test test-ins--iterate--no-loop-variables; + test test-ins--iterate--one-loop-variable; + test test-ins--iterate--two-loop-variables-and-complex-control-flow; end suite;