|
| 1 | +#include "cuda.h" |
| 2 | + |
| 3 | +// RUN: echo "sample fatbin" > %t.fatbin |
| 4 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir \ |
| 5 | +// RUN: -x hip -emit-cir -fhip-new-launch-api -I%S/../Inputs/ \ |
| 6 | +// RUN: -fcuda-include-gpubinary %t.fatbin \ |
| 7 | +// RUN: %s -o %t.cir |
| 8 | +// RUN: FileCheck --check-prefix=CIR-HOST --input-file=%t.cir %s |
| 9 | + |
| 10 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir \ |
| 11 | +// RUN: -x hip -emit-llvm -fhip-new-launch-api -I%S/../Inputs/ \ |
| 12 | +// RUN: -fcuda-include-gpubinary %t.fatbin \ |
| 13 | +// RUN: %s -o %t.ll |
| 14 | +// RUN: FileCheck --check-prefix=LLVM-HOST --input-file=%t.ll %s |
| 15 | + |
| 16 | +// OGCG emits LLVM IR in different order than clangir, we add at the end the order of OGCG. |
| 17 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu \ |
| 18 | +// RUN: -x hip -emit-llvm -fhip-new-launch-api -I%S/../Inputs/ \ |
| 19 | +// RUN: -fcuda-include-gpubinary %t.fatbin \ |
| 20 | +// RUN: %s -o %t.ll |
| 21 | +// RUN: FileCheck --check-prefix=OGCG-HOST --input-file=%t.ll %s |
| 22 | + |
| 23 | + |
| 24 | +// CIR-HOST: module @"{{.*}}" attributes { |
| 25 | +// CIR-HOST: cir.cu.binary_handle = #cir.cu.binary_handle<{{.*}}.fatbin>, |
| 26 | +// CIR-HOST: cir.global_ctors = [#cir.global_ctor<"__hip_module_ctor", {{[0-9]+}}>] |
| 27 | +// CIR-HOST: } |
| 28 | + |
| 29 | +// LLVM-HOST: @.str_Z2fnv = private constant [7 x i8] c"_Z2fnv\00" |
| 30 | +// LLVM-HOST: @__hip_fatbin_str = private constant [14 x i8] c"sample fatbin\0A", section ".hip_fatbin" |
| 31 | +// LLVM-HOST: @__hip_fatbin_wrapper = internal constant { |
| 32 | +// LLVM-HOST: i32 1212764230, i32 1, ptr @__hip_fatbin_str, ptr null |
| 33 | +// LLVM-HOST: }, section ".hipFatBinSegment" |
| 34 | +// LLVM-HOST: @_Z2fnv = constant ptr @_Z17__device_stub__fnv, align 8 |
| 35 | +// LLVM-HOST: @llvm.global_ctors = {{.*}}ptr @__hip_module_ctor |
| 36 | + |
| 37 | +// CIR-HOST: cir.func internal private @__hip_module_dtor() { |
| 38 | +// CIR-HOST: %[[#HandleGlobal:]] = cir.get_global @__hip_gpubin_handle |
| 39 | +// CIR-HOST: %[[#HandleAddr:]] = cir.load %[[#HandleGlobal]] : !cir.ptr<!cir.ptr<!cir.ptr<!void>>>, !cir.ptr<!cir.ptr<!void>> loc(#loc) |
| 40 | +// CIR-HOST: %[[#NullVal:]] = cir.const #cir.ptr<null> : !cir.ptr<!cir.ptr<!void>> loc(#loc) |
| 41 | +// CIR-HOST: %3 = cir.cmp(ne, %[[#HandleAddr]], %[[#NullVal]]) : !cir.ptr<!cir.ptr<!void>>, !cir.bool loc(#loc) |
| 42 | +// CIR-HOST: cir.brcond %3 ^bb1, ^bb2 loc(#loc) |
| 43 | +// CIR-HOST: ^bb1: |
| 44 | +// CIR-HOST: cir.call @__hipUnregisterFatBinary(%[[#HandleAddr]]) : (!cir.ptr<!cir.ptr<!void>>) -> () loc(#loc) |
| 45 | +// CIR-HOST: %[[#HandleAddr:]] = cir.get_global @__hip_gpubin_handle : !cir.ptr<!cir.ptr<!cir.ptr<!void>>> loc(#loc) |
| 46 | +// CIR-HOST: cir.store %[[#NullVal]], %[[#HandleAddr]] : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!cir.ptr<!cir.ptr<!void>>> loc(#loc) |
| 47 | +// CIR-HOST: cir.br ^bb2 loc(#loc) |
| 48 | +// CIR-HOST: ^bb2: // 2 preds: ^bb0, ^bb1 |
| 49 | +// CIR-HOST: cir.return loc(#loc) |
| 50 | +// CIR-HOST: } loc(#loc) |
| 51 | + |
| 52 | +// LLVM-HOST: define internal void @__hip_module_dtor() { |
| 53 | +// LLVM-HOST: %[[#LLVMHandleVar:]] = load ptr, ptr @__hip_gpubin_handle, align 8 |
| 54 | +// LLVM-HOST: %[[#ICMP:]] = icmp ne ptr %[[#LLVMHandleVar]], null |
| 55 | +// LLVM-HOST: br i1 %[[#ICMP]], label %[[IFBLOCK:[^,]+]], label %[[EXITBLOCK:[^,]+]] |
| 56 | +// LLVM-HOST: [[IFBLOCK]]: ; preds = %0 |
| 57 | +// LLVM-HOST: call void @__hipUnregisterFatBinary(ptr %[[#LLVMHandleVar]]) |
| 58 | +// LLVM-HOST: store ptr null, ptr @__hip_gpubin_handle, align 8 |
| 59 | +// LLVM-HOST: br label %[[EXITBLOCK]] |
| 60 | +// LLVM-HOST: [[EXITBLOCK]]: ; preds = %[[IFBLOCK]], %0 |
| 61 | +// LLVM-HOST: ret void |
| 62 | +// LLVM-HOST: } |
| 63 | + |
| 64 | +// CIR-HOST: cir.global "private" constant cir_private @".str_Z2fnv" = |
| 65 | +// CIR-HOST-SAME: #cir.const_array<"_Z2fnv", trailing_zeros> |
| 66 | + |
| 67 | +__global__ void fn() {} |
| 68 | + |
| 69 | +// CIR-HOST: cir.func internal private @__hip_register_globals(%[[FatbinHandle:[a-zA-Z0-9]+]]{{.*}}) { |
| 70 | +// CIR-HOST: %[[#NULL:]] = cir.const #cir.ptr<null> |
| 71 | +// CIR-HOST: %[[#T1:]] = cir.get_global @".str_Z2fnv" |
| 72 | +// CIR-HOST: %[[#DeviceFn:]] = cir.cast bitcast %[[#T1]] |
| 73 | +// CIR-HOST: %[[#T2:]] = cir.get_global @_Z2fnv |
| 74 | +// CIR-HOST: %[[#HostFnHandle:]] = cir.cast bitcast %[[#T2]] |
| 75 | +// CIR-HOST: %[[#MinusOne:]] = cir.const #cir.int<-1> |
| 76 | +// CIR-HOST: cir.call @__hipRegisterFunction( |
| 77 | +// CIR-HOST-SAME: %[[FatbinHandle]], |
| 78 | +// CIR-HOST-SAME: %[[#HostFnHandle]], |
| 79 | +// CIR-HOST-SAME: %[[#DeviceFn]], |
| 80 | +// CIR-HOST-SAME: %[[#DeviceFn]], |
| 81 | +// CIR-HOST-SAME: %[[#MinusOne]], |
| 82 | +// CIR-HOST-SAME: %[[#NULL]], %[[#NULL]], %[[#NULL]], %[[#NULL]], %[[#NULL]]) |
| 83 | +// CIR-HOST: } |
| 84 | + |
| 85 | +// LLVM-HOST: define internal void @__hip_register_globals(ptr %[[#LLVMFatbin:]]) { |
| 86 | +// LLVM-HOST: call i32 @__hipRegisterFunction( |
| 87 | +// LLVM-HOST-SAME: ptr %[[#LLVMFatbin]], |
| 88 | +// LLVM-HOST-SAME: ptr @_Z2fnv, |
| 89 | +// LLVM-HOST-SAME: ptr @.str_Z2fnv, |
| 90 | +// LLVM-HOST-SAME: ptr @.str_Z2fnv, |
| 91 | +// LLVM-HOST-SAME: i32 -1, |
| 92 | +// LLVM-HOST-SAME: ptr null, ptr null, ptr null, ptr null, ptr null) |
| 93 | +// LLVM-HOST: } |
| 94 | + |
| 95 | +// The content in const array should be the same as echoed above, |
| 96 | +// with a trailing line break ('\n', 0x0A). |
| 97 | +// CIR-HOST: cir.global "private" constant cir_private @__hip_fatbin_str = |
| 98 | +// CIR-HOST-SAME: #cir.const_array<"sample fatbin\0A"> |
| 99 | +// CIR-HOST-SAME: {{.*}}section = ".hip_fatbin" |
| 100 | + |
| 101 | +// The first value is HIP file head magic number. |
| 102 | +// CIR-HOST: cir.global "private" constant internal @__hip_fatbin_wrapper |
| 103 | +// CIR-HOST: = #cir.const_record<{ |
| 104 | +// CIR-HOST: #cir.int<1212764230> : !s32i, |
| 105 | +// CIR-HOST: #cir.int<1> : !s32i, |
| 106 | +// CIR-HOST: #cir.global_view<@__hip_fatbin_str> : !cir.ptr<!void>, |
| 107 | +// CIR-HOST: #cir.ptr<null> : !cir.ptr<!void> |
| 108 | +// CIR-HOST: }> |
| 109 | +// CIR-HOST-SAME: {{.*}}section = ".hipFatBinSegment" |
| 110 | + |
| 111 | +// CIR-HOST: cir.func internal private @__hip_module_ctor() { |
| 112 | +// CIR-HOST: %[[#HandleGlobalVar:]] = cir.get_global @__hip_gpubin_handle : !cir.ptr<!cir.ptr<!cir.ptr<!void>>> loc(#loc) |
| 113 | +// CIR-HOST: %[[#HandleAddr:]] = cir.load %[[#HandleGlobalVar]] : !cir.ptr<!cir.ptr<!cir.ptr<!void>>>, !cir.ptr<!cir.ptr<!void>> loc(#loc) |
| 114 | +// CIR-HOST: %[[#NullVal:]] = cir.const #cir.ptr<null> : !cir.ptr<!cir.ptr<!void>> loc(#loc) |
| 115 | +// CIR-HOST: %[[#ICMP:]] = cir.cmp(eq, %[[#HandleAddr]], %[[#NullVal]]) : !cir.ptr<!cir.ptr<!void>>, !cir.bool loc(#loc) |
| 116 | +// CIR-HOST: cir.brcond %[[#ICMP]] ^bb1, ^bb2 loc(#loc) |
| 117 | +// CIR-HOST: ^bb1: |
| 118 | +// CIR-HOST: %[[#FatBinWrapper:]] = cir.get_global @__hip_fatbin_wrapper : !cir.ptr<!rec_anon_struct> loc(#loc) |
| 119 | +// CIR-HOST: %[[#CastGlobalFatBin:]] = cir.cast bitcast %[[#FatBinWrapper]] : !cir.ptr<!rec_anon_struct> -> !cir.ptr<!void> loc(#loc) |
| 120 | +// CIR-HOST: %[[#RTVal:]] = cir.call @__hipRegisterFatBinary(%[[#CastGlobalFatBin]]) : (!cir.ptr<!void>) -> !cir.ptr<!cir.ptr<!void>> loc(#loc) |
| 121 | +// CIR-HOST: %[[#HandleGlobalVar:]] = cir.get_global @__hip_gpubin_handle : !cir.ptr<!cir.ptr<!cir.ptr<!void>>> loc(#loc) |
| 122 | +// CIR-HOST: cir.store %[[#RTVal]], %[[#HandleGlobalVar]] : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!cir.ptr<!cir.ptr<!void>>> loc(#loc) |
| 123 | +// CIR-HOST: cir.br ^bb2 loc(#loc) |
| 124 | +// CIR-HOST: ^bb2: |
| 125 | +// CIR-HOST: %[[#HandleGlobalVar:]] = cir.get_global @__hip_gpubin_handle : !cir.ptr<!cir.ptr<!cir.ptr<!void>>> loc(#loc) |
| 126 | +// CIR-HOST: %[[#HandleVal:]] = cir.load %8 : !cir.ptr<!cir.ptr<!cir.ptr<!void>>>, !cir.ptr<!cir.ptr<!void>> loc(#loc) |
| 127 | +// CIR-HOST: cir.call @__hip_register_globals(%[[#HandleVal]]) : (!cir.ptr<!cir.ptr<!void>>) -> () loc(#loc) |
| 128 | +// CIR-HOST: %[[#DTOR:]] = cir.get_global @__hip_module_dtor : !cir.ptr<!cir.func<()>> loc(#loc) |
| 129 | +// CIR-HOST: %11 = cir.call @atexit(%[[#DTOR]]) : (!cir.ptr<!cir.func<()>>) -> !s32i loc(#loc) |
| 130 | +// CIR-HOST: cir.return loc(#loc) |
| 131 | +// CIR-HOST: } loc(#loc) |
| 132 | + |
| 133 | +// LLVM-HOST: define internal void @__hip_module_ctor() { |
| 134 | +// LLVM-HOST: %[[#LLVMHandleVar:]] = load ptr, ptr @__hip_gpubin_handle, align 8 |
| 135 | +// LLVM-HOST: %[[#ICMP:]] = icmp eq ptr %[[#LLVMHandleVar]], null |
| 136 | +// LLVM-HOST: br i1 %[[#ICMP]], label %[[IFBLOCK:[^,]+]], label %[[EXITBLOCK:[^,]+]] |
| 137 | +// LLVM-HOST: [[IFBLOCK]]: |
| 138 | +// LLVM-HOST: %[[#Value:]] = call ptr @__hipRegisterFatBinary(ptr @__hip_fatbin_wrapper) |
| 139 | +// LLVM-HOST: store ptr %[[#Value]], ptr @__hip_gpubin_handle, align 8 |
| 140 | +// LLVM-HOST: br label %[[EXITBLOCK]] |
| 141 | +// LLVM-HOST: [[EXITBLOCK]]: |
| 142 | +// LLVM-HOST: %[[#HandleValue:]] = load ptr, ptr @__hip_gpubin_handle, align 8 |
| 143 | +// LLVM-HOST: call void @__hip_register_globals(ptr %[[#HandleValue]]) |
| 144 | +// LLVM-HOST: call i32 @atexit(ptr @__hip_module_dtor) |
| 145 | +// LLVM-HOST: ret void |
| 146 | + |
| 147 | +// OGCG-HOST: @_Z2fnv = constant ptr @_Z17__device_stub__fnv, align 8 |
| 148 | +// OGCG-HOST: @0 = private unnamed_addr constant [7 x i8] c"_Z2fnv\00", align 1 |
| 149 | +// OGCG-HOST: @1 = private constant [14 x i8] c"sample fatbin\0A", section ".hip_fatbin", align 4096 |
| 150 | +// OGCG-HOST: @__hip_fatbin_wrapper = internal constant { i32, i32, ptr, ptr } { i32 1212764230, i32 1, ptr @1, ptr null }, section ".hipFatBinSegment", align 8 |
| 151 | +// OGCG-HOST: @__hip_gpubin_handle = internal global ptr null, align 8 |
| 152 | +// OGCG-HOST: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @__hip_module_ctor, ptr null }] |
| 153 | + |
| 154 | +// OGCG-HOST: define internal void @__hip_register_globals(ptr %[[#LLVMFatbin:]]) { |
| 155 | +// OGCG-HOST: entry: |
| 156 | +// OGCG-HOST: call i32 @__hipRegisterFunction( |
| 157 | +// OGCG-HOST-SAME: ptr %[[#LLVMFatbin]], |
| 158 | +// OGCG-HOST-SAME: ptr @_Z2fnv, |
| 159 | +// OGCG-HOST-SAME: ptr @0, |
| 160 | +// OGCG-HOST-SAME: ptr @0, |
| 161 | +// OGCG-HOST-SAME: i32 -1, |
| 162 | +// OGCG-HOST-SAME: ptr null, ptr null, ptr null, ptr null, ptr null) |
| 163 | +// OGCG-HOST: } |
| 164 | + |
| 165 | +// OGCG-HOST: define internal void @__hip_module_ctor() { |
| 166 | +// OGCG-HOST: %[[#LLVMHandleVar:]] = load ptr, ptr @__hip_gpubin_handle, align 8 |
| 167 | +// OGCG-HOST: %[[#ICMP:]] = icmp eq ptr %[[#LLVMHandleVar]], null |
| 168 | +// OGCG-HOST: br i1 %[[#ICMP]], label %[[IFBLOCK:[^,]+]], label %[[EXITBLOCK:[^,]+]] |
| 169 | +// OGCG-HOST: [[IFBLOCK]]: |
| 170 | +// OGCG-HOST: %[[#Value:]] = call ptr @__hipRegisterFatBinary(ptr @__hip_fatbin_wrapper) |
| 171 | +// OGCG-HOST: store ptr %[[#Value]], ptr @__hip_gpubin_handle, align 8 |
| 172 | +// OGCG-HOST: br label %[[EXITBLOCK]] |
| 173 | +// OGCG-HOST: [[EXITBLOCK]]: |
| 174 | +// OGCG-HOST: %[[#HandleValue:]] = load ptr, ptr @__hip_gpubin_handle, align 8 |
| 175 | +// OGCG-HOST: call void @__hip_register_globals(ptr %[[#HandleValue]]) |
| 176 | +// OGCG-HOST: call i32 @atexit(ptr @__hip_module_dtor) |
| 177 | +// OGCG-HOST: ret void |
| 178 | + |
| 179 | +// OGCG-HOST: define internal void @__hip_module_dtor() { |
| 180 | +// OGCG-HOST: entry: |
| 181 | +// OGCG-HOST: %[[#LLVMHandleVar:]] = load ptr, ptr @__hip_gpubin_handle, align 8 |
| 182 | +// OGCG-HOST: %[[#ICMP:]] = icmp ne ptr %[[#LLVMHandleVar]], null |
| 183 | +// OGCG-HOST: br i1 %[[#ICMP]], label %[[IFBLOCK:[^,]+]], label %[[EXITBLOCK:[^,]+]] |
| 184 | +// OGCG-HOST: [[IFBLOCK]]: ; preds = %entry |
| 185 | +// OGCG-HOST: call void @__hipUnregisterFatBinary(ptr %[[#LLVMHandleVar]]) |
| 186 | +// OGCG-HOST: store ptr null, ptr @__hip_gpubin_handle, align 8 |
| 187 | +// OGCG-HOST: br label %[[EXITBLOCK]] |
| 188 | +// OGCG-HOST: [[EXITBLOCK]]: ; preds = %[[IFBLOCK]], %entry |
| 189 | +// OGCG-HOST: ret void |
| 190 | +// OGCG-HOST: } |
| 191 | + |
0 commit comments