1+ # TODO - Review branching redundancy near the top of this code
12# ###################################################################################################
23# ##################################### Memory Addressing ###########################################
34# ###################################################################################################
@@ -168,7 +169,7 @@ function offset_ptr(
168169 if iszero (O)
169170 push! (
170171 instrs,
171- " %ptr.$(i) = inttoptr $(JULIAPOINTERTYPE) %0 to $(index_gep_typ) * "
172+ " %ptr.$(i) = bitcast $(JULIAPOINTERTYPE) %0 to ptr "
172173 )
173174 i += 1
174175 else # !iszero(O)
@@ -181,25 +182,25 @@ function offset_ptr(
181182 end
182183 push! (
183184 instrs,
184- " %ptr.$(i) = inttoptr $(JULIAPOINTERTYPE) %0 to $(offset_gep_typ) * "
185+ " %ptr.$(i) = bitcast $(JULIAPOINTERTYPE) %0 to ptr "
185186 )
186187 i += 1
187188 push! (
188189 instrs,
189- " %ptr.$(i) = getelementptr inbounds $(offset_gep_typ) , $(offset_gep_typ) * %ptr.$(i- 1 ) , i32 $(offset) "
190+ " %ptr.$(i) = getelementptr inbounds $(offset_gep_typ) , ptr %ptr.$(i- 1 ) , i32 $(offset) "
190191 )
191192 i += 1
192193 if forgep && iszero (M) && (iszero (X) || isone (X))
193194 push! (
194195 instrs,
195- " %ptr.$(i) = ptrtoint $(offset_gep_typ) * %ptr.$(i- 1 ) to $(JULIAPOINTERTYPE) "
196+ " %ptr.$(i) = bitcast ptr %ptr.$(i- 1 ) to $(JULIAPOINTERTYPE) "
196197 )
197198 i += 1
198199 return instrs, i
199200 elseif offset_gep_typ != index_gep_typ
200201 push! (
201202 instrs,
202- " %ptr.$(i) = bitcast $(offset_gep_typ) * %ptr.$(i- 1 ) to $(index_gep_typ) * "
203+ " %ptr.$(i) = bitcast ptr %ptr.$(i- 1 ) to ptr "
203204 )
204205 i += 1
205206 end
@@ -218,19 +219,19 @@ function offset_ptr(
218219 end
219220 push! (
220221 instrs,
221- " %ptr.$(i) = getelementptr inbounds $(index_gep_typ) , $(index_gep_typ) * %ptr.$(i- 1 ) , <$W x i$(ibits) > %$(indname) "
222+ " %ptr.$(i) = getelementptr inbounds $(index_gep_typ) , ptr %ptr.$(i- 1 ) , <$W x i$(ibits) > %$(indname) "
222223 )
223224 i += 1
224225 if forgep
225226 push! (
226227 instrs,
227- " %ptr.$(i) = ptrtoint <$W x $index_gep_typ * > %ptr.$(i- 1 ) to <$W x $JULIAPOINTERTYPE >"
228+ " %ptr.$(i) = bitcast <$W x ptr > %ptr.$(i- 1 ) to <$W x $JULIAPOINTERTYPE >"
228229 )
229230 i += 1
230231 elseif index_gep_typ != vtyp
231232 push! (
232233 instrs,
233- " %ptr.$(i) = bitcast <$W x $index_gep_typ * > %ptr.$(i- 1 ) to <$W x $typ * >"
234+ " %ptr.$(i) = bitcast <$W x ptr > %ptr.$(i- 1 ) to <$W x ptr >"
234235 )
235236 i += 1
236237 end
@@ -278,7 +279,7 @@ function offset_ptr(
278279 end
279280 push! (
280281 instrs,
281- " %ptr.$(i) = getelementptr inbounds $(index_gep_typ) , $(index_gep_typ) * %ptr.$(i- 1 ) , i$(ibits) %$(indname) "
282+ " %ptr.$(i) = getelementptr inbounds $(index_gep_typ) , ptr %ptr.$(i- 1 ) , i$(ibits) %$(indname) "
282283 )
283284 i += 1
284285 end
@@ -293,19 +294,19 @@ function offset_ptr(
293294 if typ != = index_gep_typ
294295 push! (
295296 instrs,
296- " %ptr.$(i) = bitcast $(index_gep_typ) * %ptr.$(i- 1 ) to $(typ) * "
297+ " %ptr.$(i) = bitcast ptr %ptr.$(i- 1 ) to ptr "
297298 )
298299 i += 1
299300 end
300301 push! (
301302 instrs,
302- " %ptr.$(i) = getelementptr inbounds $(typ) , $(typ) * %ptr.$(i- 1 ) , <$W x $(vityp) > <$vityp $vi >"
303+ " %ptr.$(i) = getelementptr inbounds $(typ) , ptr %ptr.$(i- 1 ) , <$W x $(vityp) > <$vityp $vi >"
303304 )
304305 i += 1
305306 if forgep
306307 push! (
307308 instrs,
308- " %ptr.$(i) = ptrtoint <$W x $typ * > %ptr.$(i- 1 ) to <$W x $JULIAPOINTERTYPE >"
309+ " %ptr.$(i) = bitcast <$W x ptr > %ptr.$(i- 1 ) to <$W x $JULIAPOINTERTYPE >"
309310 )
310311 i += 1
311312 end
@@ -314,13 +315,13 @@ function offset_ptr(
314315 if forgep # if forgep, just return now
315316 push! (
316317 instrs,
317- " %ptr.$(i) = ptrtoint $(index_gep_typ) * %ptr.$(i- 1 ) to $JULIAPOINTERTYPE "
318+ " %ptr.$(i) = bitcast ptr %ptr.$(i- 1 ) to $JULIAPOINTERTYPE "
318319 )
319320 i += 1
320321 elseif index_gep_typ != vtyp
321322 push! (
322323 instrs,
323- " %ptr.$(i) = bitcast $(index_gep_typ) * %ptr.$(i- 1 ) to $(vtyp) * "
324+ " %ptr.$(i) = bitcast ptr %ptr.$(i- 1 ) to ptr "
324325 )
325326 i += 1
326327 end
@@ -822,27 +823,27 @@ function vload_quote_llvmcall_core(
822823 suffix (W, T_sym) *
823824 ' .' *
824825 ptr_suffix (W, T_sym)
825- decl *= " declare $loadinstr (<$W x $typ * >, i32, <$W x i1>, $vtyp )"
826+ decl *= " declare $loadinstr (<$W x ptr >, i32, <$W x i1>, $vtyp )"
826827 m = mask ? m = " %mask.0" : llvmconst (W, " i1 1" )
827828 passthrough = mask ? " zeroinitializer" : " undef"
828829 push! (
829830 instrs,
830- " %res = call $loadinstr (<$W x $typ * > %ptr.$(i- 1 ) , i32 $alignment , <$W x i1> $m , $vtyp $passthrough )" *
831+ " %res = call $loadinstr (<$W x ptr > %ptr.$(i- 1 ) , i32 $alignment , <$W x i1> $m , $vtyp $passthrough )" *
831832 LOAD_SCOPE_TBAA_FLAGS
832833 )
833834 elseif mask
834835 suff = suffix (W, T_sym)
835836 loadinstr = " $vtyp @llvm.masked.load." * suff * " .p0" * suff
836- decl *= " declare $loadinstr ($vtyp * , i32, <$W x i1>, $vtyp )"
837+ decl *= " declare $loadinstr (ptr , i32, <$W x i1>, $vtyp )"
837838 push! (
838839 instrs,
839- " %res = call $loadinstr ($vtyp * %ptr.$(i- 1 ) , i32 $alignment , <$W x i1> %mask.0, $vtyp zeroinitializer)" *
840+ " %res = call $loadinstr (ptr %ptr.$(i- 1 ) , i32 $alignment , <$W x i1> %mask.0, $vtyp zeroinitializer)" *
840841 LOAD_SCOPE_TBAA_FLAGS
841842 )
842843 else
843844 push! (
844845 instrs,
845- " %res = load $vtyp , $vtyp * %ptr.$(i- 1 ) , align $alignment " *
846+ " %res = load $vtyp , ptr %ptr.$(i- 1 ) , align $alignment " *
846847 LOAD_SCOPE_TBAA_FLAGS
847848 )
848849 end
@@ -1254,33 +1255,33 @@ function vstore_quote(
12541255 suffix (W, T_sym) *
12551256 ' .' *
12561257 ptr_suffix (W, T_sym)
1257- decl *= " declare $storeinstr ($vtyp , <$W x $typ * >, i32, <$W x i1>)"
1258+ decl *= " declare $storeinstr ($vtyp , <$W x ptr >, i32, <$W x i1>)"
12581259 m = mask ? m = " %mask.0" : llvmconst (W, " i1 1" )
12591260 push! (
12601261 instrs,
1261- " call $storeinstr ($vtyp $(argtostore) , <$W x $typ * > %ptr.$(i- 1 ) , i32 $alignment , <$W x i1> $m )" *
1262+ " call $storeinstr ($vtyp $(argtostore) , <$W x ptr > %ptr.$(i- 1 ) , i32 $alignment , <$W x i1> $m )" *
12621263 metadata
12631264 )
12641265 # push!(instrs, "call $storeinstr($vtyp $(argtostore), <$W x $typ*> %ptr.$(i-1), i32 $alignment, <$W x i1> $m)")
12651266 elseif mask
12661267 suff = suffix (W, T_sym)
12671268 storeinstr = " void @llvm.masked.store." * suff * " .p0" * suff
1268- decl *= " declare $storeinstr ($vtyp , $vtyp * , i32, <$W x i1>)"
1269+ decl *= " declare $storeinstr ($vtyp , ptr , i32, <$W x i1>)"
12691270 push! (
12701271 instrs,
1271- " call $storeinstr ($vtyp $(argtostore) , $vtyp * %ptr.$(i- 1 ) , i32 $alignment , <$W x i1> %mask.0)" *
1272+ " call $storeinstr ($vtyp $(argtostore) , ptr %ptr.$(i- 1 ) , i32 $alignment , <$W x i1> %mask.0)" *
12721273 metadata
12731274 )
12741275 elseif nontemporal
12751276 push! (
12761277 instrs,
1277- " store $vtyp $(argtostore) , $vtyp * %ptr.$(i- 1 ) , align $alignment , !nontemporal !{i32 1}" *
1278+ " store $vtyp $(argtostore) , ptr %ptr.$(i- 1 ) , align $alignment , !nontemporal !{i32 1}" *
12781279 metadata
12791280 )
12801281 else
12811282 push! (
12821283 instrs,
1283- " store $vtyp $(argtostore) , $vtyp * %ptr.$(i- 1 ) , align $alignment " *
1284+ " store $vtyp $(argtostore) , ptr %ptr.$(i- 1 ) , align $alignment " *
12841285 metadata
12851286 )
12861287 end
@@ -2170,10 +2171,10 @@ end
21702171 " Prefetch intrinsic requires a read/write argument of 0, 1, but received $R ."
21712172 )
21722173 )
2173- decl = " declare void @llvm.prefetch(i8*, i32, i32, i32)"
2174+ decl = " declare void @llvm.prefetch(ptr, i32, i32, i32)"
2175+ # should I cast
21742176 instrs = """
2175- %addr = inttoptr $JULIAPOINTERTYPE %0 to i8*
2176- call void @llvm.prefetch(i8* %addr, i32 $R , i32 $L , i32 1)
2177+ call void @llvm.prefetch(ptr %0, i32 $R , i32 $L , i32 1)
21772178 ret void
21782179 """
21792180 llvmcall_expr (
@@ -2227,9 +2228,11 @@ end
22272228# @inline prefetch2(x, i, j, oi, oj) = prefetch(gep(stridedpointer(x), (data(i) + data(oi) - 1, data(j) + data(oj) - 1)), Val{1}(), Val{0}())
22282229
22292230@generated function lifetime_start! (ptr:: Ptr{T} , :: Val{L} ) where {L,T}
2230- ptyp = LLVM_TYPES[T]
2231- decl = " declare void @llvm.lifetime.start(i64, $ptyp * nocapture)"
2232- instrs = " %ptr = inttoptr $JULIAPOINTERTYPE %0 to $ptyp *\n call void @llvm.lifetime.start(i64 $L , $ptyp * %ptr)\n ret void"
2231+ decl = " declare void @llvm.lifetime.start(i64, ptr nocapture)"
2232+ instrs = """
2233+ call void @llvm.lifetime.start(i64 $L , ptr %0)
2234+ ret void
2235+ """
22332236 llvmcall_expr (
22342237 decl,
22352238 instrs,
@@ -2243,9 +2246,11 @@ end
22432246 )
22442247end
22452248@generated function lifetime_end! (ptr:: Ptr{T} , :: Val{L} ) where {L,T}
2246- ptyp = LLVM_TYPES[T]
2247- decl = " declare void @llvm.lifetime.end(i64, $ptyp * nocapture)"
2248- instrs = " %ptr = inttoptr $JULIAPOINTERTYPE %0 to $ptyp *\n call void @llvm.lifetime.end(i64 $L , $ptyp * %ptr)\n ret void"
2249+ decl = " declare void @llvm.lifetime.end(i64, ptr nocapture)"
2250+ instrs = """
2251+ call void @llvm.lifetime.end(i64 $L , ptr %0)
2252+ ret void
2253+ """
22492254 llvmcall_expr (
22502255 decl,
22512256 instrs,
@@ -2284,12 +2289,12 @@ end
22842289 vtyp = " <$W x $typ >"
22852290 mtyp_input = LLVM_TYPES[U]
22862291 mtyp_trunc = " i$W "
2287- instrs = String[" %ptr = inttoptr $JULIAPOINTERTYPE %1 to $typ * " ]
2292+ instrs = String[" %ptr = bitcast $JULIAPOINTERTYPE %1 to ptr " ]
22882293 truncate_mask! (instrs, ' 2' , W, 0 )
2289- decl = " declare void @llvm.masked.compressstore.$(suffix (W,T)) ($vtyp , $typ * , <$W x i1>)"
2294+ decl = " declare void @llvm.masked.compressstore.$(suffix (W,T)) ($vtyp , ptr , <$W x i1>)"
22902295 push! (
22912296 instrs,
2292- " call void @llvm.masked.compressstore.$(suffix (W,T)) ($vtyp %0, $typ * %ptr, <$W x i1> %mask.0)\n ret void"
2297+ " call void @llvm.masked.compressstore.$(suffix (W,T)) ($vtyp %0, ptr %ptr, <$W x i1> %mask.0)\n ret void"
22932298 )
22942299 llvmcall_expr (
22952300 decl,
@@ -2310,21 +2315,21 @@ end
23102315) where {W,T<: NativeTypes ,U<: Unsigned }
23112316 typ = LLVM_TYPES[T]
23122317 vtyp = " <$W x $typ >"
2313- vptrtyp = " <$W x $typ * >"
2318+ vptrtyp = " <$W x ptr >"
23142319 mtyp_input = LLVM_TYPES[U]
23152320 mtyp_trunc = " i$W "
23162321 instrs = String[]
2317- push! (instrs, " %ptr = inttoptr $JULIAPOINTERTYPE %0 to $typ * " )
2322+ push! (instrs, " %ptr = bitcast $JULIAPOINTERTYPE %0 to ptr " )
23182323 if mtyp_input == mtyp_trunc
23192324 push! (instrs, " %mask = bitcast $mtyp_input %1 to <$W x i1>" )
23202325 else
23212326 push! (instrs, " %masktrunc = trunc $mtyp_input %1 to $mtyp_trunc " )
23222327 push! (instrs, " %mask = bitcast $mtyp_trunc %masktrunc to <$W x i1>" )
23232328 end
2324- decl = " declare $vtyp @llvm.masked.expandload.$(suffix (W,T)) ($typ * , <$W x i1>, $vtyp )"
2329+ decl = " declare $vtyp @llvm.masked.expandload.$(suffix (W,T)) (ptr , <$W x i1>, $vtyp )"
23252330 push! (
23262331 instrs,
2327- " %res = call $vtyp @llvm.masked.expandload.$(suffix (W,T)) ($typ * %ptr, <$W x i1> %mask, $vtyp zeroinitializer)\n ret $vtyp %res"
2332+ " %res = call $vtyp @llvm.masked.expandload.$(suffix (W,T)) (ptr %ptr, <$W x i1> %mask, $vtyp zeroinitializer)\n ret $vtyp %res"
23282333 )
23292334 llvmcall_expr (
23302335 decl,
0 commit comments