}
+static LLVMBuilderRef
+create_builder_at_entry(struct gallivm_state *gallivm)
+{
+ LLVMBuilderRef builder = gallivm->builder;
+ LLVMBasicBlockRef current_block = LLVMGetInsertBlock(builder);
+ LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
+ LLVMBasicBlockRef first_block = LLVMGetEntryBasicBlock(function);
+ LLVMValueRef first_instr = LLVMGetFirstInstruction(first_block);
+ LLVMBuilderRef first_builder = LLVMCreateBuilderInContext(gallivm->context);
+
+ if (first_instr) {
+ LLVMPositionBuilderBefore(first_builder, first_instr);
+ } else {
+ LLVMPositionBuilderAtEnd(first_builder, first_block);
+ }
+
+ return first_builder;
+}
+
+
/**
* Allocate a scalar (or vector) variable.
*
const char *name)
{
LLVMBuilderRef builder = gallivm->builder;
- LLVMBasicBlockRef current_block = LLVMGetInsertBlock(builder);
- LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
- LLVMBasicBlockRef first_block = LLVMGetEntryBasicBlock(function);
- LLVMValueRef first_instr = LLVMGetFirstInstruction(first_block);
- LLVMBuilderRef first_builder = LLVMCreateBuilderInContext(gallivm->context);
+ LLVMBuilderRef first_builder = create_builder_at_entry(gallivm);
LLVMValueRef res;
- if (first_instr) {
- LLVMPositionBuilderBefore(first_builder, first_instr);
- } else {
- LLVMPositionBuilderAtEnd(first_builder, first_block);
- }
-
res = LLVMBuildAlloca(first_builder, type, name);
LLVMBuildStore(builder, LLVMConstNull(type), res);
LLVMValueRef count,
const char *name)
{
- LLVMBuilderRef builder = gallivm->builder;
- LLVMBasicBlockRef current_block = LLVMGetInsertBlock(builder);
- LLVMValueRef function = LLVMGetBasicBlockParent(current_block);
- LLVMBasicBlockRef first_block = LLVMGetEntryBasicBlock(function);
- LLVMValueRef first_instr = LLVMGetFirstInstruction(first_block);
- LLVMBuilderRef first_builder = LLVMCreateBuilderInContext(gallivm->context);
+ LLVMBuilderRef first_builder = create_builder_at_entry(gallivm);
LLVMValueRef res;
- if (first_instr) {
- LLVMPositionBuilderBefore(first_builder, first_instr);
- } else {
- LLVMPositionBuilderAtEnd(first_builder, first_block);
- }
-
res = LLVMBuildArrayAlloca(first_builder, type, count, name);
LLVMDisposeBuilder(first_builder);