Commit d85a7a27 by Nicolas Capens Committed by Nicolas Capens

Simplify If/Else lowering

Previously we would append the 'begin' basic block with the conditional branch only once we know whether or not there's a 'false' block separate from the 'end' block (namely when executing the Else statement). We can instead treat the 'false' block as the 'end' block itself when no Else is encountered and simply continue emitting instructions in this block. Note this removes the need to explicitly materialize all variables, because that's taken care of by createCondBr(). Bug: b/180131694 Change-Id: I5c5c4373d1dc02991feffa69d4089b2c12054dc0 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/52988 Kokoro-Result: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com>
parent 7c296ec5
......@@ -3510,32 +3510,18 @@ class IfElseData
{
public:
IfElseData(RValue<Bool> cmp)
: iteration(0)
{
condition = cmp.value();
beginBB = Nucleus::getInsertBlock();
trueBB = Nucleus::createBasicBlock();
falseBB = nullptr;
endBB = Nucleus::createBasicBlock();
// The conditional branch won't be appended until we've reached the 'end'
// basic block, so we must materialize all variables now (i.e. emit store
// instrutions to write them to memory).
Variable::materializeAll();
falseBB = Nucleus::createBasicBlock();
endBB = falseBB; // Until we encounter an Else statement, these are the same.
Nucleus::createCondBr(cmp.value(), trueBB, falseBB);
Nucleus::setInsertBlock(trueBB);
}
~IfElseData()
{
Nucleus::createBr(endBB);
// Append the conditional branch instruction to the 'begin' basic block.
// Note that it's too late to materialize variables at this point.
Nucleus::setInsertBlock(beginBB);
Nucleus::createCondBr(condition, trueBB, falseBB ? falseBB : endBB);
Nucleus::setInsertBlock(endBB);
}
......@@ -3553,19 +3539,17 @@ public:
void elseClause()
{
endBB = Nucleus::createBasicBlock();
Nucleus::createBr(endBB);
falseBB = Nucleus::createBasicBlock();
Nucleus::setInsertBlock(falseBB);
}
private:
Value *condition;
BasicBlock *beginBB;
BasicBlock *trueBB;
BasicBlock *falseBB;
BasicBlock *endBB;
int iteration;
BasicBlock *trueBB = nullptr;
BasicBlock *falseBB = nullptr;
BasicBlock *endBB = nullptr;
int iteration = 0;
};
#define For(init, cond, inc) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment