MCPcopy Create free account
hub / github.com/KhronosGroup/glslang / makeSwitch

Method makeSwitch

SPIRV/SpvBuilder.cpp:4494–4525  ·  view source on GitHub ↗

Comments in header

Source from the content-addressed store, hash-verified

4492
4493// Comments in header
4494void Builder::makeSwitch(Id selector, SelectionControlMask control, int numSegments, const std::vector<int>& caseValues,
4495 const std::vector<int>& valueIndexToSegment, int defaultSegment,
4496 std::vector<Block*>& segmentBlocks)
4497{
4498 Function& function = buildPoint->getParent();
4499
4500 // make all the blocks
4501 for (int s = 0; s < numSegments; ++s)
4502 segmentBlocks.push_back(new Block(getUniqueId(), function));
4503
4504 Block* mergeBlock = new Block(getUniqueId(), function);
4505
4506 // make and insert the switch's selection-merge instruction
4507 createSelectionMerge(mergeBlock, control);
4508
4509 // make the switch instruction
4510 Instruction* switchInst = new Instruction(NoResult, NoType, Op::OpSwitch);
4511 switchInst->reserveOperands((caseValues.size() * 2) + 2);
4512 switchInst->addIdOperand(selector);
4513 auto defaultOrMerge = (defaultSegment >= 0) ? segmentBlocks[defaultSegment] : mergeBlock;
4514 switchInst->addIdOperand(defaultOrMerge->getId());
4515 defaultOrMerge->addPredecessor(buildPoint);
4516 for (int i = 0; i < (int)caseValues.size(); ++i) {
4517 switchInst->addImmediateOperand(caseValues[i]);
4518 switchInst->addIdOperand(segmentBlocks[valueIndexToSegment[i]]->getId());
4519 segmentBlocks[valueIndexToSegment[i]]->addPredecessor(buildPoint);
4520 }
4521 addInstruction(std::unique_ptr<Instruction>(switchInst));
4522
4523 // push the merge block
4524 switchMerges.push(mergeBlock);
4525}
4526
4527// Comments in header
4528void Builder::addSwitchBreak(bool implicit)

Callers 1

visitSwitchMethod · 0.80

Calls 8

reserveOperandsMethod · 0.80
addIdOperandMethod · 0.80
addPredecessorMethod · 0.80
addImmediateOperandMethod · 0.80
push_backMethod · 0.45
sizeMethod · 0.45
getIdMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected