MCPcopy
hub / github.com/lutzroeder/netron / transformExits

Method transformExits

source/python.js:18648–18716  ·  view source on GitHub ↗
(block)

Source from the content-addressed store, hash-verified

18646 return new torch._C.ExitPair(has_exited, exit_vals);
18647 }
18648 transformExits(block) {
18649 const prev_target_block = this._target_block;
18650 this.updateTargetBlock(block);
18651 let exit_pair = this.constructWontExitPair();
18652 for (const node of block.nodes()) {
18653 const it = node.next;
18654 switch (node.kind()) {
18655 case 'prim::RaiseException': {
18656 exit_pair = this.constructThrowsExitPair();
18657 break;
18658 }
18659 case 'prim::ReturnStmt':
18660 case 'prim::LoopContinuation': {
18661 if (node.kind() === this._current_exit_kind) {
18662 exit_pair = this.constructWillExitPair(node.inputs());
18663 node.destroy();
18664 }
18665 break;
18666 }
18667 case 'prim::If': {
18668 exit_pair = this.transformIf(node);
18669 break;
18670 }
18671 case 'prim::With': {
18672 exit_pair = this.transformWith(node);
18673 break;
18674 }
18675 case 'prim::Closure': {
18676 this.transformExits(node.blocks().at(0));
18677 break;
18678 }
18679 case 'prim::Loop': {
18680 exit_pair = this.transformLoop(node);
18681 break;
18682 }
18683 default: {
18684 break;
18685 }
18686 }
18687 const status = this.getExitStatus(exit_pair);
18688 if (status === 'WILL' || status === 'THROWS') {
18689 this.deleteAfterExitNodes(block, it);
18690 break;
18691 }
18692 if (status === 'MIGHT') {
18693 throw new python.Error('Not implemented.');
18694 // const nodes = block.nodes();
18695 // if (node === nodes[nodes.length - 1]) {
18696 // exit_pair = this.guardBlockNodes(block, exit_pair, it);
18697 // }
18698 // break;
18699 }
18700 }
18701 if (this._target_block === block) {
18702 if (this.getExitStatus(exit_pair) === 'MIGHT') {
18703 const new_if = this._graph.create('prim::If', 0).insertBefore(block.return_node());
18704 new_if.addBlock();
18705 new_if.addBlock();

Callers 4

transformReturnStmtsMethod · 0.80
transformLoopMethod · 0.80
transformIfMethod · 0.80

Calls 15

updateTargetBlockMethod · 0.80
constructWontExitPairMethod · 0.80
constructWillExitPairMethod · 0.80
destroyMethod · 0.80
transformIfMethod · 0.80
atMethod · 0.80
blocksMethod · 0.80
transformLoopMethod · 0.80
getExitStatusMethod · 0.80
deleteAfterExitNodesMethod · 0.80
return_nodeMethod · 0.80

Tested by

no test coverage detected