MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / SplitBasicBlock

Method SplitBasicBlock

source/opt/basic_block.cpp:245–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

243}
244
245BasicBlock* BasicBlock::SplitBasicBlock(IRContext* context, uint32_t label_id,
246 iterator iter) {
247 assert(!insts_.empty());
248
249 std::unique_ptr<BasicBlock> new_block_temp = MakeUnique<BasicBlock>(
250 MakeUnique<Instruction>(context, spv::Op::OpLabel, 0, label_id,
251 std::initializer_list<Operand>{}));
252 BasicBlock* new_block = new_block_temp.get();
253 function_->InsertBasicBlockAfter(std::move(new_block_temp), this);
254
255 new_block->insts_.Splice(new_block->end(), &insts_, iter, end());
256 assert(new_block->GetParent() == GetParent() &&
257 "The parent should already be set appropriately.");
258
259 context->AnalyzeDefUse(new_block->GetLabelInst());
260
261 // Update the phi nodes in the successor blocks to reference the new block id.
262 const_cast<const BasicBlock*>(new_block)->ForEachSuccessorLabel(
263 [new_block, this, context](const uint32_t label) {
264 BasicBlock* target_bb = context->get_instr_block(label);
265 target_bb->ForEachPhiInst(
266 [this, new_block, context](Instruction* phi_inst) {
267 bool changed = false;
268 for (uint32_t i = 1; i < phi_inst->NumInOperands(); i += 2) {
269 if (phi_inst->GetSingleWordInOperand(i) == this->id()) {
270 changed = true;
271 phi_inst->SetInOperand(i, {new_block->id()});
272 }
273 }
274
275 if (changed) {
276 context->UpdateDefUse(phi_inst);
277 }
278 });
279 });
280
281 if (context->AreAnalysesValid(IRContext::kAnalysisInstrToBlockMapping)) {
282 context->set_instr_block(new_block->GetLabelInst(), new_block);
283 new_block->ForEachInst([new_block, context](Instruction* inst) {
284 context->set_instr_block(inst, new_block);
285 });
286 }
287
288 return new_block;
289}
290
291} // namespace opt
292} // namespace spvtools

Callers 6

SplitLoopHeaderMethod · 0.80
BreakFromConstructMethod · 0.80
ApplyMethod · 0.80

Calls 15

idMethod · 0.95
getMethod · 0.80
InsertBasicBlockAfterMethod · 0.80
SpliceMethod · 0.80
GetLabelInstMethod · 0.80
ForEachSuccessorLabelMethod · 0.80
get_instr_blockMethod · 0.80
ForEachPhiInstMethod · 0.80
NumInOperandsMethod · 0.80
SetInOperandMethod · 0.80
AreAnalysesValidMethod · 0.80

Tested by

no test coverage detected