Skip to content

Commit 4267ba1

Browse files
committed
LLVMTypeAnalyzer: skipBranch() -> branchStart()
1 parent 15e0f4e commit 4267ba1

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)
@@ -135,7 +135,7 @@ LLVMTypeAnalyzer::typeAfterBranchFromEnd(std::variant<Variable *, List *> varOrL
135135
} else
136136
return Compiler::StaticType::Unknown;
137137

138-
ins = skipBranch(ins);
138+
ins = branchStart(ins);
139139

140140
if (isElse(ins)) {
141141
// Process if branch (the else branch is already processed)
@@ -151,7 +151,7 @@ LLVMTypeAnalyzer::typeAfterBranchFromEnd(std::variant<Variable *, List *> varOrL
151151
} else
152152
return Compiler::StaticType::Unknown;
153153

154-
ins = skipBranch(ins);
154+
ins = branchStart(ins);
155155
}
156156
} else if (std::holds_alternative<Variable *>(varOrList), isVariableWrite(ins, std::get<Variable *>(varOrList)) && !isWriteNoOp(ins)) {
157157
// Variable write instruction
@@ -195,29 +195,33 @@ LLVMInstruction *LLVMTypeAnalyzer::branchEnd(LLVMInstruction *start) const
195195
return ins;
196196
}
197197

198-
LLVMInstruction *LLVMTypeAnalyzer::skipBranch(LLVMInstruction *pos) const
198+
LLVMInstruction *LLVMTypeAnalyzer::branchStart(LLVMInstruction *end) const
199199
{
200+
assert(end);
201+
assert(isLoopEnd(end) || isIfEnd(end) || isElse(end));
202+
203+
// Find loop/if statement/else branch start
204+
LLVMInstruction *ins = end->previous;
200205
int level = 0;
201-
pos = pos->previous;
202206

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

209-
if (isLoopEnd(pos) || isIfEnd(pos) || isElse(pos)) {
210-
if (isElse(pos) && level == 0)
213+
if (isLoopEnd(ins) || isIfEnd(ins) || isElse(ins)) {
214+
if (isElse(ins) && level == 0)
211215
break;
212216

213217
level++;
214218
}
215219

216-
pos = pos->previous;
220+
ins = ins->previous;
217221
};
218222

219-
assert(pos);
220-
return pos;
223+
assert(ins);
224+
return ins;
221225
}
222226

223227
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
@@ -25,7 +25,7 @@ class LLVMTypeAnalyzer
2525
typeAfterBranchFromEnd(std::variant<Variable *, List *> varOrList, LLVMInstruction *end, Compiler::StaticType previousType, bool &write, InstructionSet &visitedInstructions) const;
2626

2727
LLVMInstruction *branchEnd(LLVMInstruction *start) const;
28-
LLVMInstruction *skipBranch(LLVMInstruction *pos) const;
28+
LLVMInstruction *branchStart(LLVMInstruction *end) const;
2929

3030
bool isLoopStart(LLVMInstruction *ins) const;
3131
bool isLoopEnd(LLVMInstruction *ins) const;

0 commit comments

Comments
 (0)