aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-01-08 16:50:16 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-01-08 16:50:16 -0500
commit027a0c46aef9828ab07d6342030c1ba5b5e4f769 (patch)
treee796bb65af29fa7ce53a0076e4c0b3e6932385fd /src/codegen.cpp
parent1ca983dbd7af661d3f1f840138ecba9dc0a6e372 (diff)
parent4d5d0d3adad09e9ce34d281327c424de6402fcdb (diff)
downloadzig-027a0c46aef9828ab07d6342030c1ba5b5e4f769.tar.gz
zig-027a0c46aef9828ab07d6342030c1ba5b5e4f769.zip
Merge remote-tracking branch 'origin/master' into llvm8
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 817cc9aeae..dd2f2b6565 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -649,7 +649,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
ZigLLVMDISubprogram *subprogram = ZigLLVMCreateFunction(g->dbuilder,
fn_di_scope, buf_ptr(&fn_table_entry->symbol_name), "",
import->di_file, line_number,
- fn_table_entry->type_entry->di_type, is_internal_linkage,
+ fn_table_entry->type_entry->data.fn.raw_di_type, is_internal_linkage,
is_definition, scope_line, flags, is_optimized, nullptr);
scope->di_scope = ZigLLVMSubprogramToScope(subprogram);
@@ -3789,6 +3789,11 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *int_type, BuiltinFnI
n_args = 1;
key.id = ZigLLVMFnIdBswap;
key.data.bswap.bit_count = (uint32_t)int_type->data.integral.bit_count;
+ } else if (fn_id == BuiltinFnIdBitReverse) {
+ fn_name = "bitreverse";
+ n_args = 1;
+ key.id = ZigLLVMFnIdBitReverse;
+ key.data.bit_reverse.bit_count = (uint32_t)int_type->data.integral.bit_count;
} else {
zig_unreachable();
}
@@ -5096,6 +5101,14 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInst
return LLVMBuildTrunc(g->builder, shifted, int_type->type_ref, "");
}
+static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutable *executable, IrInstructionBitReverse *instruction) {
+ LLVMValueRef op = ir_llvm_value(g, instruction->op);
+ ZigType *int_type = instruction->base.value.type;
+ assert(int_type->id == ZigTypeIdInt);
+ LLVMValueRef fn_val = get_int_builtin_fn(g, instruction->base.value.type, BuiltinFnIdBitReverse);
+ return LLVMBuildCall(g->builder, fn_val, &op, 1, "");
+}
+
static void set_debug_location(CodeGen *g, IrInstruction *instruction) {
AstNode *source_node = instruction->source_node;
Scope *scope = instruction->scope;
@@ -5335,6 +5348,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
return ir_render_sqrt(g, executable, (IrInstructionSqrt *)instruction);
case IrInstructionIdBswap:
return ir_render_bswap(g, executable, (IrInstructionBswap *)instruction);
+ case IrInstructionIdBitReverse:
+ return ir_render_bit_reverse(g, executable, (IrInstructionBitReverse *)instruction);
}
zig_unreachable();
}
@@ -6758,6 +6773,7 @@ static void define_builtin_fns(CodeGen *g) {
create_builtin_fn(g, BuiltinFnIdFromBytes, "bytesToSlice", 2);
create_builtin_fn(g, BuiltinFnIdThis, "This", 0);
create_builtin_fn(g, BuiltinFnIdBswap, "bswap", 2);
+ create_builtin_fn(g, BuiltinFnIdBitReverse, "bitreverse", 2);
}
static const char *bool_to_str(bool b) {