File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -106,7 +106,18 @@ std::shared_ptr<ExecutableCode> LLVMCodeBuilder::finalize()
106106 // All variables are currently created on the stack and synced later (seems to be faster)
107107 // NOTE: Strings are NOT copied, only the pointer and string size are copied
108108 varPtr.stackPtr = m_builder.CreateAlloca (m_valueDataType);
109- varPtr.onStack = false ; // use heap before the first assignment
109+
110+ // If there are no write operations outside loops, initialize the stack variable now
111+ Variable *variable = var;
112+ auto it = std::find_if (m_variableInstructions.begin (), m_variableInstructions.end (), [variable](const std::shared_ptr<LLVMInstruction> &ins) {
113+ return ins->type == LLVMInstruction::Type::WriteVariable && ins->workVariable == variable && !ins->loopScope ;
114+ });
115+
116+ if (it == m_variableInstructions.end ()) {
117+ createValueCopy (ptr, varPtr.stackPtr );
118+ varPtr.onStack = true ;
119+ } else
120+ varPtr.onStack = false ; // use heap before the first assignment
110121 }
111122
112123 // Create list pointers
You can’t perform that action at this time.
0 commit comments