Skip to content

Commit

Permalink
Refactor common code out of prepareForInterpretation/Compilation
Browse files Browse the repository at this point in the history
* Since we can now safely attempt to run passes multiple times
  (and they won't run if they have previously run and haven't been
  invalidated), always attempt to run interp passes before
  JIT passes. For the normal interp+JIT case, this works properly.
  For the threshold=0 case, this will also work properly since the
  scope will be brought to the same state as if the interp had run.
  • Loading branch information
subbuss committed Oct 8, 2014
1 parent 2748c1a commit a87c3a5
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions core/src/main/java/org/jruby/ir/IRScope.java
Expand Up @@ -583,15 +583,18 @@ private void runCompilerPasses(List<CompilerPass> passes) {

private void optimizeSimpleScopes() {
// For safe scopes that don't require a dynamic scope,
// inline-add lvar loads/store to tmp-var loads/stores.
// run DCE since the analysis is less likely to be
// stymied by escaped bindings.
if (!isUnsafeScope() && !flags.contains(REQUIRES_DYNSCOPE)) {
(new DeadCodeElimination()).run(this);
(new OptimizeDynScopesPass()).run(this);
}
}

/** Run any necessary passes to get the IR ready for interpretation */
public synchronized Instr[] prepareForInterpretation(boolean isLambda) {
public void initScope(boolean isLambda) {
// Reset linearization, if any exists
resetLinearizationData();

// Build CFG and run compiler passes, if necessary
if (getCFG() == null) {
buildCFG();
Expand All @@ -614,6 +617,11 @@ public synchronized Instr[] prepareForInterpretation(boolean isLambda) {
// on the commandline, skip this opt.
optimizeSimpleScopes();
}
}

/** Run any necessary passes to get the IR ready for interpretation */
public synchronized Instr[] prepareForInterpretation(boolean isLambda) {
initScope(isLambda);

checkRelinearization();

Expand All @@ -628,27 +636,14 @@ public synchronized Instr[] prepareForInterpretation(boolean isLambda) {
/* SSS FIXME: Do we need to synchronize on this? Cache this info in a scope field? */
/** Run any necessary passes to get the IR ready for compilation */
public synchronized List<BasicBlock> prepareForCompilation() {
// Reset linearization, since we will add JIT-specific flow and instrs
resetLinearizationData();

// Build CFG and run compiler passes, if necessary
if (getCFG() == null) {
buildCFG();
}

// Add this always since we dont re-JIT a previously
// JIT-ted closure. But, check if there are other
// smarts available to us and eliminate adding this
// code to every closure there is.
// For lambdas, we need to add a global ensure block to catch
// uncaught breaks and throw a LocalJumpError.
//
// Add a global ensure block to catch uncaught breaks
// and throw a LocalJumpError.
if (this instanceof IRClosure) {
if (((IRClosure)this).addGEBForUncaughtBreaks()) {
resetState();
computeScopeFlags();
}
}
// Since we dont re-JIT a previously JIT-ted closure,
// mark all closures lambdas always. But, check if there are
// other smarts available to us and eliminate adding
// this code to every closure there is.
initScope(this instanceof IRClosure);

runCompilerPasses(getManager().getJITPasses(this));

Expand Down

0 comments on commit a87c3a5

Please sign in to comment.