aboutsummaryrefslogtreecommitdiff
path: root/src/zig_llvm.cpp
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2022-08-21 01:32:19 +0200
committerRobin Voetter <robin@voetter.nl>2022-10-12 20:34:42 +0200
commit5f3b91437f5cd23bcae66227932555b7abe32669 (patch)
tree3d1db6c0e791e7b206ea4eb88abdad252f3901bd /src/zig_llvm.cpp
parent3392de87dcf516ed2e3fd1904372195bdc75c0eb (diff)
downloadzig-5f3b91437f5cd23bcae66227932555b7abe32669.tar.gz
zig-5f3b91437f5cd23bcae66227932555b7abe32669.zip
stage2: improve addrspace handling
This commit changes the way Zig is intended to deal with variable declaration for exotic targets. Where previously the idea was to enfore local/global variables to be placed into their respective address spaces, depending on the target, this is now fixed to the generic address space. To facilitate this for targets where local variables _must_ be generated into a specific address space (ex. amdgcn where locals must be generated into the private address space), the variable allocations (alloca) are generated into the right address space and then addrspace-casted back to the generic address space. While this could be less efficient in theory, LLVM will hopefull deal with figuring out the actual correct address space for a pointer for us. HIP seems to do the same thing in this regard. Global variables are handled in a similar way.
Diffstat (limited to 'src/zig_llvm.cpp')
-rw-r--r--src/zig_llvm.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp
index 4f9cd76c6a..b5edb336a5 100644
--- a/src/zig_llvm.cpp
+++ b/src/zig_llvm.cpp
@@ -512,22 +512,22 @@ LLVMValueRef ZigLLVMBuildUSubSat(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRe
LLVMValueRef ZigLLVMBuildSMulFixSat(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *name) {
llvm::Type* types[1] = {
- unwrap(LHS)->getType(),
+ unwrap(LHS)->getType(),
};
// pass scale = 0 as third argument
llvm::Value* values[3] = {unwrap(LHS), unwrap(RHS), unwrap(B)->getInt32(0)};
-
+
CallInst *call_inst = unwrap(B)->CreateIntrinsic(Intrinsic::smul_fix_sat, types, values, nullptr, name);
return wrap(call_inst);
}
LLVMValueRef ZigLLVMBuildUMulFixSat(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS, const char *name) {
llvm::Type* types[1] = {
- unwrap(LHS)->getType(),
+ unwrap(LHS)->getType(),
};
// pass scale = 0 as third argument
llvm::Value* values[3] = {unwrap(LHS), unwrap(RHS), unwrap(B)->getInt32(0)};
-
+
CallInst *call_inst = unwrap(B)->CreateIntrinsic(Intrinsic::umul_fix_sat, types, values, nullptr, name);
return wrap(call_inst);
}
@@ -808,7 +808,7 @@ void ZigLLVMSetCurrentDebugLocation2(LLVMBuilderRef builder, unsigned int line,
unsigned int column, ZigLLVMDIScope *scope, ZigLLVMDILocation *inlined_at)
{
DIScope* di_scope = reinterpret_cast<DIScope*>(scope);
- DebugLoc debug_loc = DILocation::get(di_scope->getContext(), line, column, di_scope,
+ DebugLoc debug_loc = DILocation::get(di_scope->getContext(), line, column, di_scope,
reinterpret_cast<DILocation *>(inlined_at), false);
unwrap(builder)->SetCurrentDebugLocation(debug_loc);
}
@@ -1177,9 +1177,14 @@ LLVMValueRef ZigLLVMBuildAShrExact(LLVMBuilderRef builder, LLVMValueRef LHS, LLV
return wrap(unwrap(builder)->CreateAShr(unwrap(LHS), unwrap(RHS), name, true));
}
+LLVMValueRef ZigLLVMBuildAllocaInAddressSpace(LLVMBuilderRef builder, LLVMTypeRef Ty,
+ unsigned AddressSpace, const char *Name) {
+ return wrap(unwrap(builder)->CreateAlloca(unwrap(Ty), AddressSpace, nullptr, Name));
+}
+
void ZigLLVMSetTailCall(LLVMValueRef Call) {
unwrap<CallInst>(Call)->setTailCallKind(CallInst::TCK_MustTail);
-}
+}
void ZigLLVMSetCallSret(LLVMValueRef Call, LLVMTypeRef return_type) {
CallInst *call_inst = unwrap<CallInst>(Call);