brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.8 KiB · 4a3684e Raw
176 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-cir -mmlir --mlir-print-ir-before=cir-lowering-prepare %s -o %t.cir  2> %t-before-lp.cir2// RUN: FileCheck --input-file=%t-before-lp.cir %s -check-prefix=CIR-BEFORE-LPP3// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR4// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -fclangir -emit-llvm %s -o %t-cir.ll5// RUN: FileCheck --input-file=%t-cir.ll %s -check-prefix=LLVM6// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -Wno-unused-value -emit-llvm %s -o %t.ll7// RUN: FileCheck --input-file=%t.ll %s -check-prefix=OGCG8 9struct S {10    ~S();11};12 13void test_cleanup_array() {14    S s[42];15}16 17// CIR-BEFORE-LPP: cir.func{{.*}} @_Z18test_cleanup_arrayv()18// CIR-BEFORE-LPP:   %[[S:.*]] = cir.alloca !cir.array<!rec_S x 42>, !cir.ptr<!cir.array<!rec_S x 42>>, ["s"]19// CIR-BEFORE-LPP:   cir.array.dtor %[[S]] : !cir.ptr<!cir.array<!rec_S x 42>> {20// CIR-BEFORE-LPP:   ^bb0(%arg0: !cir.ptr<!rec_S>21// CIR-BEFORE-LPP:     cir.call @_ZN1SD1Ev(%arg0) nothrow : (!cir.ptr<!rec_S>) -> ()22// CIR-BEFORE-LPP:     cir.yield23// CIR-BEFORE-LPP:   }24// CIR-BEFORE-LPP:   cir.return25 26// CIR: cir.func{{.*}} @_Z18test_cleanup_arrayv()27// CIR:   %[[S:.*]] = cir.alloca !cir.array<!rec_S x 42>, !cir.ptr<!cir.array<!rec_S x 42>>, ["s"]28// CIR:   %[[CONST41:.*]] = cir.const #cir.int<41> : !u64i29// CIR:   %[[DECAY:.*]] = cir.cast array_to_ptrdecay %[[S]] : !cir.ptr<!cir.array<!rec_S x 42>> -> !cir.ptr<!rec_S>30// CIR:   %[[END_PTR:.*]] = cir.ptr_stride %[[DECAY]], %[[CONST41]] : (!cir.ptr<!rec_S>, !u64i) -> !cir.ptr<!rec_S>31// CIR:   %[[ITER:.*]] = cir.alloca !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>, ["__array_idx"]32// CIR:   cir.store %[[END_PTR]], %[[ITER]] : !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>33// CIR:   cir.do {34// CIR:     %[[CURRENT:.*]] = cir.load %[[ITER]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S>35// CIR:     cir.call @_ZN1SD1Ev(%[[CURRENT]]) nothrow : (!cir.ptr<!rec_S>) -> ()36// CIR:     %[[CONST_MINUS1:.*]] = cir.const #cir.int<-1> : !s64i37// CIR:     %[[NEXT:.*]] = cir.ptr_stride %[[CURRENT]], %[[CONST_MINUS1]] : (!cir.ptr<!rec_S>, !s64i) -> !cir.ptr<!rec_S>38// CIR:     cir.store %[[NEXT]], %[[ITER]] : !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>39// CIR:     cir.yield40// CIR:   } while {41// CIR:     %[[CURRENT2:.*]] = cir.load %[[ITER]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S>42// CIR:     %[[CMP:.*]] = cir.cmp(ne, %[[CURRENT2]], %[[DECAY]])43// CIR:     cir.condition(%[[CMP]])44// CIR:   }45// CIR:   cir.return46 47// LLVM: define{{.*}} void @_Z18test_cleanup_arrayv()48// LLVM:   %[[ARRAY:.*]] = alloca [42 x %struct.S]49// LLVM:   %[[START:.*]] = getelementptr %struct.S, ptr %[[ARRAY]], i32 050// LLVM:   %[[END:.*]] = getelementptr %struct.S, ptr %[[START]], i64 4151// LLVM:   %[[ITER:.*]] = alloca ptr52// LLVM:   store ptr %[[END]], ptr %[[ITER]]53// LLVM:   br label %[[LOOP:.*]]54// LLVM: [[COND:.*]]:55// LLVM:   %[[CURRENT_CHECK:.*]] = load ptr, ptr %[[ITER]]56// LLVM:   %[[DONE:.*]] = icmp ne ptr %[[CURRENT_CHECK]], %[[START]]57// LLVM:   br i1 %[[DONE]], label %[[LOOP]], label %[[EXIT:.*]]58// LLVM: [[LOOP]]:59// LLVM:   %[[CURRENT:.*]] = load ptr, ptr %[[ITER]]60// LLVM:   call void @_ZN1SD1Ev(ptr %[[CURRENT]])61// LLVM:   %[[NEXT:.*]] = getelementptr %struct.S, ptr %[[CURRENT]], i64 -162// LLVM:   store ptr %[[NEXT]], ptr %[[ITER]]63// LLVM:   br label %[[COND]]64// LLVM: [[EXIT]]:65// LLVM:   ret void66 67// OGCG: define{{.*}} void @_Z18test_cleanup_arrayv()68// OGCG:   %[[ARRAY:.*]] = alloca [42 x %struct.S]69// OGCG:   %[[START:.*]] = getelementptr{{.*}} %struct.S{{.*}}70// OGCG:   %[[END:.*]] = getelementptr{{.*}} %struct.S{{.*}} i64 4271// OGCG:   br label %[[LOOP:.*]]72// OGCG: [[LOOP]]:73// OGCG:   %[[NEXT:.*]] = phi ptr [ %[[END]], %{{.*}} ], [ %[[LAST:.*]], %[[LOOP]] ]74// OGCG:   %[[LAST]] = getelementptr{{.*}} %struct.S{{.*}}, ptr %[[NEXT]], i64 -175// OGCG:   call void @_ZN1SD1Ev(ptr{{.*}} %[[LAST]])76// OGCG:   %[[DONE:.*]] = icmp eq ptr %[[LAST]], %[[START]]77// OGCG:   br i1 %[[DONE]], label %[[EXIT:.*]], label %[[LOOP]]78// OGCG: [[EXIT]]:79// OGCG:   ret void80 81void test_cleanup_zero_length_array() {82    S s[0];83}84 85// CIR-BEFORE-LPP:     cir.func{{.*}} @_Z30test_cleanup_zero_length_arrayv()86// CIR-BEFORE-LPP:       %[[S:.*]] = cir.alloca !cir.array<!rec_S x 0>, !cir.ptr<!cir.array<!rec_S x 0>>, ["s"]87// CIR-BEFORE-LPP-NOT:   cir.array.dtor88// CIR-BEFORE-LPP:       cir.return89 90// CIR:     cir.func{{.*}} @_Z30test_cleanup_zero_length_arrayv()91// CIR:       %[[S:.*]] = cir.alloca !cir.array<!rec_S x 0>, !cir.ptr<!cir.array<!rec_S x 0>>, ["s"]92// CIR-NOT:   cir.do93// CIR-NOT:   cir.call @_ZN1SD1Ev94// CIR:       cir.return95 96// LLVM:     define{{.*}} void @_Z30test_cleanup_zero_length_arrayv()97// LLVM:       alloca [0 x %struct.S]98// LLVM-NOT:   call void @_ZN1SD1Ev99// LLVM:       ret void100 101// OGCG:     define{{.*}} void @_Z30test_cleanup_zero_length_arrayv()102// OGCG:       alloca [0 x %struct.S]103// OGCG-NOT:   call void @_ZN1SD1Ev104// OGCG:       ret void105 106void multi_dimensional() {107    S s[3][5];108}109 110// CIR-BEFORE-LPP:     cir.func{{.*}} @_Z17multi_dimensionalv()111// CIR-BEFORE-LPP:       %[[S:.*]] = cir.alloca !cir.array<!cir.array<!rec_S x 5> x 3>, !cir.ptr<!cir.array<!cir.array<!rec_S x 5> x 3>>, ["s"]112// CIR-BEFORE-LPP:       %[[FLAT:.*]] = cir.cast bitcast %[[S]] : !cir.ptr<!cir.array<!cir.array<!rec_S x 5> x 3>> -> !cir.ptr<!cir.array<!rec_S x 15>>113// CIR-BEFORE-LPP:       cir.array.dtor %[[FLAT]] : !cir.ptr<!cir.array<!rec_S x 15>> {114// CIR-BEFORE-LPP:       ^bb0(%[[ARG:.*]]: !cir.ptr<!rec_S>):115// CIR-BEFORE-LPP:         cir.call @_ZN1SD1Ev(%[[ARG]]) nothrow : (!cir.ptr<!rec_S>) -> ()116// CIR-BEFORE-LPP:         cir.yield117// CIR-BEFORE-LPP:       }118// CIR-BEFORE-LPP:       cir.return119 120// CIR:     cir.func{{.*}} @_Z17multi_dimensionalv()121// CIR:       %[[S:.*]] = cir.alloca !cir.array<!cir.array<!rec_S x 5> x 3>, !cir.ptr<!cir.array<!cir.array<!rec_S x 5> x 3>>, ["s"]122// CIR:       %[[FLAT:.*]] = cir.cast bitcast %[[S]] : !cir.ptr<!cir.array<!cir.array<!rec_S x 5> x 3>> -> !cir.ptr<!cir.array<!rec_S x 15>>123// CIR:       %[[CONST14:.*]] = cir.const #cir.int<14> : !u64i124// CIR:       %[[DECAY:.*]] = cir.cast array_to_ptrdecay %[[FLAT]] : !cir.ptr<!cir.array<!rec_S x 15>> -> !cir.ptr<!rec_S>125// CIR:       %[[END_PTR:.*]] = cir.ptr_stride %[[DECAY]], %[[CONST14]] : (!cir.ptr<!rec_S>, !u64i) -> !cir.ptr<!rec_S>126// CIR:       %[[ITER:.*]] = cir.alloca !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>, ["__array_idx"]127// CIR:       cir.store %[[END_PTR]], %[[ITER]] : !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>128// CIR:       cir.do {129// CIR:         %[[CUR:.*]] = cir.load %[[ITER]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S>130// CIR:         cir.call @_ZN1SD1Ev(%[[CUR]]) nothrow : (!cir.ptr<!rec_S>) -> ()131// CIR:         %[[NEG1:.*]] = cir.const #cir.int<-1> : !s64i132// CIR:         %[[PREV:.*]] = cir.ptr_stride %[[CUR]], %[[NEG1]] : (!cir.ptr<!rec_S>, !s64i) -> !cir.ptr<!rec_S>133// CIR:         cir.store %[[PREV]], %[[ITER]] : !cir.ptr<!rec_S>, !cir.ptr<!cir.ptr<!rec_S>>134// CIR:         cir.yield135// CIR:       } while {136// CIR:         %[[CHK:.*]] = cir.load %[[ITER]] : !cir.ptr<!cir.ptr<!rec_S>>, !cir.ptr<!rec_S>137// CIR:         %[[CMP:.*]] = cir.cmp(ne, %[[CHK]], %[[DECAY]])138// CIR:         cir.condition(%[[CMP]])139// CIR:       }140// CIR:       cir.return141 142// LLVM:     define{{.*}} void @_Z17multi_dimensionalv()143// LLVM:       %[[S:.*]] = alloca [3 x [5 x %struct.S]]144// LLVM:       %[[START:.*]] = getelementptr %struct.S, ptr %[[S]], i32 0145// LLVM:       %[[END:.*]] = getelementptr %struct.S, ptr %[[START]], i64 14146// LLVM:       %[[ITER:.*]] = alloca ptr147// LLVM:       store ptr %[[END]], ptr %[[ITER]]148// LLVM:       br label %[[LOOP:.*]]149// LLVM: [[COND:.*]]:150// LLVM:       %[[CURRENT_CHECK:.*]] = load ptr, ptr %[[ITER]]151// LLVM:       %[[DONE:.*]] = icmp ne ptr %[[CURRENT_CHECK]], %[[START]]152// LLVM:       br i1 %[[DONE]], label %[[LOOP]], label %[[EXIT:.*]]153// LLVM: [[LOOP]]:154// LLVM:       %[[CUR:.*]] = load ptr, ptr %[[ITER]]155// LLVM:       call void @_ZN1SD1Ev(ptr %[[CUR]])156// LLVM:       %[[PREV:.*]] = getelementptr %struct.S, ptr %[[CUR]], i64 -1157// LLVM:       store ptr %[[PREV]], ptr %[[ITER]]158// LLVM:       br label %[[COND]]159// LLVM: [[EXIT]]:160// LLVM:       ret void161 162// OGCG:     define{{.*}} void @_Z17multi_dimensionalv()163// OGCG:       %[[ARRAY:.*]] = alloca [3 x [5 x %struct.S]]164// OGCG:       %[[START:.*]] = getelementptr{{.*}} %struct.S{{.*}}165// OGCG:       %[[END:.*]] = getelementptr{{.*}} %struct.S{{.*}} i64 15166// OGCG:       br label %[[LOOP:.*]]167// OGCG: [[LOOP]]:168// OGCG:       %[[NEXT:.*]] = phi ptr [ %[[END]], %{{.*}} ], [ %[[LAST:.*]], %[[LOOP]] ]169// OGCG:       %[[LAST]] = getelementptr{{.*}} %struct.S{{.*}}, ptr %[[NEXT]], i64 -1170// OGCG:       call void @_ZN1SD1Ev(ptr{{.*}} %[[LAST]])171// OGCG:       %[[DONE:.*]] = icmp eq ptr %[[LAST]], %[[START]]172// OGCG:       br i1 %[[DONE]], label %[[EXIT:.*]], label %[[LOOP]]173// OGCG: [[EXIT]]:174// OGCG:       ret void175 176