Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare variables using builder0 to allocate #2790

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/libasr/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3541,7 +3541,6 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>

template<typename T>
void declare_vars(const T &x, bool create_vtabs=true) {
get_builder0()
llvm::Value *target_var;
uint32_t debug_arg_count = 0;
std::vector<std::string> var_order = ASRUtils::determine_variable_declaration_order(x.m_symtab);
Expand Down Expand Up @@ -3666,7 +3665,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
llvm::Constant *init_value = llvm::Constant::getNullValue(type);
gptr->setInitializer(init_value);
} else {
ptr = builder->CreateAlloca(type, array_size, v->m_name);
get_builder0()
ptr = builder0.CreateAlloca(type, array_size, v->m_name);
}
}
set_pointer_variable_to_null(llvm::ConstantPointerNull::get(
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/llvm-expr_01-54467c1.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm-expr_01-54467c1.stdout",
"stdout_hash": "951a792984bf209b37aafc95435eb319906b5c9cb22a62a018556f06",
"stdout_hash": "959f37d41e451c0bbd728144640ad29bad8eb6dfbaf71e1bd2d45b41",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
6 changes: 3 additions & 3 deletions tests/reference/llvm-expr_01-54467c1.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ return: ; preds = %.entry

define void @__module___main___main0() {
.entry:
%x = alloca i32, align 4
%x2 = alloca i64, align 8
%y = alloca float, align 4
%y2 = alloca double, align 8
%y = alloca float, align 4
%x2 = alloca i64, align 8
%x = alloca i32, align 4
store i32 25, i32* %x, align 4
%0 = load i32, i32* %x, align 4
call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0), i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0))
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/llvm-func_inline_01-2d4583a.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm-func_inline_01-2d4583a.stdout",
"stdout_hash": "3d0670fb3a5502d046ad0acaa0b5d0f06cd05285df45bef0eca0b626",
"stdout_hash": "1c8552bcbbcba5edca127739cb9b5bb01968019462c909cee8aa26ad",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/llvm-func_inline_01-2d4583a.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ return: ; preds = %unreachable_after_r

define void @__module___main____xx_lcompilers_changed_main_xx() {
.entry:
%ans = alloca i64, align 8
%x = alloca i64, align 8
%ans = alloca i64, align 8
store i64 40, i64* %x, align 4
%0 = call i64 @__module___main___fib(i64* %x)
store i64 %0, i64* %ans, align 4
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/llvm-test_unary_op_03-046fb86.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm-test_unary_op_03-046fb86.stdout",
"stdout_hash": "8ae64ade26bcceb59c961b87142054ab443d47b4467569b01d9d24f9",
"stdout_hash": "64ad587abac8ae2bc570c04dc969a26374e4abcba7a02f051325c816",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/llvm-test_unary_op_03-046fb86.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ return: ; preds = %.entry

define void @__module___main___f() {
.entry:
%i = alloca i32, align 4
%res = alloca i32, align 4
%i = alloca i32, align 4
store i32 5, i32* %i, align 4
%0 = load i32, i32* %i, align 4
%1 = xor i32 %0, -1
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/llvm_dbg-expr_01-9fc5f30.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm_dbg-expr_01-9fc5f30.stdout",
"stdout_hash": "70643017f0ad204393988f111369cdd921c1c297149078182707cb54",
"stdout_hash": "8270bd08ebf0a1ff9ee16359845337e4d39c2affdf7c5c10eb213c9b",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
67 changes: 33 additions & 34 deletions tests/reference/llvm_dbg-expr_01-9fc5f30.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -16,33 +16,33 @@ return: ; preds = %.entry

define void @__module___main___main0() !dbg !7 {
.entry:
%x = alloca i32, align 4, !dbg !8
call void @llvm.dbg.declare(metadata i32* %x, metadata !9, metadata !DIExpression()), !dbg !11
%x2 = alloca i64, align 8
call void @llvm.dbg.declare(metadata i64* %x2, metadata !12, metadata !DIExpression()), !dbg !14
%y = alloca float, align 4
call void @llvm.dbg.declare(metadata float* %y, metadata !15, metadata !DIExpression()), !dbg !17
%y2 = alloca double, align 8
call void @llvm.dbg.declare(metadata double* %y2, metadata !18, metadata !DIExpression()), !dbg !20
store i32 25, i32* %x, align 4, !dbg !21
%0 = load i32, i32* %x, align 4, !dbg !21
call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0), i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0)), !dbg !21
br label %return, !dbg !21
%y = alloca float, align 4
%x2 = alloca i64, align 8
%x = alloca i32, align 4
call void @llvm.dbg.declare(metadata i32* %x, metadata !8, metadata !DIExpression()), !dbg !10
call void @llvm.dbg.declare(metadata i64* %x2, metadata !11, metadata !DIExpression()), !dbg !13
call void @llvm.dbg.declare(metadata float* %y, metadata !14, metadata !DIExpression()), !dbg !16
call void @llvm.dbg.declare(metadata double* %y2, metadata !17, metadata !DIExpression()), !dbg !19
store i32 25, i32* %x, align 4, !dbg !20
%0 = load i32, i32* %x, align 4, !dbg !20
call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0), i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0)), !dbg !20
br label %return, !dbg !20

