void dCILInstrPhy::ApplyConstantPropagationSSA (dConstantPropagationSolver& solver)
{
	dList<dArg> constList;
	for (dList<dArgPair>::dListNode* node = m_sources.GetFirst(); node; node = node->GetNext()) {
		const dArg* const arg = node->GetInfo().m_intructionNode ? node->GetInfo().m_intructionNode->GetInfo()->GetGeneratedVariable() : &node->GetInfo().m_arg;

		if ((arg->GetType().m_intrinsicType == dCILInstr::m_constInt) || (arg->GetType().m_intrinsicType == dCILInstr::m_constFloat)) {
			constList.Append(*arg);
		} else {
			dAssert(solver.m_variablesList.Find(arg->m_label));
			dConstantPropagationSolver::dVariable& variable = solver.m_variablesList.Find(arg->m_label)->GetInfo();
			if (variable.m_type == dConstantPropagationSolver::dVariable::m_variableValue) {
				dAssert (0);
				return; 
			}
			if (variable.m_type != dConstantPropagationSolver::dVariable::m_undefined) {
				dAssert (variable.m_type == dConstantPropagationSolver::dVariable::m_constant);
				constList.Append (dArg (variable.m_constValue, arg->GetType()));
			}
		}
	}

	if (constList.GetCount()) {
		bool equal = true;
		const dString& value = constList.GetFirst()->GetInfo().m_label; 
		for (dList<dArg>::dListNode* node = constList.GetFirst()->GetNext(); node; node = node->GetNext()) {
			equal &= (value == node->GetInfo().m_label);
		}
		if (equal) {
			solver.UpdateLatice (m_arg0, value, dConstantPropagationSolver::dVariable::m_constant);
		} else {
			solver.UpdateLatice (m_arg0, value, dConstantPropagationSolver::dVariable::m_variableValue);
		}
	}
}
예제 #2
0
void dCILInstrMove::ApplyConstantPropagationSSA (dConstantPropagationSolver& solver)
{
	//dAssert(solver.m_variablesList.Find(m_arg0.m_label));
	//dConstantPropagationSolver::dVariable& variable = solver.m_variablesList.Find(m_arg0.m_label)->GetInfo();

	dConstantPropagationSolver::dVariable::dValueTypes type = dConstantPropagationSolver::dVariable::m_undefined;
	dString value ("");
	if ((m_arg1.GetType().m_intrinsicType == m_constInt) || (m_arg1.GetType().m_intrinsicType == m_constFloat)) {
		type = dConstantPropagationSolver::dVariable::m_constant;
		value = m_arg1.m_label;
		//variable.m_value = dConstantPropagationSolver::dVariable::m_constant;
		//variable.m_constValue = m_arg1.m_label;
	} else {
		dConstantPropagationSolver::dVariable& variable = solver.m_variablesList.Find(m_arg1.m_label)->GetInfo();
		type = variable.m_type;
		value = variable.m_constValue;
	}

	if (type != dConstantPropagationSolver::dVariable::m_undefined) {
		solver.UpdateLatice (m_arg0, value, type);
	}
}