Revert "Do not use deprecated LLVM Typed pointer functions"

This reverts commit 4fa1cd56cae62acb63b7fc9c264826b54713248f.

Reason for revert: Fails macOS ARM64 build when rolling into ANGLE

```
../../third_party/SwiftShader/src/Reactor/LLVMReactor.cpp:636:37: error: no member named 'getPtrTy' in 'llvm::IRBuilder<>'
  636 |                 llvm::Type *ptrTy = jit->builder->getPtrTy();
```

Example failing roll:

https://chromium-review.git.corp.google.com/c/angle/angle/+/8183864

Error log:

https://logs.chromium.org/logs/angle/buildbucket/cr-buildbucket/8674489614448676433/+/u/compile__with_patch_/raw_io.output_text_failure_summary_

Change-Id: Idcfcc58e24a657bae2574a7285d35b2b977d74f2
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/77668
Tested-by: Shahbaz Youssefi <syoussefi@google.com>
Reviewed-by: Shahbaz Youssefi <syoussefi@google.com>
Commit-Queue: Shahbaz Youssefi <syoussefi@google.com>
Reviewed-by: Geoff Lang <geofflang@google.com>
diff --git a/src/Reactor/LLVMReactor.cpp b/src/Reactor/LLVMReactor.cpp
index 5f294ec..4507462 100644
--- a/src/Reactor/LLVMReactor.cpp
+++ b/src/Reactor/LLVMReactor.cpp
@@ -633,11 +633,11 @@
 
 	if(getPragmaState(InitializeLocalVariables))
 	{
-		llvm::Type *ptrTy = jit->builder->getPtrTy();
+		llvm::Type *i8PtrTy = llvm::Type::getInt8Ty(*jit->context)->getPointerTo();
 		llvm::Type *i32Ty = llvm::Type::getInt32Ty(*jit->context);
-		llvm::Function *memset = GET_INTRINSIC_DECLARATION(jit->module.get(), llvm::Intrinsic::memset, { ptrTy, i32Ty });
+		llvm::Function *memset = GET_INTRINSIC_DECLARATION(jit->module.get(), llvm::Intrinsic::memset, { i8PtrTy, i32Ty });
 
-		jit->builder->CreateCall(memset, { jit->builder->CreatePointerCast(declaration, ptrTy),
+		jit->builder->CreateCall(memset, { jit->builder->CreatePointerCast(declaration, i8PtrTy),
 		                                   V(Nucleus::createConstantByte((unsigned char)0)),
 		                                   V(Nucleus::createConstantInt((int)typeSize(type) * (arraySize ? arraySize : 1))),
 		                                   V(Nucleus::createConstantBool(false)) });
@@ -912,7 +912,7 @@
 				// Load as an integer and bitcast. See b/136037244.
 				auto size = jit->module->getDataLayout().getTypeStoreSize(elTy);
 				auto elAsIntTy = llvm::IntegerType::get(*jit->context, size * 8);
-				auto ptrCast = jit->builder->CreatePointerCast(V(ptr), jit->builder->getPtrTy());
+				auto ptrCast = jit->builder->CreatePointerCast(V(ptr), elAsIntTy->getPointerTo());
 				auto load = jit->builder->CreateAlignedLoad(elAsIntTy, ptrCast, llvm::MaybeAlign(alignment), isVolatile);
 				load->setAtomic(atomicOrdering(atomic, memoryOrder));
 				auto loadCast = jit->builder->CreateBitCast(load, elTy);
@@ -925,16 +925,16 @@
 				auto sizetTy = llvm::IntegerType::get(*jit->context, sizeof(size_t) * 8);
 				auto intTy = llvm::IntegerType::get(*jit->context, sizeof(int) * 8);
 				auto i8Ty = llvm::Type::getInt8Ty(*jit->context);
-				auto ptrTy = jit->builder->getPtrTy();
+				auto i8PtrTy = i8Ty->getPointerTo();
 				auto voidTy = llvm::Type::getVoidTy(*jit->context);
-				auto funcTy = llvm::FunctionType::get(voidTy, { sizetTy, ptrTy, ptrTy, intTy }, false);
+				auto funcTy = llvm::FunctionType::get(voidTy, { sizetTy, i8PtrTy, i8PtrTy, intTy }, false);
 				auto func = jit->module->getOrInsertFunction("__atomic_load", funcTy);
 				auto size = jit->module->getDataLayout().getTypeStoreSize(elTy);
 				auto out = allocateStackVariable(type);
 				jit->builder->CreateCall(func, {
 				                                   llvm::ConstantInt::get(sizetTy, size),
-				                                   jit->builder->CreatePointerCast(V(ptr), ptrTy),
-				                                   jit->builder->CreatePointerCast(V(out), ptrTy),
+				                                   jit->builder->CreatePointerCast(V(ptr), i8PtrTy),
+				                                   jit->builder->CreatePointerCast(V(out), i8PtrTy),
 				                                   llvm::ConstantInt::get(intTy, uint64_t(atomicOrdering(true, memoryOrder))),
 				                               });
 				return V(jit->builder->CreateLoad(T(type), V(out)));
@@ -982,13 +982,13 @@
 				// void __msan_unpoison(const volatile void *a, size_t size)
 				auto voidTy = llvm::Type::getVoidTy(*jit->context);
 				auto i8Ty = llvm::Type::getInt8Ty(*jit->context);
-				auto ptrTy = jit->builder->getPtrTy();
+				auto voidPtrTy = i8Ty->getPointerTo();
 				auto sizetTy = llvm::IntegerType::get(*jit->context, sizeof(size_t) * 8);
-				auto funcTy = llvm::FunctionType::get(voidTy, { ptrTy, sizetTy }, false);
+				auto funcTy = llvm::FunctionType::get(voidTy, { voidPtrTy, sizetTy }, false);
 				auto func = jit->module->getOrInsertFunction("__msan_unpoison", funcTy);
 				auto size = jit->module->getDataLayout().getTypeStoreSize(elTy);
 
-				jit->builder->CreateCall(func, { jit->builder->CreatePointerCast(V(ptr), ptrTy),
+				jit->builder->CreateCall(func, { jit->builder->CreatePointerCast(V(ptr), voidPtrTy),
 				                                 llvm::ConstantInt::get(sizetTy, size) });
 			}
 
@@ -1011,7 +1011,7 @@
 				auto size = jit->module->getDataLayout().getTypeStoreSize(elTy);
 				auto elAsIntTy = llvm::IntegerType::get(*jit->context, size * 8);
 				auto valCast = jit->builder->CreateBitCast(V(value), elAsIntTy);
-				auto ptrCast = jit->builder->CreatePointerCast(V(ptr), jit->builder->getPtrTy());
+				auto ptrCast = jit->builder->CreatePointerCast(V(ptr), elAsIntTy->getPointerTo());
 				auto store = jit->builder->CreateAlignedStore(valCast, ptrCast, llvm::MaybeAlign(alignment), isVolatile);
 				store->setAtomic(atomicOrdering(atomic, memoryOrder));
 			}
@@ -1022,17 +1022,17 @@
 				auto sizetTy = llvm::IntegerType::get(*jit->context, sizeof(size_t) * 8);
 				auto intTy = llvm::IntegerType::get(*jit->context, sizeof(int) * 8);
 				auto i8Ty = llvm::Type::getInt8Ty(*jit->context);
-				auto ptrTy = jit->builder->getPtrTy();
+				auto i8PtrTy = i8Ty->getPointerTo();
 				auto voidTy = llvm::Type::getVoidTy(*jit->context);
-				auto funcTy = llvm::FunctionType::get(voidTy, { sizetTy, ptrTy, ptrTy, intTy }, false);
+				auto funcTy = llvm::FunctionType::get(voidTy, { sizetTy, i8PtrTy, i8PtrTy, intTy }, false);
 				auto func = jit->module->getOrInsertFunction("__atomic_store", funcTy);
 				auto size = jit->module->getDataLayout().getTypeStoreSize(elTy);
 				auto copy = allocateStackVariable(type);
 				jit->builder->CreateStore(V(value), V(copy));
 				jit->builder->CreateCall(func, {
 				                                   llvm::ConstantInt::get(sizetTy, size),
-				                                   jit->builder->CreatePointerCast(V(ptr), ptrTy),
-				                                   jit->builder->CreatePointerCast(V(copy), ptrTy),
+				                                   jit->builder->CreatePointerCast(V(ptr), i8PtrTy),
+				                                   jit->builder->CreatePointerCast(V(copy), i8PtrTy),
 				                                   llvm::ConstantInt::get(intTy, uint64_t(atomicOrdering(true, memoryOrder))),
 				                               });
 			}
@@ -1056,10 +1056,11 @@
 	auto i1Ty = llvm::Type::getInt1Ty(*jit->context);
 	auto i32Ty = llvm::Type::getInt32Ty(*jit->context);
 	auto elVecTy = llvm::VectorType::get(T(elTy), numEls, false);
+	auto elVecPtrTy = elVecTy->getPointerTo();
 	auto i8Mask = jit->builder->CreateIntCast(V(mask), llvm::VectorType::get(i1Ty, numEls, false), false);  // vec<int, int, ...> -> vec<bool, bool, ...>
 	auto passthrough = zeroMaskedLanes ? llvm::Constant::getNullValue(elVecTy) : llvm::UndefValue::get(elVecTy);
 	auto align = llvm::ConstantInt::get(i32Ty, alignment);
-	auto func = GET_INTRINSIC_DECLARATION(jit->module.get(), llvm::Intrinsic::masked_load, { elVecTy, jit->builder->getPtrTy() });
+	auto func = GET_INTRINSIC_DECLARATION(jit->module.get(), llvm::Intrinsic::masked_load, { elVecTy, elVecPtrTy });
 	return V(jit->builder->CreateCall(func, { V(ptr), align, i8Mask, passthrough }));
 }
 
@@ -1075,9 +1076,10 @@
 	auto i1Ty = llvm::Type::getInt1Ty(*jit->context);
 	auto i32Ty = llvm::Type::getInt32Ty(*jit->context);
 	auto elVecTy = V(val)->getType();
+	auto elVecPtrTy = elVecTy->getPointerTo();
 	auto i1Mask = jit->builder->CreateIntCast(V(mask), llvm::VectorType::get(i1Ty, numEls, false), false);  // vec<int, int, ...> -> vec<bool, bool, ...>
 	auto align = llvm::ConstantInt::get(i32Ty, alignment);
-	auto func = GET_INTRINSIC_DECLARATION(jit->module.get(), llvm::Intrinsic::masked_store, { elVecTy, jit->builder->getPtrTy() });
+	auto func = GET_INTRINSIC_DECLARATION(jit->module.get(), llvm::Intrinsic::masked_store, { elVecTy, elVecPtrTy });
 	jit->builder->CreateCall(func, { V(val), V(ptr), align, i1Mask });
 
 	if(__has_feature(memory_sanitizer) && !jit->msanInstrumentation)
@@ -1085,9 +1087,9 @@
 		// Mark memory writes as initialized by calling __msan_unpoison
 		// void __msan_unpoison(const volatile void *a, size_t size)
 		auto voidTy = llvm::Type::getVoidTy(*jit->context);
-		auto ptrTy = jit->builder->getPtrTy();
+		auto voidPtrTy = voidTy->getPointerTo();
 		auto sizetTy = llvm::IntegerType::get(*jit->context, sizeof(size_t) * 8);
-		auto funcTy = llvm::FunctionType::get(voidTy, { ptrTy, sizetTy }, false);
+		auto funcTy = llvm::FunctionType::get(voidTy, { voidPtrTy, sizetTy }, false);
 		auto func = jit->module->getOrInsertFunction("__msan_unpoison", funcTy);
 		auto size = jit->module->getDataLayout().getTypeStoreSize(llvm::cast<llvm::VectorType>(elVecTy)->getElementType());
 
@@ -1102,7 +1104,7 @@
 
 			// Insert __msan_unpoison call in conditional block
 			auto elPtr = jit->builder->CreateGEP(elVecTy, V(ptr), idx);
-			jit->builder->CreateCall(func, { jit->builder->CreatePointerCast(elPtr, ptrTy),
+			jit->builder->CreateCall(func, { jit->builder->CreatePointerCast(elPtr, voidPtrTy),
 			                                 llvm::ConstantInt::get(sizetTy, size) });
 
 			jit->builder->CreateBr(mergeBlock);
@@ -1121,10 +1123,11 @@
 	auto i1Ty = llvm::Type::getInt1Ty(*jit->context);
 	auto i32Ty = llvm::Type::getInt32Ty(*jit->context);
 	auto i8Ty = llvm::Type::getInt8Ty(*jit->context);
-	auto ptrTy = jit->builder->getPtrTy();
+	auto i8PtrTy = i8Ty->getPointerTo();
+	auto elPtrTy = elTy->getPointerTo();
 	auto elVecTy = llvm::VectorType::get(elTy, numEls, false);
-	auto elPtrVecTy = llvm::VectorType::get(ptrTy, numEls, false);
-	auto i8Base = jit->builder->CreatePointerCast(base, ptrTy);
+	auto elPtrVecTy = llvm::VectorType::get(elPtrTy, numEls, false);
+	auto i8Base = jit->builder->CreatePointerCast(base, i8PtrTy);
 	auto i8Ptrs = jit->builder->CreateGEP(i8Ty, i8Base, offsets);
 	auto elPtrs = jit->builder->CreatePointerCast(i8Ptrs, elPtrVecTy);
 	auto i1Mask = jit->builder->CreateIntCast(mask, llvm::VectorType::get(i1Ty, numEls, false), false);  // vec<int, int, ...> -> vec<bool, bool, ...>
@@ -1152,7 +1155,7 @@
 
 			If(RValue<Bool>(elementMask))
 			{
-				Value *elPtr = Nucleus::createExtractElement(V(elPtrs), T(ptrTy), i);
+				Value *elPtr = Nucleus::createExtractElement(V(elPtrs), T(elPtrTy), i);
 				Value *el = Nucleus::createLoad(elPtr, T(elTy), /*isVolatile */ false, alignment, /* atomic */ false, std::memory_order_relaxed);
 
 				Value *v = Nucleus::createLoad(result, T(elVecTy));
@@ -1186,12 +1189,13 @@
 	auto i1Ty = llvm::Type::getInt1Ty(*jit->context);
 	auto i32Ty = llvm::Type::getInt32Ty(*jit->context);
 	auto i8Ty = llvm::Type::getInt8Ty(*jit->context);
+	auto i8PtrTy = i8Ty->getPointerTo();
 	auto elVecTy = val->getType();
-	auto ptrTy = jit->builder->getPtrTy();
 	auto elTy = llvm::cast<llvm::VectorType>(elVecTy)->getElementType();
-	auto elPtrVecTy = llvm::VectorType::get(ptrTy, numEls, false);
+	auto elPtrTy = elTy->getPointerTo();
+	auto elPtrVecTy = llvm::VectorType::get(elPtrTy, numEls, false);
 
-	auto i8Base = jit->builder->CreatePointerCast(base, ptrTy);
+	auto i8Base = jit->builder->CreatePointerCast(base, i8PtrTy);
 	auto i8Ptrs = jit->builder->CreateGEP(i8Ty, i8Base, offsets);
 	auto elPtrs = jit->builder->CreatePointerCast(i8Ptrs, elPtrVecTy);
 	auto i1Mask = jit->builder->CreateIntCast(mask, llvm::VectorType::get(i1Ty, numEls, false), false);  // vec<int, int, ...> -> vec<bool, bool, ...>
@@ -1279,8 +1283,8 @@
 	// Cast to a byte pointer, apply the byte offset, and cast back to the
 	// original pointer type.
 	return createBitCast(
-	    V(jit->builder->CreateGEP(T(Byte::type()), V(createBitCast(ptr, T(llvm::PointerType::get(*jit->context, 0)))), V(index))),
-	    T(llvm::PointerType::get(*jit->context, 0)));
+	    V(jit->builder->CreateGEP(T(Byte::type()), V(createBitCast(ptr, T(llvm::PointerType::get(T(Byte::type()), 0)))), V(index))),
+	    T(llvm::PointerType::get(T(type), 0)));
 }
 
 Value *Nucleus::createAtomicAdd(Value *ptr, Value *value, std::memory_order memoryOrder)
@@ -1454,7 +1458,7 @@
 	if(!V(v)->getType()->isVectorTy() && T(destType)->isVectorTy())
 	{
 		Value *readAddress = allocateStackVariable(destType);
-		Value *writeAddress = createBitCast(readAddress, T(llvm::PointerType::get(*jit->context, 0)));
+		Value *writeAddress = createBitCast(readAddress, T(llvm::PointerType::get(V(v)->getType(), 0)));
 		createStore(v, writeAddress, T(V(v)->getType()));
 		return createLoad(readAddress, destType);
 	}
@@ -1462,7 +1466,7 @@
 	{
 		Value *writeAddress = allocateStackVariable(T(V(v)->getType()));
 		createStore(v, writeAddress, T(V(v)->getType()));
-		Value *readAddress = createBitCast(writeAddress, T(llvm::PointerType::get(*jit->context, 0)));
+		Value *readAddress = createBitCast(writeAddress, T(llvm::PointerType::get(T(destType), 0)));
 		return createLoad(readAddress, destType);
 	}
 
@@ -1680,7 +1684,7 @@
 
 Type *Nucleus::getPointerType(Type *ElementType)
 {
-	return T(llvm::PointerType::get(*jit->context, 0));
+	return T(llvm::PointerType::get(T(ElementType), 0));
 }
 
 static llvm::Type *getNaturalIntType()
@@ -1767,7 +1771,7 @@
 Value *Nucleus::createNullPointer(Type *Ty)
 {
 	RR_DEBUG_INFO_UPDATE_LOC();
-	return V(llvm::ConstantPointerNull::get(llvm::PointerType::get(*jit->context, 0)));
+	return V(llvm::ConstantPointerNull::get(llvm::PointerType::get(T(Ty), 0)));
 }
 
 Value *Nucleus::createConstantVector(std::vector<int64_t> constants, Type *type)
@@ -3404,7 +3408,8 @@
 	for(auto ty : argTys) { paramTys.push_back(T(ty)); }
 	auto funcTy = llvm::FunctionType::get(T(retTy), paramTys, false);
 
-	auto funcPtr = jit->builder->CreatePointerCast(V(fptr.value()), jit->builder->getPtrTy());
+	auto funcPtrTy = funcTy->getPointerTo();
+	auto funcPtr = jit->builder->CreatePointerCast(V(fptr.value()), funcPtrTy);
 
 	llvm::SmallVector<llvm::Value *, 8> arguments;
 	for(auto arg : args) { arguments.push_back(V(arg)); }
@@ -3868,6 +3873,7 @@
 	auto i32Ty = llvm::Type::getInt32Ty(*jit->context);
 	auto i8PtrTy = our_getInt8PtrTy(*jit->context);
 	auto promiseTy = jit->coroutine.yieldType;
+	auto promisePtrTy = promiseTy->getPointerTo();
 
 	// LLVM intrinsics
 	auto coro_id = GET_INTRINSIC_DECLARATION(jit->module.get(), llvm::Intrinsic::coro_id);
@@ -3921,7 +3927,7 @@
 		jit->builder->SetInsertPoint(resumeBlock);
 		auto promiseAlignment = llvm::ConstantInt::get(i32Ty, 4);  // TODO: Get correct alignment.
 		auto promisePtr = jit->builder->CreateCall(coro_promise, { handle, promiseAlignment, llvm::ConstantInt::get(i1Ty, 0) });
-		auto promise = jit->builder->CreateLoad(promiseTy, jit->builder->CreatePointerCast(promisePtr, jit->builder->getPtrTy()));
+		auto promise = jit->builder->CreateLoad(promiseTy, jit->builder->CreatePointerCast(promisePtr, promisePtrTy));
 		jit->builder->CreateStore(promise, outPtr);
 		jit->builder->CreateCall(coro_resume, { handle });
 		jit->builder->CreateRet(llvm::ConstantInt::getTrue(i1Ty));
@@ -4034,6 +4040,7 @@
 	auto handleTy = i8PtrTy;
 	auto boolTy = i1Ty;
 	auto promiseTy = T(YieldType);
+	auto promisePtrTy = promiseTy->getPointerTo();
 
 	jit->function = rr::createFunction("coroutine_begin", handleTy, T(Params));
 #if LLVM_VERSION_MAJOR >= 16
@@ -4041,7 +4048,7 @@
 #else
 	jit->function->addFnAttr("coroutine.presplit", "0");
 #endif
-	jit->coroutine.await = rr::createFunction("coroutine_await", boolTy, { handleTy, jit->builder->getPtrTy() });
+	jit->coroutine.await = rr::createFunction("coroutine_await", boolTy, { handleTy, promisePtrTy });
 	jit->coroutine.destroy = rr::createFunction("coroutine_destroy", voidTy, { handleTy });
 	jit->coroutine.yieldType = promiseTy;
 	jit->coroutine.entryBlock = llvm::BasicBlock::Create(*jit->context, "function", jit->function);