return: ; preds = %.entry
ret void, !dbg !21
ret void, !dbg !20
}

; Function Attrs: nounwind readnone speculatable willreturn
declare void @llvm.dbg.declare(metadata, metadata, metadata) #0

declare void @_lfortran_printf(i8*, ...)

define i32 @main(i32 %0, i8** %1) !dbg !22 {
define i32 @main(i32 %0, i8** %1) !dbg !21 {
.entry:
call void @_lpython_call_initial_functions(i32 %0, i8** %1), !dbg !25
call void @__module___main_____main__global_stmts(), !dbg !25
ret i32 0, !dbg !25
call void @_lpython_call_initial_functions(i32 %0, i8** %1), !dbg !24
call void @__module___main_____main__global_stmts(), !dbg !24
ret i32 0, !dbg !24
}

declare void @_lpython_call_initial_functions(i32, i8**)
Expand All @@ -59,21 +59,20 @@ attributes #0 = { nounwind readnone speculatable willreturn }
!5 = !{null}
!6 = !DILocation(line: 9, column: 1, scope: !3)
!7 = distinct !DISubprogram(name: "main0", scope: !1, file: !1, line: 1, type: !4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
!8 = !DILocation(line: 1, column: 1, scope: !7)
!9 = !DILocalVariable(name: "x", arg: 1, scope: !7, file: !1, line: 2, type: !10)
!10 = !DIBasicType(name: "integer", size: 32, encoding: DW_ATE_signed)
!11 = !DILocation(line: 2, scope: !7)
!12 = !DILocalVariable(name: "x2", arg: 2, scope: !7, file: !1, line: 3, type: !13)
!13 = !DIBasicType(name: "integer", size: 64, encoding: DW_ATE_signed)
!14 = !DILocation(line: 3, scope: !7)
!15 = !DILocalVariable(name: "y", arg: 3, scope: !7, file: !1, line: 4, type: !16)
!16 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
!17 = !DILocation(line: 4, scope: !7)
!18 = !DILocalVariable(name: "y2", arg: 4, scope: !7, file: !1, line: 5, type: !19)
!19 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)
!20 = !DILocation(line: 5, scope: !7)
!21 = !DILocation(line: 6, column: 5, scope: !7)
!22 = distinct !DISubprogram(name: "main_program", scope: !1, file: !1, line: 1, type: !23, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
!23 = !DISubroutineType(types: !24)
!24 = !{!10}
!25 = !DILocation(line: 1, column: 1, scope: !22)
!8 = !DILocalVariable(name: "x", arg: 1, scope: !7, file: !1, line: 2, type: !9)
!9 = !DIBasicType(name: "integer", size: 32, encoding: DW_ATE_signed)
!10 = !DILocation(line: 2, scope: !7)
!11 = !DILocalVariable(name: "x2", arg: 2, scope: !7, file: !1, line: 3, type: !12)
!12 = !DIBasicType(name: "integer", size: 64, encoding: DW_ATE_signed)
!13 = !DILocation(line: 3, scope: !7)
!14 = !DILocalVariable(name: "y", arg: 3, scope: !7, file: !1, line: 4, type: !15)
!15 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
!16 = !DILocation(line: 4, scope: !7)
!17 = !DILocalVariable(name: "y2", arg: 4, scope: !7, file: !1, line: 5, type: !18)
!18 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)
!19 = !DILocation(line: 5, scope: !7)
!20 = !DILocation(line: 6, column: 5, scope: !7)
!21 = distinct !DISubprogram(name: "main_program", scope: !1, file: !1, line: 1, type: !22, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
!22 = !DISubroutineType(types: !23)
!23 = !{!9}
!24 = !DILocation(line: 1, column: 1, scope: !21)
Loading