const slang_ir_info *info = _slang_ir_info(n->Opcode);
char *srcAnnot[3], *dstAnnot;
GLuint i;
+ slang_ir_node *temps[3];
+
+ /* we'll save pointers to nodes/storage to free in temps[] until
+ * the very end.
+ */
+ temps[0] = temps[1] = temps[2] = NULL;
assert(info);
assert(info->InstOpcode != OPCODE_NOP);
storage_to_src_reg(&inst->SrcReg[0], n->Children[0]->Children[0]->Store);
storage_to_src_reg(&inst->SrcReg[1], n->Children[0]->Children[1]->Store);
storage_to_src_reg(&inst->SrcReg[2], n->Children[1]->Store);
- free_temp_storage(emitInfo->vt, n->Children[0]->Children[0]);
- free_temp_storage(emitInfo->vt, n->Children[0]->Children[1]);
- free_temp_storage(emitInfo->vt, n->Children[1]);
+ temps[0] = n->Children[0]->Children[0];
+ temps[1] = n->Children[0]->Children[1];
+ temps[2] = n->Children[1];
}
else if (info->NumParams == 2 &&
n->Opcode == IR_ADD && n->Children[1]->Opcode == IR_MUL) {
storage_to_src_reg(&inst->SrcReg[0], n->Children[1]->Children[0]->Store);
storage_to_src_reg(&inst->SrcReg[1], n->Children[1]->Children[1]->Store);
storage_to_src_reg(&inst->SrcReg[2], n->Children[0]->Store);
- free_temp_storage(emitInfo->vt, n->Children[1]->Children[0]);
- free_temp_storage(emitInfo->vt, n->Children[1]->Children[1]);
- free_temp_storage(emitInfo->vt, n->Children[0]);
+ temps[0] = n->Children[1]->Children[0];
+ temps[1] = n->Children[1]->Children[1];
+ temps[2] = n->Children[0];
}
else
#endif
for (i = 0; i < info->NumParams; i++)
srcAnnot[i] = storage_annotation(n->Children[i], emitInfo->prog);
- /* free temps */
+ /* record (potential) temps to free */
for (i = 0; i < info->NumParams; i++)
- free_temp_storage(emitInfo->vt, n->Children[i]);
+ temps[i] = n->Children[i];
}
/* result storage */
if (!alloc_temp_storage(emitInfo, n, size))
return NULL;
}
+
storage_to_dst_reg(&inst->DstReg, n->Store, n->Writemask);
dstAnnot = storage_annotation(n, emitInfo->prog);
inst->Comment = instruction_annotation(inst->Opcode, dstAnnot, srcAnnot[0],
srcAnnot[1], srcAnnot[2]);
+ /* really free temps now */
+ for (i = 0; i < 3; i++)
+ if (temps[i])
+ free_temp_storage(emitInfo->vt, temps[i]);
+
/*_mesa_print_instruction(inst);*/
return inst;
}