[spirv] Fix static function variable initialization (#942)

Static function variable should be initialized once. We were
emitting if checks to make sure that but got the branch wrongly
flipped.
This commit is contained in:
Lei Zhang 2017-12-20 14:03:46 -05:00 коммит произвёл GitHub
Родитель b816c124f1
Коммит c1991aadc8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 27 добавлений и 25 удалений

Просмотреть файл

@ -3816,15 +3816,17 @@ void SPIRVEmitter::initOnce(QualType varType, std::string varName,
const uint32_t condition = theBuilder.createLoad(boolType, initDoneVar); const uint32_t condition = theBuilder.createLoad(boolType, initDoneVar);
const uint32_t thenBB = theBuilder.createBasicBlock("if.true"); const uint32_t todoBB = theBuilder.createBasicBlock("if.init.todo");
const uint32_t mergeBB = theBuilder.createBasicBlock("if.merge"); const uint32_t doneBB = theBuilder.createBasicBlock("if.init.done");
theBuilder.createConditionalBranch(condition, thenBB, mergeBB, mergeBB); // If initDoneVar contains true, we jump to the "done" basic block; otherwise,
theBuilder.addSuccessor(thenBB); // jump to the "todo" basic block.
theBuilder.addSuccessor(mergeBB); theBuilder.createConditionalBranch(condition, doneBB, todoBB, doneBB);
theBuilder.setMergeTarget(mergeBB); theBuilder.addSuccessor(todoBB);
theBuilder.addSuccessor(doneBB);
theBuilder.setMergeTarget(doneBB);
theBuilder.setInsertPoint(thenBB); theBuilder.setInsertPoint(todoBB);
// Do initialization and mark done // Do initialization and mark done
if (varInit) { if (varInit) {
theBuilder.createStore(varPtr, doExpr(varInit)); theBuilder.createStore(varPtr, doExpr(varInit));
@ -3833,10 +3835,10 @@ void SPIRVEmitter::initOnce(QualType varType, std::string varName,
theBuilder.createStore(varPtr, theBuilder.getConstantNull(typeId)); theBuilder.createStore(varPtr, theBuilder.getConstantNull(typeId));
} }
theBuilder.createStore(initDoneVar, theBuilder.getConstantBool(true)); theBuilder.createStore(initDoneVar, theBuilder.getConstantBool(true));
theBuilder.createBranch(mergeBB); theBuilder.createBranch(doneBB);
theBuilder.addSuccessor(mergeBB); theBuilder.addSuccessor(doneBB);
theBuilder.setInsertPoint(mergeBB); theBuilder.setInsertPoint(doneBB);
} }
bool SPIRVEmitter::isVectorShuffle(const Expr *expr) { bool SPIRVEmitter::isVectorShuffle(const Expr *expr) {

Просмотреть файл

@ -37,35 +37,35 @@ int main(int input: A) : B {
// CHECK-LABEL: %bb_entry = OpLabel // CHECK-LABEL: %bb_entry = OpLabel
// CHECK-NEXT: [[initdonea:%\d+]] = OpLoad %bool %init_done_a // CHECK-NEXT: [[initdonea:%\d+]] = OpLoad %bool %init_done_a
// CHECK-NEXT: OpSelectionMerge %if_merge None // CHECK-NEXT: OpSelectionMerge %if_init_done None
// CHECK-NEXT: OpBranchConditional [[initdonea]] %if_true %if_merge // CHECK-NEXT: OpBranchConditional [[initdonea]] %if_init_done %if_init_todo
// CHECK-NEXT: %if_true = OpLabel // CHECK-NEXT: %if_init_todo = OpLabel
// CHECK-NEXT: OpStore %a %uint_5 // CHECK-NEXT: OpStore %a %uint_5
// CHECK-NEXT: OpStore %init_done_a %true // CHECK-NEXT: OpStore %init_done_a %true
// CHECK-NEXT: OpBranch %if_merge // CHECK-NEXT: OpBranch %if_init_done
static uint a = 5; // const init static uint a = 5; // const init
// CHECK-NEXT: %if_merge = OpLabel // CHECK-NEXT: %if_init_done = OpLabel
// CHECK-NEXT: [[initdoneb:%\d+]] = OpLoad %bool %init_done_b // CHECK-NEXT: [[initdoneb:%\d+]] = OpLoad %bool %init_done_b
// CHECK-NEXT: OpSelectionMerge %if_merge_0 None // CHECK-NEXT: OpSelectionMerge %if_init_done_0 None
// CHECK-NEXT: OpBranchConditional [[initdoneb]] %if_true_0 %if_merge_0 // CHECK-NEXT: OpBranchConditional [[initdoneb]] %if_init_done_0 %if_init_todo_0
// CHECK-NEXT: %if_true_0 = OpLabel // CHECK-NEXT: %if_init_todo_0 = OpLabel
// CHECK-NEXT: OpStore %b [[v4f0]] // CHECK-NEXT: OpStore %b [[v4f0]]
// CHECK-NEXT: OpStore %init_done_b %true // CHECK-NEXT: OpStore %init_done_b %true
// CHECK-NEXT: OpBranch %if_merge_0 // CHECK-NEXT: OpBranch %if_init_done_0
static float4 b; // no init static float4 b; // no init
// CHECK-NEXT: %if_merge_0 = OpLabel // CHECK-NEXT: %if_init_done_0 = OpLabel
// CHECK-NEXT: [[initdonec:%\d+]] = OpLoad %bool %init_done_c // CHECK-NEXT: [[initdonec:%\d+]] = OpLoad %bool %init_done_c
// CHECK-NEXT: OpSelectionMerge %if_merge_1 None // CHECK-NEXT: OpSelectionMerge %if_init_done_1 None
// CHECK-NEXT: OpBranchConditional [[initdonec]] %if_true_1 %if_merge_1 // CHECK-NEXT: OpBranchConditional [[initdonec]] %if_init_done_1 %if_init_todo_1
// CHECK-NEXT: %if_true_1 = OpLabel // CHECK-NEXT: %if_init_todo_1 = OpLabel
// CHECK-NEXT: [[initc:%\d+]] = OpLoad %int %input // CHECK-NEXT: [[initc:%\d+]] = OpLoad %int %input
// CHECK-NEXT: OpStore %c [[initc]] // CHECK-NEXT: OpStore %c [[initc]]
// CHECK-NEXT: OpStore %init_done_c %true // CHECK-NEXT: OpStore %init_done_c %true
// CHECK-NEXT: OpBranch %if_merge_1 // CHECK-NEXT: OpBranch %if_init_done_1
static int c = input; // var init static int c = input; // var init
// CHECK-NEXT: %if_merge_1 = OpLabel // CHECK-NEXT: %if_init_done_1 = OpLabel
return input; return input;
} }