public abstract class IRScope
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
protected static class |
IRScope.LocalVariableAllocator |
| Modifier and Type | Field and Description |
|---|---|
private boolean |
bindingHasEscaped |
private boolean |
canCaptureCallersBinding |
private boolean |
canModifyCode |
protected boolean |
canReceiveBreaks
Can this scope receive breaks
|
boolean |
canReceiveNonlocalReturns
Can this scope receive a non-local return?
|
private CFG |
cfg
Control flow graph representation of this method's instructions
|
private RubyModule |
containerModule
Live version of module within whose context this method executes
|
private TemporaryVariable |
currentModuleVar
%current_module and %current_scope variables
|
private TemporaryVariable |
currentScopeVar |
private java.util.Set<Variable> |
definedLocalVars
Local variables defined in this scope
|
private java.util.Map<java.lang.String,DataFlowProblem> |
dfProbs
Map of name -> dataflow problem
|
(package private) IRScope.LocalVariableAllocator |
evalScopeVars |
private java.lang.String |
fileName
File within which this scope has been defined
|
private boolean |
flagsComputed
Have scope flags been computed?
|
private static java.lang.Integer |
globalScopeCount |
protected boolean |
hasBreakInstrs
Does this scope have a break instr?
|
private boolean |
hasExplicitCallProtocol
Does this scope have explicit call protocol instructions?
If yes, there are IR instructions for managing bindings/frames, etc.
|
private boolean |
hasLoops
Does this scope have loops?
|
protected boolean |
hasNonlocalReturns
Does this scope have a non-local return instr?
|
private boolean |
hasUnusedImplicitBlockArg
Is %block implicit block arg unused?
|
private java.util.List<Instr> |
instrList
List of IR instructions for this method
|
(package private) java.util.List<IRScope> |
lexicalChildren |
private IRScope |
lexicalParent
Lexical parent scope
|
private java.util.List<BasicBlock> |
linearizedBBList |
private Instr[] |
linearizedInstrArray |
private int |
lineNumber
Starting line for this scope's definition
|
(package private) IRScope.LocalVariableAllocator |
localVars |
private static Logger |
LOG |
private IRManager |
manager |
private java.lang.String |
name
Name
|
private java.util.List<IRClosure> |
nestedClosures
List of (nested) closures in this scope
|
private int |
nextClosureIndex |
private java.util.Map<java.lang.String,java.lang.Integer> |
nextVarIndex
Keeps track of types of prefix indexes for variables and labels
|
private boolean |
receivesKeywordArgs
Does this scope receive keyword args?
|
private boolean |
relinearizeCFG
Should we re-run compiler passes -- yes after we've inlined, for example
|
private int |
scopeId
Unique global scope id
|
private StaticScope |
staticScope
Parser static-scope that this IR scope corresponds to
|
protected int |
temporaryVariableIndex |
private int |
threadPollInstrsCount
# of thread poll instrs added to this scope
|
private java.util.Set<Variable> |
usedLocalVars
Local variables used in this scope
|
private boolean |
usesBackrefOrLastline
Since backref ($~) and lastline ($_) vars are allocated space on the dynamic scope,
this is an useful flag to compute.
|
private boolean |
usesEval
Does this scope call any eval
|
private boolean |
usesZSuper
Does this scope call any zsuper
|
| Modifier | Constructor and Description |
|---|---|
|
IRScope(IRManager manager,
IRScope lexicalParent,
java.lang.String name,
java.lang.String fileName,
int lineNumber,
StaticScope staticScope) |
protected |
IRScope(IRScope s,
IRScope lexicalParent) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addChildScope(IRScope scope) |
void |
addClosure(IRClosure c) |
void |
addInstr(Instr i) |
void |
addInstrAtBeginning(Instr i) |
protected int |
allocateNextPrefixedName(java.lang.String prefix) |
boolean |
bindingHasEscaped() |
CFG |
buildCFG() |
void |
buildCFG(java.util.List<Instr> instrList) |
private java.util.List<java.lang.Object[]> |
buildJVMExceptionTable() |
java.util.List<BasicBlock> |
buildLinearization() |
boolean |
canCaptureCallersBinding() |
boolean |
canReceiveNonlocalReturns() |
private static Label[] |
catLabels(Label[] labels,
Label cat) |
CFG |
cfg() |
void |
checkRelinearization() |
void |
computeScopeFlags() |
private boolean |
computeScopeFlags(boolean receivesClosureArg,
java.util.List<Instr> instrs) |
boolean |
definesLocalVariable(Variable v) |
protected void |
depends(java.lang.Object obj) |
boolean |
equals(java.lang.Object other) |
LocalVariable |
findExistingLocalVariable(java.lang.String name,
int depth) |
CFG |
getCFG() |
java.util.List<IRClosure> |
getClosures() |
RubyModule |
getContainerModule() |
Variable |
getCurrentModuleVariable() |
Variable |
getCurrentScopeVariable() |
DataFlowProblem |
getDataFlowSolution(java.lang.String name) |
int |
getEnsurerPC(Instr excInstr) |
java.lang.String |
getFileName() |
abstract LocalVariable |
getImplicitBlockArg() |
java.util.List<Instr> |
getInstrs() |
Instr[] |
getInstrsForInterpretation() |
Instr |
getLastInstr() |
IRScope |
getLexicalParent()
Returns the lexical scope that contains this scope definition
|
java.util.List<IRScope> |
getLexicalScopes() |
int |
getLineNumber() |
LocalVariable |
getLocalVariable(java.lang.String name,
int scopeDepth)
Find or create a local variable.
|
int |
getLocalVariablesCount() |
IRManager |
getManager() |
java.lang.String |
getName() |
IRScope |
getNearestFlipVariableScope() |
IRMethod |
getNearestMethod() |
IRScope |
getNearestModuleReferencingScope()
Returns the nearest scope which we can extract a live module from.
|
IRScope |
getNearestTopLocalVariableScope() |
LocalVariable |
getNewFlipStateVariable() |
Variable |
getNewInlineVariable(java.lang.String inlinePrefix,
Variable v) |
Label |
getNewLabel() |
Label |
getNewLabel(java.lang.String prefix) |
LocalVariable |
getNewLocalVariable(java.lang.String name,
int depth) |
TemporaryVariable |
getNewTemporaryVariable() |
TemporaryVariable |
getNewTemporaryVariable(java.lang.String name) |
int |
getNextClosureId() |
protected int |
getPrefixCountSize(java.lang.String prefix) |
int |
getRescuerPC(Instr excInstr) |
int |
getScopeId() |
abstract java.lang.String |
getScopeName() |
LocalVariable |
getSelf()
---------------------------------------
SSS FIXME: What is this method for?
|
StaticScope |
getStaticScope() |
int |
getTemporaryVariableSize() |
int |
getThreadPollInstrsCount() |
IRScope |
getTopLevelScope()
Returns the top level scope
|
int |
getUsedVariablesCount() |
boolean |
hasExplicitCallProtocol() |
int |
hashCode() |
private boolean |
hasListener() |
boolean |
hasLoops() |
protected void |
initEvalScopeVariableAllocator(boolean reset) |
void |
initFlipStateVariable(Variable v,
Operand initState) |
void |
inlineMethod(IRScope method,
RubyModule implClass,
int classToken,
BasicBlock basicBlock,
CallBase call) |
boolean |
isFlipScope() |
boolean |
isForLoopBody() |
boolean |
isModuleBody()
Does this scope represent a module body? (SSS FIXME: what about script or eval script bodies?)
|
boolean |
isNestedInClosure(IRClosure closure) |
boolean |
isNonSingletonClassBody()
Is this IRClassBody but not IRMetaClassBody?
|
boolean |
isScriptScope()
Is this an eval script or a regular file script?
|
boolean |
isTopLocalVariableScope() |
java.util.List<BasicBlock> |
linearization() |
void |
markUnusedImplicitBlockArg() |
boolean |
modifiesCode() |
Tuple<Instr[],java.util.Map<java.lang.Integer,Label[]>> |
prepareForCompilation()
Run any necessary passes to get the IR ready for compilation
|
Instr[] |
prepareForInterpretation(boolean isLambda)
Run any necessary passes to get the IR ready for interpretation
|
private Instr[] |
prepareInstructionsForInterpretation() |
boolean |
receivesKeywordArgs() |
void |
recordBeginBlock(IRClosure beginBlockClosure) |
void |
recordEndBlock(IRClosure endBlockClosure) |
void |
resetCFG() |
void |
resetDFProblemsState() |
void |
resetLinearizationData() |
void |
resetState() |
void |
resetTemporaryVariables() |
protected void |
resetVariableCounter(java.lang.String prefix) |
private void |
runCompilerPasses() |
protected void |
setCFG(CFG cfg) |
void |
setCodeModificationFlag(boolean f) |
void |
setDataFlowSolution(java.lang.String name,
DataFlowProblem p) |
void |
setExplicitCallProtocolFlag(boolean flag) |
void |
setHasLoopsFlag(boolean f) |
void |
setName(java.lang.String name) |
private void |
setupLabelPCs(java.util.HashMap<Label,java.lang.Integer> labelIPCMap) |
private void |
setupLexicalContainment() |
void |
setUpUseDefLocalVarMaps() |
void |
splitCalls() |
java.lang.String |
toPersistableString() |
java.lang.String |
toString() |
java.lang.String |
toStringInstrs() |
java.lang.String |
toStringVariables() |
boolean |
usesBackrefOrLastline() |
boolean |
usesEval() |
boolean |
usesLocalVariable(Variable v) |
boolean |
usesZSuper() |
private static final Logger LOG
private static java.lang.Integer globalScopeCount
private int scopeId
private java.lang.String name
private final java.lang.String fileName
private final int lineNumber
private IRScope lexicalParent
private StaticScope staticScope
private RubyModule containerModule
private java.util.List<Instr> instrList
private CFG cfg
private java.util.List<IRClosure> nestedClosures
private java.util.Set<Variable> definedLocalVars
private java.util.Set<Variable> usedLocalVars
private boolean hasUnusedImplicitBlockArg
private TemporaryVariable currentModuleVar
private TemporaryVariable currentScopeVar
private java.util.Map<java.lang.String,DataFlowProblem> dfProbs
private Instr[] linearizedInstrArray
private java.util.List<BasicBlock> linearizedBBList
protected int temporaryVariableIndex
private java.util.Map<java.lang.String,java.lang.Integer> nextVarIndex
private int nextClosureIndex
java.util.List<IRScope> lexicalChildren
IRScope.LocalVariableAllocator localVars
IRScope.LocalVariableAllocator evalScopeVars
private boolean flagsComputed
private boolean canCaptureCallersBinding
private boolean canModifyCode
private boolean bindingHasEscaped
private boolean usesEval
private boolean receivesKeywordArgs
protected boolean hasBreakInstrs
protected boolean canReceiveBreaks
protected boolean hasNonlocalReturns
public boolean canReceiveNonlocalReturns
private boolean usesBackrefOrLastline
private boolean usesZSuper
private boolean hasLoops
private int threadPollInstrsCount
private boolean hasExplicitCallProtocol
private boolean relinearizeCFG
private IRManager manager
public IRScope(IRManager manager, IRScope lexicalParent, java.lang.String name, java.lang.String fileName, int lineNumber, StaticScope staticScope)
private final void setupLexicalContainment()
private boolean hasListener()
public int getScopeId()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object other)
equals in class java.lang.Objectprotected void addChildScope(IRScope scope)
public java.util.List<IRScope> getLexicalScopes()
public void addClosure(IRClosure c)
public Instr getLastInstr()
public void addInstrAtBeginning(Instr i)
public void addInstr(Instr i)
public LocalVariable getNewFlipStateVariable()
public boolean isForLoopBody()
public Label getNewLabel(java.lang.String prefix)
public Label getNewLabel()
public java.util.List<IRClosure> getClosures()
public IRManager getManager()
public IRScope getLexicalParent()
public StaticScope getStaticScope()
public IRMethod getNearestMethod()
public IRScope getNearestFlipVariableScope()
public IRScope getNearestTopLocalVariableScope()
public IRScope getNearestModuleReferencingScope()
public java.lang.String getName()
public void setName(java.lang.String name)
public java.lang.String getFileName()
public int getLineNumber()
public IRScope getTopLevelScope()
public boolean isNestedInClosure(IRClosure closure)
public void setHasLoopsFlag(boolean f)
public boolean hasLoops()
public boolean hasExplicitCallProtocol()
public void setExplicitCallProtocolFlag(boolean flag)
public void setCodeModificationFlag(boolean f)
public boolean receivesKeywordArgs()
public boolean modifiesCode()
public boolean bindingHasEscaped()
public boolean usesBackrefOrLastline()
public boolean usesEval()
public boolean usesZSuper()
public boolean canCaptureCallersBinding()
public boolean canReceiveNonlocalReturns()
public CFG buildCFG()
protected void setCFG(CFG cfg)
public CFG getCFG()
private void setupLabelPCs(java.util.HashMap<Label,java.lang.Integer> labelIPCMap)
private Instr[] prepareInstructionsForInterpretation()
private void runCompilerPasses()
public Instr[] prepareForInterpretation(boolean isLambda)
public Tuple<Instr[],java.util.Map<java.lang.Integer,Label[]>> prepareForCompilation()
private java.util.List<java.lang.Object[]> buildJVMExceptionTable()
private boolean computeScopeFlags(boolean receivesClosureArg,
java.util.List<Instr> instrs)
public void computeScopeFlags()
public abstract java.lang.String getScopeName()
public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toStringInstrs()
public java.lang.String toPersistableString()
public java.lang.String toStringVariables()
public LocalVariable getSelf()
public Variable getCurrentModuleVariable()
public Variable getCurrentScopeVariable()
public abstract LocalVariable getImplicitBlockArg()
public void markUnusedImplicitBlockArg()
public LocalVariable findExistingLocalVariable(java.lang.String name, int depth)
public LocalVariable getLocalVariable(java.lang.String name, int scopeDepth)
public LocalVariable getNewLocalVariable(java.lang.String name, int depth)
protected void initEvalScopeVariableAllocator(boolean reset)
public TemporaryVariable getNewTemporaryVariable()
public TemporaryVariable getNewTemporaryVariable(java.lang.String name)
public void resetTemporaryVariables()
public int getTemporaryVariableSize()
public Variable getNewInlineVariable(java.lang.String inlinePrefix, Variable v)
public int getThreadPollInstrsCount()
public int getLocalVariablesCount()
public int getUsedVariablesCount()
public void setUpUseDefLocalVarMaps()
public boolean usesLocalVariable(Variable v)
public boolean definesLocalVariable(Variable v)
public void setDataFlowSolution(java.lang.String name,
DataFlowProblem p)
public DataFlowProblem getDataFlowSolution(java.lang.String name)
public java.util.List<Instr> getInstrs()
public Instr[] getInstrsForInterpretation()
public void resetLinearizationData()
public void checkRelinearization()
public java.util.List<BasicBlock> buildLinearization()
public int getRescuerPC(Instr excInstr)
public int getEnsurerPC(Instr excInstr)
public java.util.List<BasicBlock> linearization()
protected void depends(java.lang.Object obj)
public CFG cfg()
public void splitCalls()
public void resetDFProblemsState()
public void resetState()
public void inlineMethod(IRScope method, RubyModule implClass, int classToken, BasicBlock basicBlock, CallBase call)
public void buildCFG(java.util.List<Instr> instrList)
public void resetCFG()
public void recordBeginBlock(IRClosure beginBlockClosure)
public void recordEndBlock(IRClosure endBlockClosure)
protected int allocateNextPrefixedName(java.lang.String prefix)
protected void resetVariableCounter(java.lang.String prefix)
protected int getPrefixCountSize(java.lang.String prefix)
public RubyModule getContainerModule()
public int getNextClosureId()
public boolean isModuleBody()
public boolean isNonSingletonClassBody()
public boolean isFlipScope()
public boolean isTopLocalVariableScope()
public boolean isScriptScope()