public IRClosure cloneForInlining(CloneInfo ii) { IRClosure clonedClosure; IRScope lexicalParent = ii.getScope(); if (ii instanceof SimpleCloneInfo && !((SimpleCloneInfo)ii).isEnsureBlockCloneMode()) { clonedClosure = new IRClosure(this, lexicalParent, closureId, getName()); } else { int id = lexicalParent.getNextClosureId(); ByteList fullName = lexicalParent.getName().getBytes().dup(); fullName.append(CLOSURE_CLONE); fullName.append(new Integer(id).toString().getBytes()); clonedClosure = new IRClosure(this, lexicalParent, id, getManager().runtime.newSymbol(fullName)); } // WrappedIRClosure should always have a single unique IRClosure in them so we should // not end up adding n copies of the same closure as distinct clones... lexicalParent.addClosure(clonedClosure); return cloneForInlining(ii, clonedClosure); }
public IRClosure cloneForInlining(CloneInfo ii) { IRClosure clonedClosure; IRScope lexicalParent = ii.getScope(); if (ii instanceof SimpleCloneInfo && !((SimpleCloneInfo)ii).isEnsureBlockCloneMode()) { clonedClosure = new IRClosure(this, lexicalParent, closureId, getName()); } else { int id = lexicalParent.getNextClosureId(); ByteList fullName = lexicalParent.getName().getBytes().dup(); fullName.append(CLOSURE_CLONE); fullName.append(new Integer(id).toString().getBytes()); clonedClosure = new IRClosure(this, lexicalParent, id, getManager().runtime.newSymbol(fullName)); } // WrappedIRClosure should always have a single unique IRClosure in them so we should // not end up adding n copies of the same closure as distinct clones... lexicalParent.addClosure(clonedClosure); return cloneForInlining(ii, clonedClosure); }
public BasicBlock cloneForInlinedClosure(InlinerInfo ii) { // Update cfg for this bb IRScope hostScope = ii.getInlineHostScope(); BasicBlock clonedBB = ii.getOrCreateRenamedBB(this); // Process instructions for (Instr i: getInstrs()) { Instr clonedInstr = i.cloneForInlinedClosure(ii); if (clonedInstr != null) { clonedBB.addInstr(clonedInstr); if (clonedInstr instanceof CallBase) { CallBase call = (CallBase)clonedInstr; Operand block = call.getClosureArg(null); if (block instanceof WrappedIRClosure) hostScope.addClosure(((WrappedIRClosure)block).getClosure()); } } } return clonedBB; }
public BasicBlock cloneForInlinedClosure(InlinerInfo ii) { // Update cfg for this bb IRScope hostScope = ii.getInlineHostScope(); BasicBlock clonedBB = ii.getOrCreateRenamedBB(this); // Process instructions for (Instr i: getInstrs()) { Instr clonedInstr = i.cloneForInlinedClosure(ii); if (clonedInstr != null) { clonedBB.addInstr(clonedInstr); if (clonedInstr instanceof CallBase) { CallBase call = (CallBase)clonedInstr; Operand block = call.getClosureArg(null); if (block instanceof WrappedIRClosure) hostScope.addClosure(((WrappedIRClosure)block).getClosure()); } } } return clonedBB; }
public IRClosure(IRManager manager, IRScope lexicalParent, int lineNumber, StaticScope staticScope, Signature signature, ByteList prefix, boolean isBeginEndBlock, boolean needsCoverage) { this(manager, lexicalParent, lineNumber, staticScope, prefix); this.signature = signature; lexicalParent.addClosure(this); if (getManager().isDryRun()) { this.body = null; } else { boolean shouldJit = manager.getInstanceConfig().getCompileMode().shouldJIT(); this.body = shouldJit ? new MixedModeIRBlockBody(this, signature) : new InterpretedIRBlockBody(this, signature); if (staticScope != null && !isBeginEndBlock) { staticScope.setIRScope(this); staticScope.setScopeType(this.getScopeType()); } } if (needsCoverage) getFlags().add(IRFlags.CODE_COVERAGE); }
public IRClosure(IRManager manager, IRScope lexicalParent, int lineNumber, StaticScope staticScope, Signature signature, ByteList prefix, boolean isBeginEndBlock, boolean needsCoverage) { this(manager, lexicalParent, lineNumber, staticScope, prefix); this.signature = signature; lexicalParent.addClosure(this); if (getManager().isDryRun()) { this.body = null; } else { boolean shouldJit = manager.getInstanceConfig().getCompileMode().shouldJIT(); this.body = shouldJit ? new MixedModeIRBlockBody(this, signature) : new InterpretedIRBlockBody(this, signature); if (staticScope != null && !isBeginEndBlock) { staticScope.setIRScope(this); staticScope.setScopeType(this.getScopeType()); } } if (needsCoverage) getFlags().add(IRFlags.CODE_COVERAGE); }
public BasicBlock cloneForInlinedMethod(InlinerInfo ii) { IRScope hostScope = ii.getInlineHostScope(); BasicBlock clonedBB = ii.getOrCreateRenamedBB(this); for (Instr i: getInstrs()) { Instr clonedInstr = i.cloneForInlinedScope(ii); if (clonedInstr != null) { clonedBB.addInstr(clonedInstr); if (clonedInstr instanceof YieldInstr) ii.recordYieldSite(clonedBB, (YieldInstr)clonedInstr); if (clonedInstr instanceof CallBase) { CallBase call = (CallBase)clonedInstr; Operand block = call.getClosureArg(null); if (block instanceof WrappedIRClosure) hostScope.addClosure(((WrappedIRClosure)block).getClosure()); } } } return clonedBB; }
public BasicBlock cloneForInlinedMethod(InlinerInfo ii) { IRScope hostScope = ii.getInlineHostScope(); BasicBlock clonedBB = ii.getOrCreateRenamedBB(this); for (Instr i: getInstrs()) { Instr clonedInstr = i.cloneForInlinedScope(ii); if (clonedInstr != null) { clonedBB.addInstr(clonedInstr); if (clonedInstr instanceof YieldInstr) ii.recordYieldSite(clonedBB, (YieldInstr)clonedInstr); if (clonedInstr instanceof CallBase) { CallBase call = (CallBase)clonedInstr; Operand block = call.getClosureArg(null); if (block instanceof WrappedIRClosure) hostScope.addClosure(((WrappedIRClosure)block).getClosure()); } } } return clonedBB; }
CallBase call = (CallBase)clonedInstr; Operand block = call.getClosureArg(null); if (block instanceof WrappedIRClosure) builder.scope.addClosure(((WrappedIRClosure)block).getClosure());
CallBase call = (CallBase)clonedInstr; Operand block = call.getClosureArg(null); if (block instanceof WrappedIRClosure) builder.scope.addClosure(((WrappedIRClosure)block).getClosure());
public Operand buildLambda(LambdaNode node, IRScope s) { IRClosure closure = new IRClosure(manager, s, false, node.getPosition().getStartLine(), node.getScope(), Arity.procArityOf(node.getArgs()), node.getArgumentType(), true); s.addClosure(closure); // Create a new nested builder to ensure this gets its own IR builder state // like the ensure block stack IRBuilder closureBuilder = newIRBuilder(manager); // Receive self closure.addInstr(new ReceiveSelfInstr(getSelf(closure))); // args closureBuilder.receiveBlockArgs(node, closure); closureBuilder.receiveBlockClosureArg(node.getBlockVarNode(), closure); Operand closureRetVal = node.getBody() == null ? manager.getNil() : closureBuilder.build(node.getBody(), closure); // can be U_NIL if the node is an if node with returns in both branches. if (closureRetVal != U_NIL) closure.addInstr(new ReturnInstr(closureRetVal)); // Added as part of 'prepareForInterpretation' code. // catchUncaughtBreakInLambdas(closure); Variable lambda = s.getNewTemporaryVariable(); s.addInstr(new BuildLambdaInstr(lambda, closure, node.getPosition())); return lambda; }
public Operand buildLambda(LambdaNode node, IRScope s) { IRClosure closure = new IRClosure(manager, s, false, node.getPosition().getStartLine(), node.getScope(), Arity.procArityOf(node.getArgs()), node.getArgumentType(), true); s.addClosure(closure); // Create a new nested builder to ensure this gets its own IR builder state // like the ensure block stack IRBuilder closureBuilder = newIRBuilder(manager); // Receive self closure.addInstr(new ReceiveSelfInstr(getSelf(closure))); // args closureBuilder.receiveBlockArgs(node, closure); closureBuilder.receiveBlockClosureArg(node.getBlockVarNode(), closure); Operand closureRetVal = node.getBody() == null ? manager.getNil() : closureBuilder.build(node.getBody(), closure); // can be U_NIL if the node is an if node with returns in both branches. if (closureRetVal != U_NIL) closure.addInstr(new ReturnInstr(closureRetVal)); // Added as part of 'prepareForInterpretation' code. // catchUncaughtBreakInLambdas(closure); Variable lambda = s.getNewTemporaryVariable(); s.addInstr(new BuildLambdaInstr(lambda, closure, node.getPosition())); return lambda; }
public Operand buildForIter(final ForNode forNode, IRScope s) { // Create a new closure context IRClosure closure = new IRClosure(manager, s, true, forNode.getPosition().getStartLine(), forNode.getScope(), Arity.procArityOf(forNode.getVarNode()), forNode.getArgumentType(), !is1_9() && !is2_0()); s.addClosure(closure); // Create a new nested builder to ensure this gets its own IR builder state // like the ensure block stack IRBuilder forBuilder = newIRBuilder(manager); // Receive self closure.addInstr(new ReceiveSelfInstr(getSelf(closure))); // Build args Node varNode = forNode.getVarNode(); if (varNode != null && varNode.getNodeType() != null) forBuilder.receiveBlockArgs(forNode, closure); // Set %current_scope = <current-scope> // Set %current_module = <current-module> closure.addInstr(new CopyInstr(closure.getCurrentScopeVariable(), new CurrentScope(closure))); closure.addInstr(new CopyInstr(closure.getCurrentModuleVariable(), new ScopeModule(closure))); // Thread poll on entry of closure closure.addInstr(new ThreadPollInstr()); // Start label -- used by redo! closure.addInstr(new LabelInstr(closure.startLabel)); // Build closure body and return the result of the closure Operand closureRetVal = forNode.getBodyNode() == null ? manager.getNil() : forBuilder.build(forNode.getBodyNode(), closure); if (closureRetVal != U_NIL) { // can be null if the node is an if node with returns in both branches. closure.addInstr(new ReturnInstr(closureRetVal)); } return new WrappedIRClosure(closure); }
public Operand buildForIter(final ForNode forNode, IRScope s) { // Create a new closure context IRClosure closure = new IRClosure(manager, s, true, forNode.getPosition().getStartLine(), forNode.getScope(), Arity.procArityOf(forNode.getVarNode()), forNode.getArgumentType(), !is1_9() && !is2_0()); s.addClosure(closure); // Create a new nested builder to ensure this gets its own IR builder state // like the ensure block stack IRBuilder forBuilder = newIRBuilder(manager); // Receive self closure.addInstr(new ReceiveSelfInstr(getSelf(closure))); // Build args Node varNode = forNode.getVarNode(); if (varNode != null && varNode.getNodeType() != null) forBuilder.receiveBlockArgs(forNode, closure); // Set %current_scope = <current-scope> // Set %current_module = <current-module> closure.addInstr(new CopyInstr(closure.getCurrentScopeVariable(), new CurrentScope(closure))); closure.addInstr(new CopyInstr(closure.getCurrentModuleVariable(), new ScopeModule(closure))); // Thread poll on entry of closure closure.addInstr(new ThreadPollInstr()); // Start label -- used by redo! closure.addInstr(new LabelInstr(closure.startLabel)); // Build closure body and return the result of the closure Operand closureRetVal = forNode.getBodyNode() == null ? manager.getNil() : forBuilder.build(forNode.getBodyNode(), closure); if (closureRetVal != U_NIL) { // can be null if the node is an if node with returns in both branches. closure.addInstr(new ReturnInstr(closureRetVal)); } return new WrappedIRClosure(closure); }
public Operand buildIter(final IterNode iterNode, IRScope s) { IRClosure closure = new IRClosure(manager, s, false, iterNode.getPosition().getStartLine(), iterNode.getScope(), Arity.procArityOf(iterNode.getVarNode()), iterNode.getArgumentType(), !is1_9() && !is2_0()); s.addClosure(closure); // Create a new nested builder to ensure this gets its own IR builder state // like the ensure block stack IRBuilder closureBuilder = newIRBuilder(manager); // Receive self closure.addInstr(new ReceiveSelfInstr(getSelf(closure))); // Build args NodeType argsNodeId = BlockBody.getArgumentTypeWackyHack(iterNode); if ((iterNode.getVarNode() != null) && (argsNodeId != null)) closureBuilder.receiveBlockArgs(iterNode, closure); closureBuilder.receiveBlockClosureArg(iterNode.getBlockVarNode(), closure); // Set %current_scope = <current-scope> // Set %current_module = <current-module> closure.addInstr(new CopyInstr(closure.getCurrentScopeVariable(), new CurrentScope(closure))); closure.addInstr(new CopyInstr(closure.getCurrentModuleVariable(), new ScopeModule(closure))); // Thread poll on entry of closure closure.addInstr(new ThreadPollInstr()); // start label -- used by redo! closure.addInstr(new LabelInstr(closure.startLabel)); // Build closure body and return the result of the closure Operand closureRetVal = iterNode.getBodyNode() == null ? manager.getNil() : closureBuilder.build(iterNode.getBodyNode(), closure); if (closureRetVal != U_NIL) { // can be U_NIL if the node is an if node with returns in both branches. closure.addInstr(new ReturnInstr(closureRetVal)); } return new WrappedIRClosure(closure); }
public Operand buildIter(final IterNode iterNode, IRScope s) { IRClosure closure = new IRClosure(manager, s, false, iterNode.getPosition().getStartLine(), iterNode.getScope(), Arity.procArityOf(iterNode.getVarNode()), iterNode.getArgumentType(), !is1_9() && !is2_0()); s.addClosure(closure); // Create a new nested builder to ensure this gets its own IR builder state // like the ensure block stack IRBuilder closureBuilder = newIRBuilder(manager); // Receive self closure.addInstr(new ReceiveSelfInstr(getSelf(closure))); // Build args NodeType argsNodeId = BlockBody.getArgumentTypeWackyHack(iterNode); if ((iterNode.getVarNode() != null) && (argsNodeId != null)) closureBuilder.receiveBlockArgs(iterNode, closure); closureBuilder.receiveBlockClosureArg(iterNode.getBlockVarNode(), closure); // Set %current_scope = <current-scope> // Set %current_module = <current-module> closure.addInstr(new CopyInstr(closure.getCurrentScopeVariable(), new CurrentScope(closure))); closure.addInstr(new CopyInstr(closure.getCurrentModuleVariable(), new ScopeModule(closure))); // Thread poll on entry of closure closure.addInstr(new ThreadPollInstr()); // start label -- used by redo! closure.addInstr(new LabelInstr(closure.startLabel)); // Build closure body and return the result of the closure Operand closureRetVal = iterNode.getBodyNode() == null ? manager.getNil() : closureBuilder.build(iterNode.getBodyNode(), closure); if (closureRetVal != U_NIL) { // can be U_NIL if the node is an if node with returns in both branches. closure.addInstr(new ReturnInstr(closureRetVal)); } return new WrappedIRClosure(closure); }