mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 21:31:24 +01:00
Use static allocas for temporaries. (#5734)
Previously we created allocas for temporaries at whatever point in the output LLVM function we'd reached. This would result in these being dynamic allocas (performing a dynamic stack allocation), which is inefficent and can lead to a stack overflow if it happens in a loop. Switch to putting the allocas in the entry block instead, and instead generate a lifetime start marker when we reach the point where the temporary is introduced. We already did this for local variables; this is just factoring out and reusing that code.
This commit is contained in:
+8
-3
@@ -33,6 +33,7 @@ fn G() -> i32 {
|
||||
// CHECK:STDOUT: define i32 @_CG.Main() !dbg !9 {
|
||||
// CHECK:STDOUT: entry:
|
||||
// CHECK:STDOUT: %.loc18_20.3.temp = alloca [3 x i32], align 4, !dbg !10
|
||||
// CHECK:STDOUT: call void @llvm.lifetime.start.p0(i64 12, ptr %.loc18_20.3.temp), !dbg !10
|
||||
// CHECK:STDOUT: %.loc18_20.4.array.index = getelementptr inbounds [3 x i32], ptr %.loc18_20.3.temp, i32 0, i64 0, !dbg !10
|
||||
// CHECK:STDOUT: %.loc18_20.7.array.index = getelementptr inbounds [3 x i32], ptr %.loc18_20.3.temp, i32 0, i64 1, !dbg !10
|
||||
// CHECK:STDOUT: %.loc18_20.10.array.index = getelementptr inbounds [3 x i32], ptr %.loc18_20.3.temp, i32 0, i64 2, !dbg !10
|
||||
@@ -41,10 +42,14 @@ fn G() -> i32 {
|
||||
// CHECK:STDOUT: ret i32 %F.call, !dbg !12
|
||||
// CHECK:STDOUT: }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
|
||||
// CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #0
|
||||
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
|
||||
// CHECK:STDOUT: declare void @llvm.lifetime.start.p0(i64 immarg, ptr captures(none)) #0
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
|
||||
// CHECK:STDOUT: ; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
|
||||
// CHECK:STDOUT: declare void @llvm.memcpy.p0.p0.i64(ptr noalias writeonly captures(none), ptr noalias readonly captures(none), i64, i1 immarg) #1
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
|
||||
// CHECK:STDOUT: attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
|
||||
// CHECK:STDOUT:
|
||||
// CHECK:STDOUT: !llvm.module.flags = !{!0, !1}
|
||||
// CHECK:STDOUT: !llvm.dbg.cu = !{!2}
|
||||
|
||||
Reference in New Issue
Block a user