Move continue-block to after all branches.

This commit is contained in:
Dejan Mircevski 2016-01-19 16:56:45 -05:00
parent e7f6cac1bd
commit f3c63cc359
6 changed files with 54 additions and 40 deletions

View File

@ -67,8 +67,9 @@ class ReadableOrderTraverser {
public: public:
explicit ReadableOrderTraverser(std::function<void(Block*)> callback) : callback_(callback) {} explicit ReadableOrderTraverser(std::function<void(Block*)> callback) : callback_(callback) {}
// Visits the block if it hasn't been visited already and isn't currently // Visits the block if it hasn't been visited already and isn't currently
// being delayed. Invokes callback(block), then descends into its successors. // being delayed. Invokes callback(block), then descends into its
// Delays merge-block processing until all the branches have been completed. // successors. Delays merge-block and continue-block processing until all
// the branches have been completed.
void visit(Block* block) void visit(Block* block)
{ {
assert(block); assert(block);
@ -77,14 +78,25 @@ public:
callback_(block); callback_(block);
visited_[block] = true; visited_[block] = true;
Block* mergeBlock = nullptr; Block* mergeBlock = nullptr;
Block* continueBlock = nullptr;
auto mergeInst = block->getMergeInstruction(); auto mergeInst = block->getMergeInstruction();
if (mergeInst) { if (mergeInst) {
Id mergeId = mergeInst->getIdOperand(0); Id mergeId = mergeInst->getIdOperand(0);
mergeBlock = block->getParent().getParent().getInstruction(mergeId)->getBlock(); mergeBlock = block->getParent().getParent().getInstruction(mergeId)->getBlock();
delayed_[mergeBlock] = true; delayed_[mergeBlock] = true;
if (mergeInst->getOpCode() == spv::OpLoopMerge) {
Id continueId = mergeInst->getIdOperand(1);
continueBlock =
block->getParent().getParent().getInstruction(continueId)->getBlock();
delayed_[continueBlock] = true;
}
} }
for (const auto succ : block->getSuccessors()) for (const auto succ : block->getSuccessors())
visit(succ); visit(succ);
if (continueBlock) {
delayed_[continueBlock] = false;
visit(continueBlock);
}
if (mergeBlock) { if (mergeBlock) {
delayed_[mergeBlock] = false; delayed_[mergeBlock] = false;
visit(mergeBlock); visit(mergeBlock);

View File

@ -66,12 +66,6 @@ Linked vertex stage:
19: Label 19: Label
Store 21(B) 22 Store 21(B) 22
Branch 13 Branch 13
13: Label
37: 6(int) Load 8(i)
38: 6(int) IAdd 37 22
Store 8(i) 38
40: 17(bool) SLessThan 38 39
BranchConditional 40 10 12
20: Label 20: Label
25: 6(int) Load 8(i) 25: 6(int) Load 8(i)
27: 17(bool) IEqual 25 26 27: 17(bool) IEqual 25 26
@ -83,6 +77,12 @@ Linked vertex stage:
29: Label 29: Label
Store 35(F) 36 Store 35(F) 36
Branch 13 Branch 13
13: Label
37: 6(int) Load 8(i)
38: 6(int) IAdd 37 22
Store 8(i) 38
40: 17(bool) SLessThan 38 39
BranchConditional 40 10 12
12: Label 12: Label
Store 41(G) 42 Store 41(G) 42
Return Return

View File

@ -67,11 +67,6 @@ Linked vertex stage:
24: Label 24: Label
Store 26(B) 19 Store 26(B) 19
Branch 13 Branch 13
13: Label
40: 6(int) Load 8(i)
41: 6(int) IAdd 40 19
Store 8(i) 41
Branch 10
25: Label 25: Label
29: 6(int) Load 8(i) 29: 6(int) Load 8(i)
31: 6(int) SMod 29 30 31: 6(int) SMod 29 30
@ -84,6 +79,11 @@ Linked vertex stage:
34: Label 34: Label
Store 38(F) 39 Store 38(F) 39
Branch 13 Branch 13
13: Label
40: 6(int) Load 8(i)
41: 6(int) IAdd 40 19
Store 8(i) 41
Branch 10
12: Label 12: Label
Store 42(G) 43 Store 42(G) 43
Return Return

View File

@ -197,6 +197,8 @@ Linked fragment stage:
43: 7(fvec4) FAdd 42 28 43: 7(fvec4) FAdd 42 28
Store 9(color) 43 Store 9(color) 43
Branch 15 Branch 15
16: Label
Branch 13
15: Label 15: Label
Branch 45 Branch 45
45: Label 45: Label
@ -236,14 +238,14 @@ Linked fragment stage:
BranchConditional 77 78 79 BranchConditional 77 78 79
78: Label 78: Label
Branch 63 Branch 63
63: Label
Branch 60
79: Label 79: Label
81: 7(fvec4) Load 69(bigColor1_1) 81: 7(fvec4) Load 69(bigColor1_1)
82: 7(fvec4) Load 9(color) 82: 7(fvec4) Load 9(color)
83: 7(fvec4) FAdd 82 81 83: 7(fvec4) FAdd 82 81
Store 9(color) 83 Store 9(color) 83
Branch 63 Branch 63
63: Label
Branch 60
62: Label 62: Label
Branch 84 Branch 84
84: Label 84: Label
@ -482,17 +484,17 @@ Linked fragment stage:
BranchConditional 260 261 262 BranchConditional 260 261 262
261: Label 261: Label
Branch 249 Branch 249
249: Label
267: 141(int) Load 245(i)
268: 141(int) IAdd 267 159
Store 245(i) 268
Branch 246
262: Label 262: Label
264: 21(ptr) AccessChain 9(color) 73 264: 21(ptr) AccessChain 9(color) 73
265: 6(float) Load 264 265: 6(float) Load 264
266: 6(float) FAdd 265 93 266: 6(float) FAdd 265 93
Store 264 266 Store 264 266
Branch 249 Branch 249
249: Label
267: 141(int) Load 245(i)
268: 141(int) IAdd 267 159
Store 245(i) 268
Branch 246
248: Label 248: Label
Store 269(i) 144 Store 269(i) 144
Branch 270 Branch 270
@ -545,12 +547,6 @@ Linked fragment stage:
BranchConditional 304 305 306 BranchConditional 304 305 306
305: Label 305: Label
Branch 296 Branch 296
296: Label
325: 21(ptr) AccessChain 9(color) 64
326: 6(float) Load 325
327: 6(float) Load 132(d4)
328: 17(bool) FOrdLessThan 326 327
BranchConditional 328 293 295
306: Label 306: Label
308: 21(ptr) AccessChain 9(color) 107 308: 21(ptr) AccessChain 9(color) 107
309: 6(float) Load 308 309: 6(float) Load 308
@ -576,6 +572,12 @@ Linked fragment stage:
Branch 313 Branch 313
313: Label 313: Label
Branch 296 Branch 296
296: Label
325: 21(ptr) AccessChain 9(color) 64
326: 6(float) Load 325
327: 6(float) Load 132(d4)
328: 17(bool) FOrdLessThan 326 327
BranchConditional 328 293 295
295: Label 295: Label
Branch 329 Branch 329
329: Label 329: Label
@ -891,14 +893,14 @@ Linked fragment stage:
Branch 549 Branch 549
549: Label 549: Label
Branch 524 Branch 524
524: Label
Branch 521
539: Label 539: Label
558: 7(fvec4) Load 9(color) 558: 7(fvec4) Load 9(color)
559: 7(fvec4) CompositeConstruct 93 93 93 93 559: 7(fvec4) CompositeConstruct 93 93 93 93
560: 7(fvec4) FAdd 558 559 560: 7(fvec4) FAdd 558 559
Store 9(color) 560 Store 9(color) 560
Branch 523 Branch 523
524: Label
Branch 521
523: Label 523: Label
Branch 562 Branch 562
562: Label 562: Label
@ -927,8 +929,6 @@ Linked fragment stage:
BranchConditional 583 584 585 BranchConditional 583 584 585
584: Label 584: Label
Branch 565 Branch 565
565: Label
Branch 562
585: Label 585: Label
Branch 579 Branch 579
579: Label 579: Label
@ -940,6 +940,8 @@ Linked fragment stage:
592: 21(ptr) AccessChain 9(color) 107 592: 21(ptr) AccessChain 9(color) 107
Store 592 591 Store 592 591
Branch 565 Branch 565
565: Label
Branch 562
564: Label 564: Label
593: 7(fvec4) Load 9(color) 593: 7(fvec4) Load 9(color)
594: 7(fvec4) CompositeConstruct 93 93 93 93 594: 7(fvec4) CompositeConstruct 93 93 93 93

View File

@ -171,12 +171,6 @@ Linked fragment stage:
49: 6(float) FAdd 47 48 49: 6(float) FAdd 47 48
Store 46 49 Store 46 49
Branch 16 Branch 16
16: Label
69: 24(ptr) AccessChain 9(color) 35
70: 6(float) Load 69
71: 6(float) Load 28(d4)
72: 30(bool) FOrdLessThan 70 71
BranchConditional 72 13 15
45: Label 45: Label
Branch 33 Branch 33
33: Label 33: Label
@ -204,6 +198,12 @@ Linked fragment stage:
Branch 57 Branch 57
57: Label 57: Label
Branch 16 Branch 16
16: Label
69: 24(ptr) AccessChain 9(color) 35
70: 6(float) Load 69
71: 6(float) Load 28(d4)
72: 30(bool) FOrdLessThan 70 71
BranchConditional 72 13 15
15: Label 15: Label
Branch 73 Branch 73
73: Label 73: Label
@ -261,8 +261,6 @@ Linked fragment stage:
117: 6(float) FAdd 116 48 117: 6(float) FAdd 116 48
Store 115 117 Store 115 117
Branch 76 Branch 76
76: Label
Branch 73
114: Label 114: Label
Branch 104 Branch 104
104: Label 104: Label
@ -290,6 +288,8 @@ Linked fragment stage:
Branch 124 Branch 124
124: Label 124: Label
Branch 76 Branch 76
76: Label
Branch 73
75: Label 75: Label
136: 7(fvec4) Load 9(color) 136: 7(fvec4) Load 9(color)
137: 7(fvec4) CompositeConstruct 48 48 48 48 137: 7(fvec4) CompositeConstruct 48 48 48 48

View File

@ -60,8 +60,6 @@ Linked vertex stage:
24: Label 24: Label
Store 26(B) 21 Store 26(B) 21
Branch 13 Branch 13
13: Label
Branch 10
25: Label 25: Label
29: 6(int) Load 8(i) 29: 6(int) Load 8(i)
31: 6(int) SMod 29 30 31: 6(int) SMod 29 30
@ -76,6 +74,8 @@ Linked vertex stage:
37: 6(int) IAdd 36 19 37: 6(int) IAdd 36 19
Store 8(i) 37 Store 8(i) 37
Branch 13 Branch 13
13: Label
Branch 10
12: Label 12: Label
Store 38(D) 39 Store 38(D) 39
Return Return