aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-02-04 21:49:27 -0500
committerAndrew Kelley <superjoe30@gmail.com>2017-02-04 21:49:27 -0500
commit419e75eb2313b4910921185211201317cbbb400c (patch)
tree3ad2166c30e84a6d7ce075fb48741e336eb87027 /src/codegen.cpp
parent0d7abc6368a826490f8985634882300b50d81cba (diff)
downloadzig-419e75eb2313b4910921185211201317cbbb400c.tar.gz
zig-419e75eb2313b4910921185211201317cbbb400c.zip
remove volatileStore builtin; add volatile pointers
closes #238
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 942113d58d..1311dd57e0 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -1294,18 +1294,19 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
LLVMValueRef value = ir_llvm_value(g, instruction->value);
assert(instruction->ptr->value.type->id == TypeTableEntryIdPointer);
- TypeTableEntry *op1_type = instruction->ptr->value.type->data.pointer.child_type;
+ TypeTableEntry *ptr_type = get_underlying_type(instruction->ptr->value.type);
+ TypeTableEntry *child_type = get_underlying_type(ptr_type->data.pointer.child_type);
- if (!type_has_bits(op1_type)) {
+ if (!type_has_bits(child_type)) {
return nullptr;
}
- if (handle_is_ptr(op1_type)) {
- return gen_struct_memcpy(g, value, ptr, op1_type);
+ if (handle_is_ptr(child_type)) {
+ return gen_struct_memcpy(g, value, ptr, child_type);
}
LLVMValueRef llvm_instruction = LLVMBuildStore(g->builder, value, ptr);
- LLVMSetVolatile(llvm_instruction, instruction->is_volatile);
+ LLVMSetVolatile(llvm_instruction, ptr_type->data.pointer.is_volatile);
return nullptr;
}
@@ -1803,12 +1804,15 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");
+ LLVMValueRef is_volatile = instruction->is_volatile ?
+ LLVMConstAllOnes(LLVMInt1Type()) : LLVMConstNull(LLVMInt1Type());
+
LLVMValueRef params[] = {
dest_ptr_casted, // dest pointer
char_val, // source pointer
len_val, // byte count
LLVMConstInt(LLVMInt32Type(), 1, false), // align in bytes
- LLVMConstNull(LLVMInt1Type()), // is volatile
+ is_volatile,
};
LLVMBuildCall(g->builder, g->memset_fn_val, params, 5, "");
@@ -1825,12 +1829,15 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns
LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, "");
LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, ptr_u8, "");
+ LLVMValueRef is_volatile = instruction->is_volatile ?
+ LLVMConstAllOnes(LLVMInt1Type()) : LLVMConstNull(LLVMInt1Type());
+
LLVMValueRef params[] = {
dest_ptr_casted, // dest pointer
src_ptr_casted, // source pointer
len_val, // byte count
LLVMConstInt(LLVMInt32Type(), 1, false), // align in bytes
- LLVMConstNull(LLVMInt1Type()), // is volatile
+ is_volatile,
};
LLVMBuildCall(g->builder, g->memcpy_fn_val, params, 5, "");
@@ -3690,7 +3697,6 @@ static void define_builtin_fns(CodeGen *g) {
create_builtin_fn(g, BuiltinFnIdAlloca, "alloca", 2);
create_builtin_fn(g, BuiltinFnIdSetGlobalAlign, "setGlobalAlign", 2);
create_builtin_fn(g, BuiltinFnIdSetGlobalSection, "setGlobalSection", 2);
- create_builtin_fn(g, BuiltinFnIdVolatileStore, "volatileStore", 2);
}
static void init(CodeGen *g, Buf *source_path) {