Skip to content

Commit 005357a

Browse files
committed
LLVMTypeAnalyzer: skipBranch() -> branchStart()
1 parent 547c506 commit 005357a

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/engine/internal/llvm/llvmtypeanalyzer.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Compiler::StaticType LLVMTypeAnalyzer::variableType(Variable *var, LLVMInstructi
6262
} else if (isElse(ins)) {
6363
// Skip if branch if coming from else
6464
firstElseBranch = ins;
65-
ins = skipBranch(ins);
65+
ins = branchStart(ins);
6666
continue;
6767
} else if (isVariableWrite(ins, var) && !isWriteNoOp(ins)) {
6868
if (level <= 0) { // ignore nested branches (they're handled by the branch analyzer)
@@ -134,7 +134,7 @@ Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranchFromEnd(Variable *
134134
} else
135135
return Compiler::StaticType::Unknown;
136136

137-
ins = skipBranch(ins);
137+
ins = branchStart(ins);
138138

139139
if (isElse(ins)) {
140140
// Process if branch (the else branch is already processed)
@@ -150,7 +150,7 @@ Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranchFromEnd(Variable *
150150
} else
151151
return Compiler::StaticType::Unknown;
152152

153-
ins = skipBranch(ins);
153+
ins = branchStart(ins);
154154
}
155155
} else if (isVariableWrite(ins, var) && !isWriteNoOp(ins)) {
156156
// Variable write instruction
@@ -194,29 +194,33 @@ LLVMInstruction *LLVMTypeAnalyzer::branchEnd(LLVMInstruction *start) const
194194
return ins;
195195
}
196196

197-
LLVMInstruction *LLVMTypeAnalyzer::skipBranch(LLVMInstruction *pos) const
197+
LLVMInstruction *LLVMTypeAnalyzer::branchStart(LLVMInstruction *end) const
198198
{
199+
assert(end);
200+
assert(isLoopEnd(end) || isIfEnd(end) || isElse(end));
201+
202+
// Find loop/if statement/else branch start
203+
LLVMInstruction *ins = end->previous;
199204
int level = 0;
200-
pos = pos->previous;
201205

202-
while (pos && !((isLoopStart(pos) || isIfStart(pos)) && level == 0)) {
203-
if (isLoopStart(pos) || isIfStart(pos)) {
206+
while (ins && !((isLoopStart(ins) || isIfStart(ins)) && level == 0)) {
207+
if (isLoopStart(ins) || isIfStart(ins)) {
204208
assert(level > 0);
205209
level--;
206210
}
207211

208-
if (isLoopEnd(pos) || isIfEnd(pos) || isElse(pos)) {
209-
if (isElse(pos) && level == 0)
212+
if (isLoopEnd(ins) || isIfEnd(ins) || isElse(ins)) {
213+
if (isElse(ins) && level == 0)
210214
break;
211215

212216
level++;
213217
}
214218

215-
pos = pos->previous;
219+
ins = ins->previous;
216220
};
217221

218-
assert(pos);
219-
return pos;
222+
assert(ins);
223+
return ins;
220224
}
221225

222226
bool LLVMTypeAnalyzer::isLoopStart(LLVMInstruction *ins) const

src/engine/internal/llvm/llvmtypeanalyzer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class LLVMTypeAnalyzer
2222
Compiler::StaticType variableTypeAfterBranchFromEnd(Variable *var, LLVMInstruction *end, Compiler::StaticType previousType, bool &write, InstructionSet &visitedInstructions) const;
2323

2424
LLVMInstruction *branchEnd(LLVMInstruction *start) const;
25-
LLVMInstruction *skipBranch(LLVMInstruction *pos) const;
25+
LLVMInstruction *branchStart(LLVMInstruction *end) const;
2626

2727
bool isLoopStart(LLVMInstruction *ins) const;
2828
bool isLoopEnd(LLVMInstruction *ins) const;

0 commit comments

Comments
 (0)