@@ -63,26 +63,12 @@ void LLVMBuildUtils::init(llvm::Function *function, BlockPrototype *procedurePro
6363 // Direct access
6464 varPtr.heapPtr = ptr;
6565
66- // All variables are currently created on the stack and synced later (seems to be faster)
66+ // In warp scripts, all variables are created on the stack and synced later (seems to be faster)
6767 // NOTE: Strings are NOT copied, only the pointer is copied
68- // TODO: Restore this feature
69- // varPtr.stackPtr = m_builder.CreateAlloca(m_valueDataType);
70- varPtr.stackPtr = varPtr.heapPtr ;
71- varPtr.onStack = false ;
72-
73- // If there are no write operations outside loops, initialize the stack variable now
74- /* Variable *variable = var;
75- // TODO: Loop scope was used here, replace it with some "inside loop" flag if needed
76- auto it = std::find_if(m_variableInstructions.begin(), m_variableInstructions.end(), [variable](const LLVMInstruction *ins) {
77- return ins->type == LLVMInstruction::Type::WriteVariable && ins->targetVariable == variable && !ins->loopScope;
78- });
79-
80- if (it == m_variableInstructions.end()) {
81- createValueCopy(ptr, varPtr.stackPtr);
82- varPtr.onStack = true;
83- } else
84- varPtr.onStack = false; // use heap before the first assignment
85- */
68+ varPtr.onStack = m_warp;
69+
70+ if (varPtr.onStack )
71+ varPtr.stackPtr = m_builder.CreateAlloca (m_valueDataType);
8672 }
8773
8874 // Create list pointers
@@ -104,6 +90,9 @@ void LLVMBuildUtils::init(llvm::Function *function, BlockPrototype *procedurePro
10490 }
10591 }
10692
93+ reloadVariables (m_targetVariables);
94+ reloadLists ();
95+
10796 // Create end branch
10897 m_endBranch = llvm::BasicBlock::Create (m_llvmCtx, " end" , m_function);
10998}
@@ -313,19 +302,21 @@ void LLVMBuildUtils::syncVariables(llvm::Value *targetVariables)
313302{
314303 // Copy stack variables to the actual variables
315304 for (auto &[var, varPtr] : m_variablePtrs) {
316- if (varPtr.onStack && varPtr. changed )
305+ if (varPtr.onStack )
317306 createValueCopy (varPtr.stackPtr , getVariablePtr (targetVariables, var));
318-
319- varPtr.changed = false ;
320307 }
321308}
322309
323310void LLVMBuildUtils::reloadVariables (llvm::Value *targetVariables)
324311{
325- // Reset variables to use heap
326- for (auto &[var, varPtr] : m_variablePtrs) {
327- varPtr.onStack = false ;
328- varPtr.changed = false ;
312+ // Load variables to stack
313+ if (m_warp) {
314+ for (auto &[var, varPtr] : m_variablePtrs) {
315+ if (varPtr.onStack ) {
316+ llvm::Value *ptr = getVariablePtr (m_targetVariables, var);
317+ createValueCopy (ptr, varPtr.stackPtr );
318+ }
319+ }
329320 }
330321}
331322
0 commit comments