@@ -63,37 +63,6 @@ Compiler::StaticType LLVMTypeAnalyzer::variableType(LLVMVariablePtr *varPtr, LLV
6363 return previousType;
6464}
6565
66- bool LLVMTypeAnalyzer::variableTypeChangesInBranch (LLVMVariablePtr *varPtr, LLVMInstruction *start, Compiler::StaticType previousType) const
67- {
68- if (!varPtr || !start)
69- return false ;
70-
71- assert (isLoopStart (start) || isIfStart (start) || isElse (start));
72-
73- // Find loop/if statement end or else branch
74- LLVMInstruction *ins = start->next ;
75- int level = 0 ;
76-
77- while (ins && !((isLoopEnd (ins) || isIfEnd (ins) || isElse (ins)) && level == 0 )) {
78- if (isLoopStart (ins) || isIfStart (ins))
79- level++;
80- else if (isLoopEnd (ins) || isIfEnd (ins)) {
81- assert (level > 0 );
82- level--;
83- }
84-
85- ins = ins->next ;
86- }
87-
88- if (!ins) {
89- assert (false );
90- return true ;
91- }
92-
93- // Process the branch from end
94- return variableTypeChangesInBranchFromEnd (varPtr, ins, previousType);
95- }
96-
9766Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranch (LLVMVariablePtr *varPtr, LLVMInstruction *start, Compiler::StaticType previousType) const
9867{
9968 if (!varPtr || !start)
@@ -129,66 +98,45 @@ Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranchFromEnd(LLVMVariab
12998{
13099 // Find the last write instruction
131100 LLVMInstruction *ins = end->previous ;
101+ bool typeMightReset = false ;
132102
133103 while (ins && !isLoopStart (ins) && !isIfStart (ins)) {
134104 if (isLoopEnd (ins) || isIfEnd (ins) || isElse (ins)) {
135105 // Process the nested loop or if statement
136106 Compiler::StaticType ret = variableTypeAfterBranchFromEnd (varPtr, ins, previousType);
137107
138- if (!typesMatch (ret, previousType))
139- return ret;
108+ if (typesMatch (ret, previousType))
109+ typeMightReset = true ;
110+ else
111+ return Compiler::StaticType::Unknown;
140112
141113 ins = skipBranch (ins);
142114
143115 if (isElse (ins)) {
144116 // Process if branch (the else branch is already processed)
145117 ret = variableTypeAfterBranchFromEnd (varPtr, ins, previousType);
146118
147- if (!typesMatch (ret, previousType))
148- return ret;
119+ if (typesMatch (ret, previousType))
120+ typeMightReset = true ;
121+ else
122+ return Compiler::StaticType::Unknown;
149123
150124 ins = skipBranch (ins);
151125 }
152126 } else if (ins->type == LLVMInstruction::Type::WriteVariable && ins->workVariable == varPtr->var ) {
153127 // Variable write instruction
154- return writeValueType (ins);
155- }
156-
157- ins = ins->previous ;
158- }
159-
160- return previousType;
161- }
162-
163- bool LLVMTypeAnalyzer::variableTypeChangesInBranchFromEnd (LLVMVariablePtr *varPtr, LLVMInstruction *end, Compiler::StaticType previousType) const
164- {
165- // Find the last write instruction
166- LLVMInstruction *ins = end->previous ;
167-
168- while (ins && !isLoopStart (ins) && !isIfStart (ins)) {
169- if (isLoopEnd (ins) || isIfEnd (ins) || isElse (ins)) {
170- // Process the nested loop or if statement
171- if (variableTypeChangesInBranchFromEnd (varPtr, ins, previousType))
172- return true ;
128+ Compiler::StaticType writeType = writeValueType (ins);
173129
174- ins = skipBranch (ins);
175-
176- if (isElse (ins)) {
177- // Process if branch (the else branch is already processed)
178- if (variableTypeChangesInBranchFromEnd (varPtr, ins, previousType))
179- return true ;
180-
181- ins = skipBranch (ins);
182- }
183- } else if (ins->type == LLVMInstruction::Type::WriteVariable && ins->workVariable == varPtr->var ) {
184- // Variable write instruction
185- return !writeTypesMatch (ins, previousType);
130+ if (typesMatch (writeType, previousType))
131+ return writeType;
132+ else
133+ return typeMightReset ? Compiler::StaticType::Unknown : writeType;
186134 }
187135
188136 ins = ins->previous ;
189137 }
190138
191- return false ;
139+ return previousType ;
192140}
193141
194142LLVMInstruction *LLVMTypeAnalyzer::skipBranch (LLVMInstruction *pos) const
0 commit comments