github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/compiler/testdata/slice.ll (about) 1 ; ModuleID = 'slice.go' 2 source_filename = "slice.go" 3 target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-n32:64-S128-ni:1:10:20" 4 target triple = "wasm32-unknown-wasi" 5 6 ; Function Attrs: allockind("alloc,zeroed") allocsize(0) 7 declare noalias nonnull ptr @runtime.alloc(i32, ptr, ptr) #0 8 9 declare void @runtime.trackPointer(ptr nocapture readonly, ptr, ptr) #1 10 11 ; Function Attrs: nounwind 12 define hidden void @main.init(ptr %context) unnamed_addr #2 { 13 entry: 14 ret void 15 } 16 17 ; Function Attrs: nounwind 18 define hidden i32 @main.sliceLen(ptr %ints.data, i32 %ints.len, i32 %ints.cap, ptr %context) unnamed_addr #2 { 19 entry: 20 ret i32 %ints.len 21 } 22 23 ; Function Attrs: nounwind 24 define hidden i32 @main.sliceCap(ptr %ints.data, i32 %ints.len, i32 %ints.cap, ptr %context) unnamed_addr #2 { 25 entry: 26 ret i32 %ints.cap 27 } 28 29 ; Function Attrs: nounwind 30 define hidden i32 @main.sliceElement(ptr %ints.data, i32 %ints.len, i32 %ints.cap, i32 %index, ptr %context) unnamed_addr #2 { 31 entry: 32 %.not = icmp ult i32 %index, %ints.len 33 br i1 %.not, label %lookup.next, label %lookup.throw 34 35 lookup.next: ; preds = %entry 36 %0 = getelementptr inbounds i32, ptr %ints.data, i32 %index 37 %1 = load i32, ptr %0, align 4 38 ret i32 %1 39 40 lookup.throw: ; preds = %entry 41 call void @runtime.lookupPanic(ptr undef) #3 42 unreachable 43 } 44 45 declare void @runtime.lookupPanic(ptr) #1 46 47 ; Function Attrs: nounwind 48 define hidden { ptr, i32, i32 } @main.sliceAppendValues(ptr %ints.data, i32 %ints.len, i32 %ints.cap, ptr %context) unnamed_addr #2 { 49 entry: 50 %stackalloc = alloca i8, align 1 51 %varargs = call dereferenceable(12) ptr @runtime.alloc(i32 12, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #3 52 call void @runtime.trackPointer(ptr nonnull %varargs, ptr nonnull %stackalloc, ptr undef) #3 53 store i32 1, ptr %varargs, align 4 54 %0 = getelementptr inbounds [3 x i32], ptr %varargs, i32 0, i32 1 55 store i32 2, ptr %0, align 4 56 %1 = getelementptr inbounds [3 x i32], ptr %varargs, i32 0, i32 2 57 store i32 3, ptr %1, align 4 58 %append.new = call { ptr, i32, i32 } @runtime.sliceAppend(ptr %ints.data, ptr nonnull %varargs, i32 %ints.len, i32 %ints.cap, i32 3, i32 4, ptr undef) #3 59 %append.newPtr = extractvalue { ptr, i32, i32 } %append.new, 0 60 %append.newLen = extractvalue { ptr, i32, i32 } %append.new, 1 61 %append.newCap = extractvalue { ptr, i32, i32 } %append.new, 2 62 %2 = insertvalue { ptr, i32, i32 } undef, ptr %append.newPtr, 0 63 %3 = insertvalue { ptr, i32, i32 } %2, i32 %append.newLen, 1 64 %4 = insertvalue { ptr, i32, i32 } %3, i32 %append.newCap, 2 65 call void @runtime.trackPointer(ptr %append.newPtr, ptr nonnull %stackalloc, ptr undef) #3 66 ret { ptr, i32, i32 } %4 67 } 68 69 declare { ptr, i32, i32 } @runtime.sliceAppend(ptr, ptr nocapture readonly, i32, i32, i32, i32, ptr) #1 70 71 ; Function Attrs: nounwind 72 define hidden { ptr, i32, i32 } @main.sliceAppendSlice(ptr %ints.data, i32 %ints.len, i32 %ints.cap, ptr %added.data, i32 %added.len, i32 %added.cap, ptr %context) unnamed_addr #2 { 73 entry: 74 %stackalloc = alloca i8, align 1 75 %append.new = call { ptr, i32, i32 } @runtime.sliceAppend(ptr %ints.data, ptr %added.data, i32 %ints.len, i32 %ints.cap, i32 %added.len, i32 4, ptr undef) #3 76 %append.newPtr = extractvalue { ptr, i32, i32 } %append.new, 0 77 %append.newLen = extractvalue { ptr, i32, i32 } %append.new, 1 78 %append.newCap = extractvalue { ptr, i32, i32 } %append.new, 2 79 %0 = insertvalue { ptr, i32, i32 } undef, ptr %append.newPtr, 0 80 %1 = insertvalue { ptr, i32, i32 } %0, i32 %append.newLen, 1 81 %2 = insertvalue { ptr, i32, i32 } %1, i32 %append.newCap, 2 82 call void @runtime.trackPointer(ptr %append.newPtr, ptr nonnull %stackalloc, ptr undef) #3 83 ret { ptr, i32, i32 } %2 84 } 85 86 ; Function Attrs: nounwind 87 define hidden i32 @main.sliceCopy(ptr %dst.data, i32 %dst.len, i32 %dst.cap, ptr %src.data, i32 %src.len, i32 %src.cap, ptr %context) unnamed_addr #2 { 88 entry: 89 %copy.n = call i32 @runtime.sliceCopy(ptr %dst.data, ptr %src.data, i32 %dst.len, i32 %src.len, i32 4, ptr undef) #3 90 ret i32 %copy.n 91 } 92 93 declare i32 @runtime.sliceCopy(ptr nocapture writeonly, ptr nocapture readonly, i32, i32, i32, ptr) #1 94 95 ; Function Attrs: nounwind 96 define hidden { ptr, i32, i32 } @main.makeByteSlice(i32 %len, ptr %context) unnamed_addr #2 { 97 entry: 98 %stackalloc = alloca i8, align 1 99 %slice.maxcap = icmp slt i32 %len, 0 100 br i1 %slice.maxcap, label %slice.throw, label %slice.next 101 102 slice.next: ; preds = %entry 103 %makeslice.buf = call ptr @runtime.alloc(i32 %len, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #3 104 %0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0 105 %1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1 106 %2 = insertvalue { ptr, i32, i32 } %1, i32 %len, 2 107 call void @runtime.trackPointer(ptr nonnull %makeslice.buf, ptr nonnull %stackalloc, ptr undef) #3 108 ret { ptr, i32, i32 } %2 109 110 slice.throw: ; preds = %entry 111 call void @runtime.slicePanic(ptr undef) #3 112 unreachable 113 } 114 115 declare void @runtime.slicePanic(ptr) #1 116 117 ; Function Attrs: nounwind 118 define hidden { ptr, i32, i32 } @main.makeInt16Slice(i32 %len, ptr %context) unnamed_addr #2 { 119 entry: 120 %stackalloc = alloca i8, align 1 121 %slice.maxcap = icmp slt i32 %len, 0 122 br i1 %slice.maxcap, label %slice.throw, label %slice.next 123 124 slice.next: ; preds = %entry 125 %makeslice.cap = shl i32 %len, 1 126 %makeslice.buf = call ptr @runtime.alloc(i32 %makeslice.cap, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #3 127 %0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0 128 %1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1 129 %2 = insertvalue { ptr, i32, i32 } %1, i32 %len, 2 130 call void @runtime.trackPointer(ptr nonnull %makeslice.buf, ptr nonnull %stackalloc, ptr undef) #3 131 ret { ptr, i32, i32 } %2 132 133 slice.throw: ; preds = %entry 134 call void @runtime.slicePanic(ptr undef) #3 135 unreachable 136 } 137 138 ; Function Attrs: nounwind 139 define hidden { ptr, i32, i32 } @main.makeArraySlice(i32 %len, ptr %context) unnamed_addr #2 { 140 entry: 141 %stackalloc = alloca i8, align 1 142 %slice.maxcap = icmp ugt i32 %len, 1431655765 143 br i1 %slice.maxcap, label %slice.throw, label %slice.next 144 145 slice.next: ; preds = %entry 146 %makeslice.cap = mul i32 %len, 3 147 %makeslice.buf = call ptr @runtime.alloc(i32 %makeslice.cap, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #3 148 %0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0 149 %1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1 150 %2 = insertvalue { ptr, i32, i32 } %1, i32 %len, 2 151 call void @runtime.trackPointer(ptr nonnull %makeslice.buf, ptr nonnull %stackalloc, ptr undef) #3 152 ret { ptr, i32, i32 } %2 153 154 slice.throw: ; preds = %entry 155 call void @runtime.slicePanic(ptr undef) #3 156 unreachable 157 } 158 159 ; Function Attrs: nounwind 160 define hidden { ptr, i32, i32 } @main.makeInt32Slice(i32 %len, ptr %context) unnamed_addr #2 { 161 entry: 162 %stackalloc = alloca i8, align 1 163 %slice.maxcap = icmp ugt i32 %len, 1073741823 164 br i1 %slice.maxcap, label %slice.throw, label %slice.next 165 166 slice.next: ; preds = %entry 167 %makeslice.cap = shl i32 %len, 2 168 %makeslice.buf = call ptr @runtime.alloc(i32 %makeslice.cap, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #3 169 %0 = insertvalue { ptr, i32, i32 } undef, ptr %makeslice.buf, 0 170 %1 = insertvalue { ptr, i32, i32 } %0, i32 %len, 1 171 %2 = insertvalue { ptr, i32, i32 } %1, i32 %len, 2 172 call void @runtime.trackPointer(ptr nonnull %makeslice.buf, ptr nonnull %stackalloc, ptr undef) #3 173 ret { ptr, i32, i32 } %2 174 175 slice.throw: ; preds = %entry 176 call void @runtime.slicePanic(ptr undef) #3 177 unreachable 178 } 179 180 ; Function Attrs: nounwind 181 define hidden ptr @main.Add32(ptr %p, i32 %len, ptr %context) unnamed_addr #2 { 182 entry: 183 %stackalloc = alloca i8, align 1 184 %0 = getelementptr i8, ptr %p, i32 %len 185 call void @runtime.trackPointer(ptr %0, ptr nonnull %stackalloc, ptr undef) #3 186 ret ptr %0 187 } 188 189 ; Function Attrs: nounwind 190 define hidden ptr @main.Add64(ptr %p, i64 %len, ptr %context) unnamed_addr #2 { 191 entry: 192 %stackalloc = alloca i8, align 1 193 %0 = trunc i64 %len to i32 194 %1 = getelementptr i8, ptr %p, i32 %0 195 call void @runtime.trackPointer(ptr %1, ptr nonnull %stackalloc, ptr undef) #3 196 ret ptr %1 197 } 198 199 ; Function Attrs: nounwind 200 define hidden ptr @main.SliceToArray(ptr %s.data, i32 %s.len, i32 %s.cap, ptr %context) unnamed_addr #2 { 201 entry: 202 %0 = icmp ult i32 %s.len, 4 203 br i1 %0, label %slicetoarray.throw, label %slicetoarray.next 204 205 slicetoarray.next: ; preds = %entry 206 ret ptr %s.data 207 208 slicetoarray.throw: ; preds = %entry 209 call void @runtime.sliceToArrayPointerPanic(ptr undef) #3 210 unreachable 211 } 212 213 declare void @runtime.sliceToArrayPointerPanic(ptr) #1 214 215 ; Function Attrs: nounwind 216 define hidden ptr @main.SliceToArrayConst(ptr %context) unnamed_addr #2 { 217 entry: 218 %stackalloc = alloca i8, align 1 219 %makeslice = call dereferenceable(24) ptr @runtime.alloc(i32 24, ptr nonnull inttoptr (i32 3 to ptr), ptr undef) #3 220 call void @runtime.trackPointer(ptr nonnull %makeslice, ptr nonnull %stackalloc, ptr undef) #3 221 br i1 false, label %slicetoarray.throw, label %slicetoarray.next 222 223 slicetoarray.next: ; preds = %entry 224 ret ptr %makeslice 225 226 slicetoarray.throw: ; preds = %entry 227 unreachable 228 } 229 230 ; Function Attrs: nounwind 231 define hidden { ptr, i32, i32 } @main.SliceInt(ptr dereferenceable_or_null(4) %ptr, i32 %len, ptr %context) unnamed_addr #2 { 232 entry: 233 %stackalloc = alloca i8, align 1 234 %0 = icmp ugt i32 %len, 1073741823 235 %1 = icmp eq ptr %ptr, null 236 %2 = icmp ne i32 %len, 0 237 %3 = and i1 %1, %2 238 %4 = or i1 %3, %0 239 br i1 %4, label %unsafe.Slice.throw, label %unsafe.Slice.next 240 241 unsafe.Slice.next: ; preds = %entry 242 %5 = insertvalue { ptr, i32, i32 } undef, ptr %ptr, 0 243 %6 = insertvalue { ptr, i32, i32 } %5, i32 %len, 1 244 %7 = insertvalue { ptr, i32, i32 } %6, i32 %len, 2 245 call void @runtime.trackPointer(ptr %ptr, ptr nonnull %stackalloc, ptr undef) #3 246 ret { ptr, i32, i32 } %7 247 248 unsafe.Slice.throw: ; preds = %entry 249 call void @runtime.unsafeSlicePanic(ptr undef) #3 250 unreachable 251 } 252 253 declare void @runtime.unsafeSlicePanic(ptr) #1 254 255 ; Function Attrs: nounwind 256 define hidden { ptr, i32, i32 } @main.SliceUint16(ptr dereferenceable_or_null(1) %ptr, i16 %len, ptr %context) unnamed_addr #2 { 257 entry: 258 %stackalloc = alloca i8, align 1 259 %0 = icmp eq ptr %ptr, null 260 %1 = icmp ne i16 %len, 0 261 %2 = and i1 %0, %1 262 br i1 %2, label %unsafe.Slice.throw, label %unsafe.Slice.next 263 264 unsafe.Slice.next: ; preds = %entry 265 %3 = zext i16 %len to i32 266 %4 = insertvalue { ptr, i32, i32 } undef, ptr %ptr, 0 267 %5 = insertvalue { ptr, i32, i32 } %4, i32 %3, 1 268 %6 = insertvalue { ptr, i32, i32 } %5, i32 %3, 2 269 call void @runtime.trackPointer(ptr %ptr, ptr nonnull %stackalloc, ptr undef) #3 270 ret { ptr, i32, i32 } %6 271 272 unsafe.Slice.throw: ; preds = %entry 273 call void @runtime.unsafeSlicePanic(ptr undef) #3 274 unreachable 275 } 276 277 ; Function Attrs: nounwind 278 define hidden { ptr, i32, i32 } @main.SliceUint64(ptr dereferenceable_or_null(4) %ptr, i64 %len, ptr %context) unnamed_addr #2 { 279 entry: 280 %stackalloc = alloca i8, align 1 281 %0 = icmp ugt i64 %len, 1073741823 282 %1 = icmp eq ptr %ptr, null 283 %2 = icmp ne i64 %len, 0 284 %3 = and i1 %1, %2 285 %4 = or i1 %3, %0 286 br i1 %4, label %unsafe.Slice.throw, label %unsafe.Slice.next 287 288 unsafe.Slice.next: ; preds = %entry 289 %5 = trunc i64 %len to i32 290 %6 = insertvalue { ptr, i32, i32 } undef, ptr %ptr, 0 291 %7 = insertvalue { ptr, i32, i32 } %6, i32 %5, 1 292 %8 = insertvalue { ptr, i32, i32 } %7, i32 %5, 2 293 call void @runtime.trackPointer(ptr %ptr, ptr nonnull %stackalloc, ptr undef) #3 294 ret { ptr, i32, i32 } %8 295 296 unsafe.Slice.throw: ; preds = %entry 297 call void @runtime.unsafeSlicePanic(ptr undef) #3 298 unreachable 299 } 300 301 ; Function Attrs: nounwind 302 define hidden { ptr, i32, i32 } @main.SliceInt64(ptr dereferenceable_or_null(4) %ptr, i64 %len, ptr %context) unnamed_addr #2 { 303 entry: 304 %stackalloc = alloca i8, align 1 305 %0 = icmp ugt i64 %len, 1073741823 306 %1 = icmp eq ptr %ptr, null 307 %2 = icmp ne i64 %len, 0 308 %3 = and i1 %1, %2 309 %4 = or i1 %3, %0 310 br i1 %4, label %unsafe.Slice.throw, label %unsafe.Slice.next 311 312 unsafe.Slice.next: ; preds = %entry 313 %5 = trunc i64 %len to i32 314 %6 = insertvalue { ptr, i32, i32 } undef, ptr %ptr, 0 315 %7 = insertvalue { ptr, i32, i32 } %6, i32 %5, 1 316 %8 = insertvalue { ptr, i32, i32 } %7, i32 %5, 2 317 call void @runtime.trackPointer(ptr %ptr, ptr nonnull %stackalloc, ptr undef) #3 318 ret { ptr, i32, i32 } %8 319 320 unsafe.Slice.throw: ; preds = %entry 321 call void @runtime.unsafeSlicePanic(ptr undef) #3 322 unreachable 323 } 324 325 attributes #0 = { allockind("alloc,zeroed") allocsize(0) "alloc-family"="runtime.alloc" "target-features"="+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext" } 326 attributes #1 = { "target-features"="+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext" } 327 attributes #2 = { nounwind "target-features"="+bulk-memory,+mutable-globals,+nontrapping-fptoint,+sign-ext" } 328 attributes #3 = { nounwind }