changeset 4262:744dade427b8

another batch of work towards GraalCompilation removal: * remove GraalCompilation in various places * add getGlobalStubRegisterConfig() to RiRuntime * remove CallStub xir op * remove template stub code from RiXirGenerator and calleeTemplates from XirTemplate * remove stub management code from GraalCompiler and LIRGenerator * remove Util.archKindsEqual
author Lukas Stadler <lukas.stadler@jku.at>
date Wed, 11 Jan 2012 13:35:49 +0100
parents 57b0da88576a
children f461a4a09e53
files graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiRuntime.java graal/com.oracle.max.cri/src/com/oracle/max/cri/xir/CiXirAssembler.java graal/com.oracle.max.cri/src/com/oracle/max/cri/xir/RiXirGenerator.java graal/com.oracle.max.cri/src/com/oracle/max/cri/xir/XirTemplate.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/simple/SpillAllAllocator.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScanWalker.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/MoveResolver.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/RegisterVerifier.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/asm/TargetMethodAssembler.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/FrameMap.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIR.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/Backend.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64Backend.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64CallOpcode.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64CompilerStubEmitter.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64ConvertFIOpcode.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64ConvertFLOpcode.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64DeoptimizationStub.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64XirAssembler.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64XirOpcode.java graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/Util.java graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/CompilerImpl.java graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotRuntime.java graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotXirGenerator.java
diffstat 29 files changed, 124 insertions(+), 622 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiRuntime.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiRuntime.java	Wed Jan 11 13:35:49 2012 +0100
@@ -130,6 +130,8 @@
      */
     RiRegisterConfig getRegisterConfig(RiMethod method);
 
+    RiRegisterConfig getGlobalStubRegisterConfig();
+
     /**
      * Custom area on the stack of each compiled method that the VM can use for its own purposes.
      * @return the size of the custom area in bytes
--- a/graal/com.oracle.max.cri/src/com/oracle/max/cri/xir/CiXirAssembler.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.cri/src/com/oracle/max/cri/xir/CiXirAssembler.java	Wed Jan 11 13:35:49 2012 +0100
@@ -499,10 +499,6 @@
          */
         PointerCAS,
         /**
-         * Call the {@link XirTemplate.GlobalFlags#GLOBAL_STUB shared stub} defined by {@code extra} with {@code args} and put the result in {@code r}.
-         */
-        CallStub,
-        /**
          * Call the {@link RiMethod} defined by {@code extra}  with {@code args} and put the result in {@code r}.
          */
         CallRuntime,
@@ -821,11 +817,6 @@
         append(new XirInstruction(CiKind.Void, message, ShouldNotReachHere, null));
     }
 
-    public void callStub(XirTemplate stub, XirOperand result, XirOperand... args) {
-        CiKind resultKind = result == null ? CiKind.Void : result.kind;
-        append(new XirInstruction(resultKind, stub, CallStub, result, args));
-    }
-
     public void callRuntime(Object rt, XirOperand result, XirOperand... args) {
         callRuntime(rt, result, false, args);
     }
--- a/graal/com.oracle.max.cri/src/com/oracle/max/cri/xir/RiXirGenerator.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.cri/src/com/oracle/max/cri/xir/RiXirGenerator.java	Wed Jan 11 13:35:49 2012 +0100
@@ -22,11 +22,9 @@
  */
 package com.oracle.max.cri.xir;
 
-import java.util.*;
-
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.cri.ri.*;
-import com.oracle.max.cri.ri.RiType.*;
+import com.oracle.max.cri.ri.RiType.Representation;
 
 /**
  * Represents the interface through which the compiler requests the XIR for a given bytecode from the runtime system.
@@ -112,12 +110,10 @@
     XirSnippet genTypeCheck(XirSite site, XirArgument object, XirArgument hub, RiType type);
 
     /**
-     * Gets the list of XIR templates, using the given XIR assembler to create them if
-     * they haven't yet been created.
+     * Initializes the XIR generator for the given XIR assembler.
      *
      * @param asm the XIR assembler
-     * @return the list of templates
      */
-    List<XirTemplate> makeTemplates(CiXirAssembler asm);
+    void initialize(CiXirAssembler asm);
 
 }
--- a/graal/com.oracle.max.cri/src/com/oracle/max/cri/xir/XirTemplate.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.cri/src/com/oracle/max/cri/xir/XirTemplate.java	Wed Jan 11 13:35:49 2012 +0100
@@ -112,8 +112,6 @@
 
     public final boolean allocateResultOperand;
 
-    public final XirTemplate[] calleeTemplates;
-
     public final XirMark[] marks;
 
     public final int outgoingStackSize;
@@ -139,7 +137,6 @@
                        XirTemp[] temps,
                        XirConstant[] constantValues,
                        int flags,
-                       XirTemplate[] calleeTemplates,
                        XirMark[] marks,
                        int outgoingStackSize) {
         this.name = name;
@@ -153,7 +150,6 @@
         this.temps = temps;
         this.allocateResultOperand = allocateResultOperand;
         this.constants = constantValues;
-        this.calleeTemplates = calleeTemplates;
         this.marks = marks;
         this.outgoingStackSize = outgoingStackSize;
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/simple/SpillAllAllocator.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/alloc/simple/SpillAllAllocator.java	Wed Jan 11 13:35:49 2012 +0100
@@ -47,11 +47,11 @@
 
     private final DataFlowAnalysis dataFlow;
 
-    public SpillAllAllocator(GraalContext context, LIR lir, GraalCompilation compilation, RiRegisterConfig registerConfig) {
+    public SpillAllAllocator(GraalContext context, LIR lir, FrameMap frameMap, RiRegisterConfig registerConfig) {
         this.context = context;
         this.lir = lir;
         this.registerConfig = registerConfig;
-        this.frameMap = compilation.frameMap();
+        this.frameMap = frameMap;
 
         this.dataFlow = new DataFlowAnalysis(context, lir, registerConfig);
         this.blockLocations = new LocationMap[lir.linearScanOrder().size()];
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompilation.java	Wed Jan 11 13:35:49 2012 +0100
@@ -40,6 +40,7 @@
 import com.oracle.max.graal.compiler.phases.*;
 import com.oracle.max.graal.compiler.phases.PhasePlan.PhasePosition;
 import com.oracle.max.graal.compiler.schedule.*;
+import com.oracle.max.graal.debug.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 
@@ -79,7 +80,7 @@
         this.graph = graph;
         this.method = method;
         this.stats = stats == null ? new CiStatistics() : stats;
-        this.registerConfig = method == null ? compiler.compilerStubRegisterConfig : compiler.runtime.getRegisterConfig(method);
+        this.registerConfig = method == null ? compiler.runtime.getGlobalStubRegisterConfig() : compiler.runtime.getRegisterConfig(method);
         this.placeholderState = debugInfoLevel == DebugInfoLevel.REF_MAPS ? new FrameState(method, 0, 0, 0, false) : null;
 
         if (context().isObserved() && method != null) {
@@ -119,7 +120,7 @@
 
     private TargetMethodAssembler createAssembler() {
         AbstractAssembler masm = compiler.backend.newAssembler(registerConfig);
-        TargetMethodAssembler tasm = new TargetMethodAssembler(this, masm);
+        TargetMethodAssembler tasm = new TargetMethodAssembler(context(), compiler, compiler.target, compiler.runtime, frameMap, lir.slowPaths, masm);
         tasm.setFrameSize(frameMap.frameSize());
         tasm.targetMethod.setCustomStackAreaOffset(frameMap.offsetToCustomArea());
         return tasm;
@@ -245,9 +246,7 @@
 
             IdentifyBlocksPhase schedule = new IdentifyBlocksPhase(true, LIRBlock.FACTORY);
             schedule.apply(graph, context());
-            if (stats != null) {
-                stats.loopCount = schedule.loopCount();
-            }
+            stats.loopCount = schedule.loopCount();
 
             if (context().isObserved()) {
                 context().observable.fireCompilationEvent("After IdentifyBlocksPhase", this, graph, schedule);
@@ -275,7 +274,7 @@
                     b.setLinearScanNumber(z++);
                 }
 
-                lir = new LIR(startBlock, linearScanOrder, codeEmittingOrder, valueToBlock);
+                lir = new LIR(startBlock, linearScanOrder, codeEmittingOrder, valueToBlock, schedule.loopCount());
 
                 if (context().isObserved()) {
                     context().observable.fireCompilationEvent("After linear scan order", this, graph, lir);
@@ -295,7 +294,7 @@
     }
 
     public void initFrameMap() {
-        frameMap = this.compiler.backend.newFrameMap(compiler.runtime, compiler.target, registerConfig);
+        frameMap = this.compiler.backend.newFrameMap(registerConfig);
     }
 
     private void emitLIR(RiXirGenerator xir) {
@@ -330,7 +329,7 @@
                 }
 
                 if (GraalOptions.AllocSSA) {
-                    new SpillAllAllocator(context(), lir, this, registerConfig).execute();
+                    new SpillAllAllocator(context(), lir, frameMap, registerConfig).execute();
                 } else {
                     new LinearScan(this, lir, lirGenerator, frameMap()).allocate();
                 }
@@ -357,7 +356,7 @@
                 TargetMethodAssembler tasm = createAssembler();
                 lir.emitCode(tasm);
 
-                CiTargetMethod targetMethod = tasm.finishTargetMethod(method, compiler.runtime, false);
+                CiTargetMethod targetMethod = tasm.finishTargetMethod(method, false);
                 if (assumptions != null && !assumptions.isEmpty()) {
                     targetMethod.setAssumptions(assumptions);
                 }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/GraalCompiler.java	Wed Jan 11 13:35:49 2012 +0100
@@ -59,16 +59,13 @@
      */
     public final Backend backend;
 
-    public final RiRegisterConfig compilerStubRegisterConfig;
-
-    public GraalCompiler(GraalContext context, GraalRuntime runtime, CiTarget target, RiXirGenerator xirGen, RiRegisterConfig compilerStubRegisterConfig) {
+    public GraalCompiler(GraalContext context, GraalRuntime runtime, CiTarget target, RiXirGenerator xirGen) {
         this.context = context;
         this.runtime = runtime;
         this.target = target;
         this.xir = xirGen;
-        this.compilerStubRegisterConfig = compilerStubRegisterConfig;
-        this.backend = Backend.create(target.arch, this);
-        init();
+        this.backend = Backend.create(target.arch, runtime, target);
+        xir.initialize(backend.newXirAssembler());
     }
 
     public CiTargetMethod compileMethod(RiResolvedMethod method, int osrBCI, CiStatistics stats, CiCompiler.DebugInfoLevel debugInfoLevel) {
@@ -116,51 +113,4 @@
             context.timers.endScope();
         }
     }
-
-    private void init() {
-        final List<XirTemplate> xirTemplateStubs = xir.makeTemplates(backend.newXirAssembler());
-
-        if (xirTemplateStubs != null) {
-            for (XirTemplate template : xirTemplateStubs) {
-                TTY.Filter filter = new TTY.Filter(GraalOptions.PrintFilter, template.name);
-                try {
-                    stubs.put(template, backend.emit(context, template));
-                } finally {
-                    filter.remove();
-                }
-            }
-        }
-
-        for (CompilerStub.Id id : CompilerStub.Id.values()) {
-            TTY.Filter suppressor = new TTY.Filter(GraalOptions.PrintFilter, id);
-            try {
-                stubs.put(id, backend.emit(context, id));
-            } finally {
-                suppressor.remove();
-            }
-        }
-    }
-
-    public CompilerStub lookupStub(CompilerStub.Id id) {
-        CompilerStub stub = stubs.get(id);
-        assert stub != null : "no stub for global stub id: " + id;
-        return stub;
-    }
-
-    public CompilerStub lookupStub(XirTemplate template) {
-        CompilerStub stub = stubs.get(template);
-        assert stub != null : "no stub for XirTemplate: " + template;
-        return stub;
-    }
-
-    public CompilerStub lookupStub(CiRuntimeCall runtimeCall) {
-        CompilerStub stub = stubs.get(runtimeCall);
-        if (stub == null) {
-            stub = backend.emit(context, runtimeCall);
-            stubs.put(runtimeCall, stub);
-        }
-
-        assert stub != null : "could not find global stub for runtime call: " + runtimeCall;
-        return stub;
-    }
 }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScan.java	Wed Jan 11 13:35:49 2012 +0100
@@ -49,7 +49,8 @@
 public final class LinearScan {
 
     final GraalContext context;
-    final GraalCompilation compilation;
+    final RiRegisterConfig registerConfig;
+    final CiTarget target;
     final RiMethod method;
     final LIR ir;
     final LIRGenerator gen;
@@ -119,8 +120,9 @@
 
     public LinearScan(GraalCompilation compilation, LIR ir, LIRGenerator gen, FrameMap frameMap) {
         this.context = compilation.compiler.context;
+        this.target = compilation.compiler.target;
+        this.registerConfig = compilation.registerConfig;
         this.method = compilation.method;
-        this.compilation = compilation;
         this.ir = ir;
         this.gen = gen;
         this.frameMap = frameMap;
@@ -282,7 +284,7 @@
     }
 
     int numLoops() {
-        return compilation.stats.loopCount;
+        return ir.loopCount();
     }
 
     boolean isIntervalInLoop(int interval, int loop) {
@@ -1033,15 +1035,15 @@
         }
     }
 
-    void addRegisterHint(final LIRInstruction op, final CiValue target, OperandMode mode, EnumSet<OperandFlag> flags) {
-        if (flags.contains(OperandFlag.RegisterHint) && isVariableOrRegister(target)) {
+    void addRegisterHint(final LIRInstruction op, final CiValue targetValue, OperandMode mode, EnumSet<OperandFlag> flags) {
+        if (flags.contains(OperandFlag.RegisterHint) && isVariableOrRegister(targetValue)) {
 
-            op.forEachRegisterHint(target, mode, new ValueProcedure() {
+            op.forEachRegisterHint(targetValue, mode, new ValueProcedure() {
                 @Override
                 protected CiValue doValue(CiValue registerHint) {
                     if (isVariableOrRegister(registerHint)) {
                         Interval from = intervalFor(registerHint);
-                        Interval to = intervalFor(target);
+                        Interval to = intervalFor(targetValue);
                         if (from != null && to != null) {
                             to.setLocationHint(from);
                             if (GraalOptions.TraceLinearScanLevel >= 4) {
@@ -1061,7 +1063,6 @@
         intervals = new Interval[intervalsSize + INITIAL_SPLIT_INTERVALS_CAPACITY];
 
         // create a list with all caller-save registers (cpu, fpu, xmm)
-        RiRegisterConfig registerConfig = compilation.registerConfig;
         CiRegister[] callerSaveRegs = registerConfig.getCallerSaveRegisters();
 
         // iterate all blocks in reverse order
@@ -1341,7 +1342,7 @@
         notPrecoloredIntervals = result.second;
 
         // allocate cpu registers
-        LinearScanWalker lsw = new LinearScanWalker(this, precoloredIntervals, notPrecoloredIntervals, !compilation.compiler.target.arch.isX86());
+        LinearScanWalker lsw = new LinearScanWalker(this, precoloredIntervals, notPrecoloredIntervals, !target.arch.isX86());
         lsw.walk();
         lsw.finishAllocation();
     }
@@ -1544,12 +1545,12 @@
                 }
 
                 case Float: {
-                    assert !compilation.compiler.target.arch.isX86() || reg.isFpu() : "not xmm register: " + reg;
+                    assert !target.arch.isX86() || reg.isFpu() : "not xmm register: " + reg;
                     break;
                 }
 
                 case Double: {
-                    assert !compilation.compiler.target.arch.isX86() || reg.isFpu() : "not xmm register: " + reg;
+                    assert !target.arch.isX86() || reg.isFpu() : "not xmm register: " + reg;
                     break;
                 }
 
@@ -1871,7 +1872,8 @@
         }
 
         if (context.isObserved()) {
-            context.observable.fireCompilationEvent(label, compilation, this, Arrays.copyOf(intervals, intervalsSize));
+            // FIX(ls)
+//            context.observable.fireCompilationEvent(label, compilation, this, Arrays.copyOf(intervals, intervalsSize));
         }
     }
 
@@ -1884,7 +1886,8 @@
         }
 
         if (context.isObserved()) {
-            context.observable.fireCompilationEvent(label, compilation, hirValid ? compilation.graph : null, compilation.lir());
+            // FIX(ls)
+//            context.observable.fireCompilationEvent(label, compilation, hirValid ? compilation.graph : null, compilation.lir());
         }
     }
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScanWalker.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/LinearScanWalker.java	Wed Jan 11 13:35:49 2012 +0100
@@ -819,7 +819,7 @@
     }
 
     void initVarsForAlloc(Interval interval) {
-        EnumMap<RegisterFlag, CiRegister[]> categorizedRegs = allocator.compilation.registerConfig.getCategorizedAllocatableRegisters();
+        EnumMap<RegisterFlag, CiRegister[]> categorizedRegs = allocator.registerConfig.getCategorizedAllocatableRegisters();
         availableRegs = categorizedRegs.get(asVariable(interval.operand).flag);
     }
 
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/MoveResolver.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/MoveResolver.java	Wed Jan 11 13:35:49 2012 +0100
@@ -30,7 +30,6 @@
 import com.oracle.max.criutils.*;
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.lir.*;
-import com.oracle.max.graal.compiler.util.*;
 
 /**
  */
@@ -193,7 +192,7 @@
 
     private void insertMove(Interval fromInterval, Interval toInterval) {
         assert fromInterval.operand != toInterval.operand : "from and to interval equal: " + fromInterval;
-        assert Util.archKindsEqual(fromInterval.kind(), toInterval.kind()) : "move between different types";
+        assert fromInterval.kind() == toInterval.kind() : "move between different types";
         assert insertIdx != -1 : "must setup insert position first";
 
         CiValue fromOpr = fromInterval.operand;
@@ -207,7 +206,7 @@
     }
 
     private void insertMove(CiValue fromOpr, Interval toInterval) {
-        assert Util.archKindsEqual(fromOpr.kind, toInterval.kind()) : "move between different types";
+        assert fromOpr.kind == toInterval.kind() : "move between different types";
         assert insertIdx != -1 : "must setup insert position first";
 
         CiValue toOpr = toInterval.operand;
@@ -331,7 +330,7 @@
         }
 
         assert fromInterval.operand != toInterval.operand : "from and to interval equal: " + fromInterval;
-        assert Util.archKindsEqual(fromInterval.kind(), toInterval.kind());
+        assert fromInterval.kind() == toInterval.kind();
         mappingFrom.add(fromInterval);
         mappingFromOpr.add(CiValue.IllegalValue);
         mappingTo.add(toInterval);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/RegisterVerifier.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/alloc/RegisterVerifier.java	Wed Jan 11 13:35:49 2012 +0100
@@ -42,10 +42,6 @@
     ArrayMap<Interval[]> savedStates; // saved information of previous check
 
     // simplified access to methods of LinearScan
-    GraalCompilation compilation() {
-        return allocator.compilation;
-    }
-
     Interval intervalAt(CiValue operand) {
         return allocator.intervalFor(operand);
     }
@@ -249,7 +245,7 @@
             op.forEachInput(useProc);
             // invalidate all caller save registers at calls
             if (op.hasCall()) {
-                for (CiRegister r : allocator.compilation.registerConfig.getCallerSaveRegisters()) {
+                for (CiRegister r : allocator.registerConfig.getCallerSaveRegisters()) {
                     statePut(inputState, r.asValue(), null);
                 }
             }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/asm/TargetMethodAssembler.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/asm/TargetMethodAssembler.java	Wed Jan 11 13:35:49 2012 +0100
@@ -32,21 +32,32 @@
 import com.oracle.max.criutils.*;
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.lir.*;
+import com.oracle.max.graal.compiler.lir.LIR.SlowPath;
 import com.oracle.max.graal.compiler.util.*;
 
 public class TargetMethodAssembler {
-    public final GraalCompilation compilation;
+
     public final AbstractAssembler asm;
     public final CiTargetMethod targetMethod;
     public final CiTarget target;
+    public final RiRuntime runtime;
+    public final FrameMap frameMap;
+    public final List<SlowPath> slowPaths;
+    public final GraalCompiler compiler;
+
     private List<ExceptionInfo> exceptionInfoList;
     private int lastSafepointPos;
+    private final GraalContext context;
 
-    public TargetMethodAssembler(GraalCompilation compilation, AbstractAssembler asm) {
-        this.compilation = compilation;
+    public TargetMethodAssembler(GraalContext context, GraalCompiler compiler, CiTarget target, RiRuntime runtime, FrameMap frameMap, List<SlowPath> slowPaths, AbstractAssembler asm) {
+        this.context = context;
+        this.compiler = compiler;
+        this.target = target;
+        this.runtime = runtime;
+        this.frameMap = frameMap;
+        this.slowPaths = slowPaths;
         this.asm = asm;
         this.targetMethod = new CiTargetMethod();
-        this.target = compilation.compiler.target;
         // 0 is a valid pc for safepoints in template methods
         this.lastSafepointPos = -1;
     }
@@ -63,7 +74,7 @@
         targetMethod.addAnnotation(new CiTargetMethod.CodeComment(asm.codeBuffer.position(), s));
     }
 
-    public CiTargetMethod finishTargetMethod(Object name, RiRuntime runtime, boolean isStub) {
+    public CiTargetMethod finishTargetMethod(Object name, boolean isStub) {
         // Install code, data and frame size
         targetMethod.setTargetCode(asm.codeBuffer.close(false), asm.codeBuffer.position());
 
@@ -76,11 +87,11 @@
         }
 
         if (GraalOptions.Meter) {
-            compilation.compiler.context.metrics.TargetMethods++;
-            compilation.compiler.context.metrics.CodeBytesEmitted += targetMethod.targetCodeSize();
-            compilation.compiler.context.metrics.SafepointsEmitted += targetMethod.safepoints.size();
-            compilation.compiler.context.metrics.DataPatches += targetMethod.dataReferences.size();
-            compilation.compiler.context.metrics.ExceptionHandlersEmitted += targetMethod.exceptionHandlers.size();
+            context.metrics.TargetMethods++;
+            context.metrics.CodeBytesEmitted += targetMethod.targetCodeSize();
+            context.metrics.SafepointsEmitted += targetMethod.safepoints.size();
+            context.metrics.DataPatches += targetMethod.dataReferences.size();
+            context.metrics.ExceptionHandlersEmitted += targetMethod.exceptionHandlers.size();
         }
 
         if (GraalOptions.PrintAssembly && !TTY.isSuppressed() && !isStub) {
@@ -226,10 +237,6 @@
     }
 
     public CiAddress asAddress(CiValue value) {
-        if (isStackSlot(value)) {
-            CiStackSlot slot = (CiStackSlot) value;
-            return new CiAddress(slot.kind, compilation.registerConfig.getFrameRegister().asValue(), compilation.frameMap().offsetForStackSlot(slot));
-        }
-        return (CiAddress) value;
+        return frameMap.asAddress(value);
     }
 }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/gen/LIRGenerator.java	Wed Jan 11 13:35:49 2012 +0100
@@ -22,12 +22,12 @@
  */
 package com.oracle.max.graal.compiler.gen;
 
-import static com.oracle.max.graal.compiler.lir.StandardOpcode.*;
 import static com.oracle.max.cri.ci.CiCallingConvention.Type.*;
 import static com.oracle.max.cri.ci.CiValue.*;
 import static com.oracle.max.cri.ci.CiValueUtil.*;
 import static com.oracle.max.cri.util.MemoryBarriers.*;
 import static com.oracle.max.graal.alloc.util.ValueUtil.*;
+import static com.oracle.max.graal.compiler.lir.StandardOpcode.*;
 
 import java.lang.reflect.*;
 import java.util.*;
@@ -48,7 +48,6 @@
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.lir.*;
 import com.oracle.max.graal.compiler.schedule.*;
-import com.oracle.max.graal.compiler.stub.*;
 import com.oracle.max.graal.compiler.util.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
@@ -67,7 +66,6 @@
     public final GraalContext context;
 
     protected final Graph graph;
-    private final GraalCompiler compiler;
     protected final RiRuntime runtime;
     protected final CiTarget target;
     protected final RiResolvedMethod method;
@@ -144,7 +142,6 @@
     public LIRGenerator(GraalCompilation compilation, RiXirGenerator xir) {
         this.context = compilation.compiler.context;
         this.graph = compilation.graph;
-        this.compiler = compilation.compiler;
         this.runtime = compilation.compiler.runtime;
         this.target = compilation.compiler.target;
         this.frameMap = compilation.frameMap();
@@ -1024,18 +1021,6 @@
         }
     }
 
-    protected CompilerStub stubFor(CompilerStub.Id id) {
-        CompilerStub stub = compiler.lookupStub(id);
-        frameMap.usesStub(stub);
-        return stub;
-    }
-
-    protected CompilerStub stubFor(XirTemplate template) {
-        CompilerStub stub = compiler.lookupStub(template);
-        frameMap.usesStub(stub);
-        return stub;
-    }
-
     @Override
     public void emitLookupSwitch(LookupSwitchNode x) {
         Variable tag = load(operand(x.value()));
@@ -1270,11 +1255,6 @@
             }
         }
 
-        for (XirTemplate calleeTemplate : snippet.template.calleeTemplates) {
-            // TODO Save these for use in AMD64LIRAssembler
-            stubFor(calleeTemplate);
-        }
-
         for (XirConstant c : snippet.template.constants) {
             assert operandsArray[c.index] == null;
             operandsArray[c.index] = c.value;
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/FrameMap.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/FrameMap.java	Wed Jan 11 13:35:49 2012 +0100
@@ -22,7 +22,7 @@
  */
 package com.oracle.max.graal.compiler.lir;
 
-import static com.oracle.max.graal.alloc.util.ValueUtil.*;
+import static com.oracle.max.cri.ci.CiValueUtil.*;
 
 import java.util.*;
 
@@ -352,4 +352,12 @@
             }
         }
     }
+
+    public CiAddress asAddress(CiValue value) {
+        if (isStackSlot(value)) {
+            CiStackSlot slot = (CiStackSlot) value;
+            return new CiAddress(slot.kind, registerConfig.getFrameRegister().asValue(), offsetForStackSlot(slot));
+        }
+        return (CiAddress) value;
+    }
 }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIR.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/lir/LIR.java	Wed Jan 11 13:35:49 2012 +0100
@@ -65,6 +65,8 @@
 
     private int numVariables;
 
+    private final int loopCount;
+
 
     public interface SlowPath {
         void emitCode(TargetMethodAssembler tasm);
@@ -72,13 +74,15 @@
 
     /**
      * Creates a new LIR instance for the specified compilation.
+     * @param loopCount number of loops
      * @param compilation the compilation
      */
-    public LIR(LIRBlock startBlock, List<LIRBlock> linearScanOrder, List<LIRBlock> codeEmittingOrder, NodeMap<LIRBlock> valueToBlock) {
+    public LIR(LIRBlock startBlock, List<LIRBlock> linearScanOrder, List<LIRBlock> codeEmittingOrder, NodeMap<LIRBlock> valueToBlock, int loopCount) {
         this.codeEmittingOrder = codeEmittingOrder;
         this.linearScanOrder = linearScanOrder;
         this.startBlock = startBlock;
         this.valueToBlock = valueToBlock;
+        this.loopCount = loopCount;
 
         slowPaths = new ArrayList<>();
         deoptimizationStubs = new ArrayList<>();
@@ -104,6 +108,10 @@
         return valueToBlock;
     }
 
+    public int loopCount() {
+        return loopCount;
+    }
+
     public int numVariables() {
         return numVariables;
     }
@@ -183,7 +191,7 @@
     private void printAssembly(TargetMethodAssembler tasm) {
         byte[] currentBytes = tasm.asm.codeBuffer.copyData(lastDecodeStart, tasm.asm.codeBuffer.position());
         if (currentBytes.length > 0) {
-            String disasm = tasm.compilation.compiler.runtime.disassemble(currentBytes, lastDecodeStart);
+            String disasm = tasm.runtime.disassemble(currentBytes, lastDecodeStart);
             if (disasm.length() != 0) {
                 TTY.println(disasm);
             } else {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/Backend.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/Backend.java	Wed Jan 11 13:35:49 2012 +0100
@@ -31,36 +31,33 @@
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.gen.*;
 import com.oracle.max.graal.compiler.lir.*;
-import com.oracle.max.graal.compiler.stub.*;
 
 /**
  * The {@code Backend} class represents a compiler backend for Graal.
  */
 public abstract class Backend {
-    public final GraalCompiler compiler;
+    public final RiRuntime runtime;
+    public final CiTarget target;
 
-    protected Backend(GraalCompiler compiler) {
-        this.compiler = compiler;
+    protected Backend(RiRuntime runtime, CiTarget target) {
+        this.runtime = runtime;
+        this.target = target;
     }
 
-    public static Backend create(CiArchitecture arch, GraalCompiler compiler) {
+    public static Backend create(CiArchitecture arch, RiRuntime runtime, CiTarget target) {
         String className = arch.getClass().getName().replace("com.oracle.max.asm", "com.oracle.max.graal.compiler") + "Backend";
         try {
             Class<?> c = Class.forName(className);
-            Constructor<?> cons = c.getDeclaredConstructor(GraalCompiler.class);
-            return (Backend) cons.newInstance(compiler);
+            Constructor<?> cons = c.getDeclaredConstructor(RiRuntime.class, CiTarget.class);
+            return (Backend) cons.newInstance(runtime, target);
         } catch (Exception e) {
             throw new Error("Could not instantiate " + className, e);
         }
     }
 
-    public abstract FrameMap newFrameMap(RiRuntime runtime, CiTarget target, RiRegisterConfig registerConfig);
+    public abstract FrameMap newFrameMap(RiRegisterConfig registerConfig);
     public abstract LIRGenerator newLIRGenerator(GraalCompilation compilation, RiXirGenerator xir);
     public abstract AbstractAssembler newAssembler(RiRegisterConfig registerConfig);
     public abstract CiXirAssembler newXirAssembler();
 
-    public abstract CompilerStub emit(GraalContext context, CompilerStub.Id stub);
-    public abstract CompilerStub emit(GraalContext context, CiRuntimeCall runtimeCall);
-    public abstract CompilerStub emit(GraalContext context, XirTemplate t);
-
 }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64Backend.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64Backend.java	Wed Jan 11 13:35:49 2012 +0100
@@ -25,14 +25,11 @@
 import com.oracle.max.asm.*;
 import com.oracle.max.asm.target.amd64.*;
 import com.oracle.max.cri.ci.*;
-import com.oracle.max.cri.ci.CiCompiler.*;
 import com.oracle.max.cri.ri.*;
 import com.oracle.max.cri.xir.*;
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.gen.*;
 import com.oracle.max.graal.compiler.lir.*;
-import com.oracle.max.graal.compiler.stub.*;
-import com.oracle.max.graal.compiler.stub.CompilerStub.Id;
 import com.oracle.max.graal.compiler.target.*;
 
 /**
@@ -40,8 +37,8 @@
  */
 public class AMD64Backend extends Backend {
 
-    public AMD64Backend(GraalCompiler compiler) {
-        super(compiler);
+    public AMD64Backend(RiRuntime runtime, CiTarget target) {
+        super(runtime, target);
     }
     /**
      * Creates a new LIRGenerator for x86.
@@ -54,57 +51,17 @@
     }
 
     @Override
-    public FrameMap newFrameMap(RiRuntime runtime, CiTarget target, RiRegisterConfig registerConfig) {
+    public FrameMap newFrameMap(RiRegisterConfig registerConfig) {
         return new FrameMap(runtime, target, registerConfig);
     }
 
     @Override
     public AbstractAssembler newAssembler(RiRegisterConfig registerConfig) {
-        return new AMD64MacroAssembler(compiler.target, registerConfig);
+        return new AMD64MacroAssembler(target, registerConfig);
     }
 
     @Override
     public CiXirAssembler newXirAssembler() {
-        return new AMD64XirAssembler(compiler.target);
-    }
-
-    @Override
-    public CompilerStub emit(GraalContext context, Id stub) {
-        final GraalCompilation comp = new GraalCompilation(context, compiler, null, -1, null, DebugInfoLevel.FULL);
-        try {
-            return new AMD64CompilerStubEmitter(comp, stub.arguments, stub.resultKind).emit(stub);
-        } finally {
-            comp.close();
-        }
-    }
-
-    @Override
-    public CompilerStub emit(GraalContext context, CiRuntimeCall rtCall) {
-        final GraalCompilation comp = new GraalCompilation(context, compiler, null, -1, null, DebugInfoLevel.FULL);
-        try {
-            return new AMD64CompilerStubEmitter(comp, rtCall.arguments, rtCall.resultKind).emit(rtCall);
-        } finally {
-            comp.close();
-        }
-    }
-
-    private static CiKind[] getArgumentKinds(XirTemplate template) {
-        CiXirAssembler.XirParameter[] params = template.parameters;
-        CiKind[] result = new CiKind[params.length];
-        for (int i = 0; i < params.length; i++) {
-            result[i] = params[i].kind;
-        }
-        return result;
-    }
-
-
-    @Override
-    public CompilerStub emit(GraalContext context, XirTemplate t) {
-        final GraalCompilation comp = new GraalCompilation(context, compiler, null, -1, null, DebugInfoLevel.FULL);
-        try {
-            return new AMD64CompilerStubEmitter(comp, getArgumentKinds(t), t.resultOperand.kind).emit(t);
-        } finally {
-            comp.close();
-        }
+        return new AMD64XirAssembler(target);
     }
 }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64CallOpcode.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64CallOpcode.java	Wed Jan 11 13:35:49 2012 +0100
@@ -121,11 +121,11 @@
     public static void directCall(TargetMethodAssembler tasm, AMD64MacroAssembler masm, Object target, LIRDebugInfo info) {
         int before = masm.codeBuffer.position();
         if (target instanceof CiRuntimeCall) {
-            long maxOffset = tasm.compilation.compiler.runtime.getMaxCallTargetOffset((CiRuntimeCall) target);
+            long maxOffset = tasm.runtime.getMaxCallTargetOffset((CiRuntimeCall) target);
             if (maxOffset != (int) maxOffset) {
                 // offset might not fit a 32-bit immediate, generate an
                 // indirect call with a 64-bit immediate
-                CiRegister scratch = tasm.compilation.registerConfig.getScratchRegister();
+                CiRegister scratch = tasm.frameMap.registerConfig.getScratchRegister();
                 // TODO(cwi): we want to get rid of a generally reserved scratch register.
                 masm.movq(scratch, 0L);
                 masm.call(scratch);
@@ -159,7 +159,7 @@
     }
 
     private static Object asCallTarget(TargetMethodAssembler tasm, Object o) {
-        return tasm.compilation.compiler.runtime.asCallTarget(o);
+        return tasm.runtime.asCallTarget(o);
     }
 
     public static void shouldNotReachHere(TargetMethodAssembler tasm, AMD64MacroAssembler masm) {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64CompilerStubEmitter.java	Wed Jan 11 12:13:33 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,340 +0,0 @@
-/*
- * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package com.oracle.max.graal.compiler.target.amd64;
-
-import static com.oracle.max.cri.ci.CiCallingConvention.Type.*;
-import static com.oracle.max.cri.ci.CiValueUtil.*;
-
-import java.util.*;
-
-import com.oracle.max.asm.*;
-import com.oracle.max.asm.target.amd64.*;
-import com.oracle.max.asm.target.amd64.AMD64Assembler.ConditionFlag;
-import com.oracle.max.cri.ci.*;
-import com.oracle.max.cri.ci.CiRegister.*;
-import com.oracle.max.cri.ri.*;
-import com.oracle.max.cri.xir.*;
-import com.oracle.max.cri.xir.CiXirAssembler.*;
-import com.oracle.max.graal.compiler.*;
-import com.oracle.max.graal.compiler.asm.*;
-import com.oracle.max.graal.compiler.stub.*;
-
-/**
- * An object used to produce a single compiler stub.
- */
-public class AMD64CompilerStubEmitter {
-
-    private static final CiRegister convertArgument = AMD64.xmm0;
-    private static final CiRegister convertResult = AMD64.rax;
-
-    /**
-     * The slots in which the stub finds its incoming arguments.
-     * To get the arguments from the perspective of the stub's caller,
-     * use {@link CiStackSlot#asOutArg()}.
-     */
-    private final CiStackSlot[] inArgs;
-
-    /**
-     * The slot in which the stub places its return value (if any).
-     * To get the value from the perspective of the stub's caller,
-     * use {@link CiStackSlot#asOutArg()}.
-     */
-    private final CiStackSlot outResult;
-
-    /**
-     * The layout of the callee save area of the stub being emitted.
-     */
-    private CiCalleeSaveLayout calleeSaveLayout;
-
-    /**
-     * The compilation object for the stub being emitted.
-     */
-    private final GraalCompilation comp;
-
-    private final TargetMethodAssembler tasm;
-    private final AMD64MacroAssembler asm;
-
-    public AMD64CompilerStubEmitter(GraalCompilation compilation, CiKind[] argTypes, CiKind resultKind) {
-        compilation.initFrameMap();
-        this.comp = compilation;
-        final RiRegisterConfig registerConfig = compilation.compiler.compilerStubRegisterConfig;
-        this.asm = new AMD64MacroAssembler(compilation.compiler.target, registerConfig);
-        this.tasm = new TargetMethodAssembler(compilation, asm);
-
-        inArgs = new CiStackSlot[argTypes.length];
-        if (argTypes.length != 0) {
-            final CiValue[] locations = registerConfig.getCallingConvention(JavaCallee, argTypes, compilation.compiler.target, true).locations;
-            for (int i = 0; i < argTypes.length; i++) {
-                inArgs[i] = (CiStackSlot) locations[i];
-            }
-        }
-
-        if (resultKind != CiKind.Void) {
-            final CiValue location = registerConfig.getCallingConvention(JavaCallee, new CiKind[] {resultKind}, compilation.compiler.target, true).locations[0];
-            outResult = (CiStackSlot) location;
-        } else {
-            outResult = null;
-        }
-    }
-
-    public CompilerStub emit(CiRuntimeCall runtimeCall) {
-        emitStandardForward(null, runtimeCall);
-        String name = "graal-stub-" + runtimeCall;
-        CiTargetMethod targetMethod = tasm.finishTargetMethod(name, comp.compiler.runtime, true);
-        Object stubObject = comp.compiler.runtime.registerCompilerStub(targetMethod, name);
-        return new CompilerStub(null, runtimeCall.resultKind, stubObject, inArgs, outResult);
-    }
-
-    public CompilerStub emit(CompilerStub.Id stub) {
-        switch (stub) {
-            case f2i:
-                emitF2I();
-                break;
-            case f2l:
-                emitF2L();
-                break;
-            case d2i:
-                emitD2I();
-                break;
-            case d2l:
-                emitD2L();
-                break;
-        }
-
-        String name = "graal-stub-" + stub;
-        CiTargetMethod targetMethod = tasm.finishTargetMethod(name, comp.compiler.runtime, true);
-        Object stubObject = comp.compiler.runtime.registerCompilerStub(targetMethod, name);
-        return new CompilerStub(stub, stub.resultKind, stubObject, inArgs, outResult);
-    }
-
-    private static CiValue allocateOperand(XirTemp temp, ArrayList<CiRegister> allocatableRegisters) {
-        if (temp instanceof XirRegister) {
-            XirRegister fixed = (XirRegister) temp;
-            return fixed.register;
-        }
-
-        return newRegister(temp.kind, allocatableRegisters);
-    }
-
-    private static CiValue newRegister(CiKind kind, ArrayList<CiRegister> allocatableRegisters) {
-        assert kind != CiKind.Float && kind != CiKind.Double;
-        assert allocatableRegisters.size() > 0;
-        return allocatableRegisters.remove(allocatableRegisters.size() - 1).asValue(kind);
-    }
-
-    public CompilerStub emit(XirTemplate template) {
-        ArrayList<CiRegister> allocatableRegisters = new ArrayList<>(Arrays.asList(comp.registerConfig.getCategorizedAllocatableRegisters().get(RegisterFlag.CPU)));
-        for (XirTemp t : template.temps) {
-            if (t instanceof XirRegister) {
-                final XirRegister fixed = (XirRegister) t;
-                if (isRegister(fixed.register)) {
-                    allocatableRegisters.remove(asRegister(fixed.register));
-                }
-            }
-        }
-
-        prologue(comp.registerConfig.getCalleeSaveLayout());
-
-        CiValue[] operands = new CiValue[template.variableCount];
-
-        XirOperand resultOperand = template.resultOperand;
-
-        if (template.allocateResultOperand) {
-            CiValue outputOperand = CiValue.IllegalValue;
-            // This snippet has a result that must be separately allocated
-            // Otherwise it is assumed that the result is part of the inputs
-            if (resultOperand.kind != CiKind.Void && resultOperand.kind != CiKind.Illegal) {
-                outputOperand = outResult;
-                assert operands[resultOperand.index] == null;
-            }
-            operands[resultOperand.index] = outputOperand;
-        }
-
-        for (int i = 0; i < template.parameters.length; i++) {
-            final XirParameter param = template.parameters[i];
-            assert !(param instanceof XirConstantOperand) : "constant parameters not supported for stubs";
-
-            CiValue op = inArgs[i];
-            assert operands[param.index] == null;
-
-            // Is the value destroyed?
-            if (template.isParameterDestroyed(param.parameterIndex)) {
-                CiValue newOp = newRegister(op.kind, allocatableRegisters);
-                AMD64MoveOpcode.move(tasm, asm, newOp, op);
-                operands[param.index] = newOp;
-            } else {
-                operands[param.index] = op;
-            }
-        }
-
-        for (XirConstant c : template.constants) {
-            assert operands[c.index] == null;
-            operands[c.index] = c.value;
-        }
-
-        for (XirTemp t : template.temps) {
-            CiValue op = allocateOperand(t, allocatableRegisters);
-            assert operands[t.index] == null;
-            operands[t.index] = op;
-        }
-
-        for (CiValue operand : operands) {
-            assert operand != null;
-        }
-
-        Label[] labels = new Label[template.labels.length];
-        for (int i = 0; i < labels.length; i++) {
-            labels[i] = new Label();
-        }
-
-        assert template.marks.length == 0 : "marks not supported in compiler stubs";
-        AMD64XirOpcode.emitXirInstructions(tasm, asm, null, template.fastPath, labels, operands, null);
-        epilogue();
-        String stubName = "graal-" + template.name;
-        CiTargetMethod targetMethod = tasm.finishTargetMethod(stubName, comp.compiler.runtime, true);
-        Object stubObject = comp.compiler.runtime.registerCompilerStub(targetMethod, stubName);
-        return new CompilerStub(null, template.resultOperand.kind, stubObject, inArgs, outResult);
-    }
-
-    private void convertPrologue() {
-        prologue(new CiCalleeSaveLayout(0, -1, comp.compiler.target.wordSize, convertArgument, convertResult));
-        asm.movq(convertArgument, tasm.asAddress(inArgs[0]));
-    }
-
-    private void convertEpilogue() {
-        asm.movq(tasm.asAddress(outResult), convertResult);
-        epilogue();
-    }
-
-    private void emitD2L() {
-        emitCOMISSD(true, false);
-    }
-
-    private void emitD2I() {
-        emitCOMISSD(true, true);
-    }
-
-    private void emitF2L() {
-        emitCOMISSD(false, false);
-    }
-
-    private void emitF2I() {
-        emitCOMISSD(false, true);
-    }
-
-    private void emitCOMISSD(boolean isDouble, @SuppressWarnings("unused") boolean isInt) {
-        // TODO(tw): Check why isInt is never checked?
-        convertPrologue();
-        if (isDouble) {
-            asm.ucomisd(convertArgument, tasm.asDoubleConstRef(CiConstant.DOUBLE_0));
-        } else {
-            asm.ucomiss(convertArgument, tasm.asFloatConstRef(CiConstant.FLOAT_0));
-        }
-        Label nan = new Label();
-        Label ret = new Label();
-        asm.jccb(ConditionFlag.parity, nan);
-        asm.jccb(ConditionFlag.below, ret);
-
-        // input is > 0 -> return maxInt
-        // result register already contains 0x80000000, so subtracting 1 gives 0x7fffffff
-        asm.decrementl(convertResult, 1);
-        asm.jmpb(ret);
-
-        // input is NaN -> return 0
-        asm.bind(nan);
-        asm.xorptr(convertResult, convertResult);
-
-        asm.bind(ret);
-        convertEpilogue();
-    }
-
-    private void emitStandardForward(CompilerStub.Id stub, CiRuntimeCall call) {
-        if (stub != null) {
-            assert stub.resultKind == call.resultKind;
-            assert stub.arguments.length == call.arguments.length;
-            for (int i = 0; i < stub.arguments.length; i++) {
-                assert stub.arguments[i] == call.arguments[i];
-            }
-        }
-
-        prologue(comp.registerConfig.getCalleeSaveLayout());
-        forwardRuntimeCall(call);
-        epilogue();
-    }
-
-    private void prologue(CiCalleeSaveLayout csl) {
-        assert this.calleeSaveLayout == null;
-        assert csl != null : "stub should define a callee save area";
-        this.calleeSaveLayout = csl;
-        int entryCodeOffset = comp.compiler.runtime.codeOffset();
-        if (entryCodeOffset != 0) {
-            // pad to normal code entry point
-            asm.nop(entryCodeOffset);
-        }
-        final int frameSize = frameSize();
-        asm.subq(AMD64.rsp, frameSize);
-        tasm.setFrameSize(frameSize);
-        comp.frameMap().setFrameSize(frameSize);
-        asm.save(csl, csl.frameOffsetToCSA);
-    }
-
-    private void epilogue() {
-        tasm.targetMethod.setRegisterRestoreEpilogueOffset(asm.codeBuffer.position());
-
-        // Restore registers
-        int frameToCSA = calleeSaveLayout.frameOffsetToCSA;
-        asm.restore(calleeSaveLayout, frameToCSA);
-
-        // Restore rsp
-        asm.addq(AMD64.rsp, frameSize());
-        asm.ret(0);
-    }
-
-    private int frameSize() {
-        return comp.compiler.target.alignFrameSize(calleeSaveLayout.size);
-    }
-
-    private void forwardRuntimeCall(CiRuntimeCall call) {
-        // Load arguments
-        CiCallingConvention cc = comp.registerConfig.getCallingConvention(RuntimeCall, call.arguments, comp.compiler.target, false);
-        for (int i = 0; i < cc.locations.length; ++i) {
-            CiValue location = cc.locations[i];
-            asm.movq(asRegister(location), tasm.asAddress(inArgs[i]));
-        }
-
-        if (GraalOptions.AlignCallsForPatching) {
-            asm.alignForPatchableDirectCall();
-        }
-        // Call to the runtime
-        int before = asm.codeBuffer.position();
-        asm.call();
-        int after = asm.codeBuffer.position();
-        tasm.recordDirectCall(before, after - before, comp.compiler.runtime.asCallTarget(call), null);
-        asm.ensureUniquePC();
-
-        if (call.resultKind != CiKind.Void) {
-            CiRegister returnRegister = comp.registerConfig.getReturnRegister(call.resultKind);
-            asm.movq(tasm.asAddress(outResult), returnRegister);
-        }
-    }
-}
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64ConvertFIOpcode.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64ConvertFIOpcode.java	Wed Jan 11 13:35:49 2012 +0100
@@ -60,7 +60,7 @@
             default:
                 throw Util.shouldNotReachHere();
         }
-        tasm.compilation.lir().slowPaths.add(slowPath);
+        tasm.slowPaths.add(slowPath);
 
         masm.cmp32(asIntReg(result), Integer.MIN_VALUE);
         masm.jcc(ConditionFlag.equal, slowPath.start);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64ConvertFLOpcode.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64ConvertFLOpcode.java	Wed Jan 11 13:35:49 2012 +0100
@@ -61,7 +61,7 @@
             default:
                 throw Util.shouldNotReachHere();
         }
-        tasm.compilation.lir().slowPaths.add(slowPath);
+        tasm.slowPaths.add(slowPath);
 
         CiRegister tmp = asLongReg(scratch);
         masm.movq(tmp, java.lang.Long.MIN_VALUE);
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64DeoptimizationStub.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64DeoptimizationStub.java	Wed Jan 11 13:35:49 2012 +0100
@@ -53,7 +53,7 @@
         AMD64MacroAssembler masm = (AMD64MacroAssembler) tasm.asm;
 
         // TODO(cwi): we want to get rid of a generally reserved scratch register.
-        CiRegister scratch = tasm.compilation.registerConfig.getScratchRegister();
+        CiRegister scratch = tasm.frameMap.registerConfig.getScratchRegister();
 
         masm.bind(label);
         if (GraalOptions.CreateDeoptInfo && deoptInfo != null) {
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64LIRGenerator.java	Wed Jan 11 13:35:49 2012 +0100
@@ -44,7 +44,6 @@
 import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.compiler.gen.*;
 import com.oracle.max.graal.compiler.lir.*;
-import com.oracle.max.graal.compiler.stub.*;
 import com.oracle.max.graal.compiler.util.*;
 import com.oracle.max.graal.nodes.DeoptimizeNode.DeoptAction;
 import com.oracle.max.graal.nodes.*;
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64XirAssembler.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64XirAssembler.java	Wed Jan 11 13:35:49 2012 +0100
@@ -43,7 +43,6 @@
     protected XirTemplate buildTemplate(String name, boolean isStub) {
         List<XirInstruction> fastPath = new ArrayList<>(instructions.size());
         List<XirInstruction> slowPath = new ArrayList<>();
-        List<XirTemplate> calleeTemplates = new ArrayList<>();
 
         int flags = 0;
 
@@ -164,18 +163,6 @@
                     currentList.add(new XirInstruction(i.kind, i.op, i.result, i.x(), i.y(), fixedRAX));
                     appended = true;
                     break;
-                case CallStub:
-                    for (int j = 0; j < i.arguments.length; j++) {
-                        XirOperand op = i.arguments[j];
-                        if (op instanceof XirConstantOperand && (op.kind == CiKind.Object || op.kind == CiKind.Long)) {
-                            XirOperand tempLocation = createTemp("callStubTempLocation", op.kind);
-                            currentList.add(new XirInstruction(op.kind, XirOp.Mov, tempLocation, op));
-                            i.arguments[j] = tempLocation;
-                        }
-                    }
-                    flags |= HAS_STUB_CALL.mask;
-                    calleeTemplates.add((XirTemplate) i.extra);
-                    break;
                 case CallRuntime:
                     flags |= HAS_RUNTIME_CALL.mask;
                     break;
@@ -228,9 +215,8 @@
         XirParameter[] xirParameters = parameters.toArray(new XirParameter[parameters.size()]);
         XirTemp[] temporaryOperands = temps.toArray(new XirTemp[temps.size()]);
         XirConstant[] constantOperands = constants.toArray(new XirConstant[constants.size()]);
-        XirTemplate[] calleeTemplateArray = calleeTemplates.toArray(new XirTemplate[calleeTemplates.size()]);
         XirMark[] marksArray = marks.toArray(new XirMark[marks.size()]);
-        return new XirTemplate(name, this.variableCount, this.allocateResultOperand, resultOperand, fp, sp, xirLabels, xirParameters, temporaryOperands, constantOperands, flags, calleeTemplateArray, marksArray, outgoingStackSize);
+        return new XirTemplate(name, this.variableCount, this.allocateResultOperand, resultOperand, fp, sp, xirLabels, xirParameters, temporaryOperands, constantOperands, flags, marksArray, outgoingStackSize);
     }
 
     @Override
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64XirOpcode.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/target/amd64/AMD64XirOpcode.java	Wed Jan 11 13:35:49 2012 +0100
@@ -85,7 +85,7 @@
         }
 
         if (snippet.template.slowPath != null) {
-            tasm.compilation.lir().slowPaths.add(new SlowPath(op, labels, snippet.marks));
+            tasm.slowPaths.add(new SlowPath(op, labels, snippet.marks));
         }
     }
 
@@ -294,26 +294,13 @@
 
                     break;
 
-                case CallStub: {
-                    XirTemplate stubId = (XirTemplate) inst.extra;
-                    CiValue result = CiValue.IllegalValue;
-                    if (inst.result != null) {
-                        result = operands[inst.result.index];
-                    }
-                    CiValue[] args = new CiValue[inst.arguments.length];
-                    for (int i = 0; i < args.length; i++) {
-                        args[i] = operands[inst.arguments[i].index];
-                    }
-                    AMD64CallOpcode.callStub(tasm, masm, tasm.compilation.compiler.lookupStub(stubId), info, result, args);
-                    break;
-                }
                 case CallRuntime: {
                     CiKind[] signature = new CiKind[inst.arguments.length];
                     for (int i = 0; i < signature.length; i++) {
                         signature[i] = inst.arguments[i].kind;
                     }
 
-                    CiCallingConvention cc = tasm.compilation.registerConfig.getCallingConvention(RuntimeCall, signature, tasm.target, false);
+                    CiCallingConvention cc = tasm.frameMap.registerConfig.getCallingConvention(RuntimeCall, signature, tasm.target, false);
                     for (int i = 0; i < inst.arguments.length; i++) {
                         CiValue argumentLocation = cc.locations[i];
                         CiValue argumentSourceLocation = operands[inst.arguments[i].index];
@@ -326,7 +313,7 @@
                     AMD64CallOpcode.directCall(tasm, masm, runtimeCallInformation.target, (runtimeCallInformation.useInfoAfter) ? infoAfter : info);
 
                     if (inst.result != null && inst.result.kind != CiKind.Illegal && inst.result.kind != CiKind.Void) {
-                        CiRegister returnRegister = tasm.compilation.registerConfig.getReturnRegister(inst.result.kind);
+                        CiRegister returnRegister = tasm.frameMap.registerConfig.getReturnRegister(inst.result.kind);
                         CiValue resultLocation = returnRegister.asValue(inst.result.kind.stackKind());
                         AMD64MoveOpcode.move(tasm, masm, operands[inst.result.index], resultLocation);
                     }
@@ -430,7 +417,7 @@
                     break;
                 }
                 case StackOverflowCheck: {
-                    int frameSize = tasm.compilation.frameMap().frameSize();
+                    int frameSize = tasm.frameMap.frameSize();
                     int lastFramePage = frameSize / tasm.target.pageSize;
                     // emit multiple stack bangs for methods with frames larger than a page
                     for (int i = 0; i <= lastFramePage; i++) {
@@ -441,7 +428,7 @@
                     break;
                 }
                 case PushFrame: {
-                    int frameSize = tasm.compilation.frameMap().frameSize();
+                    int frameSize = tasm.frameMap.frameSize();
                     masm.decrementq(AMD64.rsp, frameSize); // does not emit code for frameSize == 0
                     if (GraalOptions.ZapStackOnMethodEntry) {
                         final int intSize = 4;
@@ -449,22 +436,22 @@
                             masm.movl(new CiAddress(CiKind.Int, AMD64.rsp.asValue(), i * intSize), 0xC1C1C1C1);
                         }
                     }
-                    CiCalleeSaveLayout csl = tasm.compilation.registerConfig.getCalleeSaveLayout();
+                    CiCalleeSaveLayout csl = tasm.frameMap.registerConfig.getCalleeSaveLayout();
                     if (csl != null && csl.size != 0) {
-                        int frameToCSA = tasm.compilation.frameMap().offsetToCalleeSaveArea();
+                        int frameToCSA = tasm.frameMap.offsetToCalleeSaveArea();
                         assert frameToCSA >= 0;
                         masm.save(csl, frameToCSA);
                     }
                     break;
                 }
                 case PopFrame: {
-                    int frameSize = tasm.compilation.frameMap().frameSize();
+                    int frameSize = tasm.frameMap.frameSize();
 
-                    CiCalleeSaveLayout csl = tasm.compilation.registerConfig.getCalleeSaveLayout();
+                    CiCalleeSaveLayout csl = tasm.frameMap.registerConfig.getCalleeSaveLayout();
                     if (csl != null && csl.size != 0) {
                         tasm.targetMethod.setRegisterRestoreEpilogueOffset(masm.codeBuffer.position());
                         // saved all registers, restore all registers
-                        int frameToCSA = tasm.compilation.frameMap().offsetToCalleeSaveArea();
+                        int frameToCSA = tasm.frameMap.offsetToCalleeSaveArea();
                         masm.restore(csl, frameToCSA);
                     }
 
@@ -481,7 +468,7 @@
                     if (isRegister(result)) {
                         masm.pop(asRegister(result));
                     } else {
-                        CiRegister rscratch = tasm.compilation.registerConfig.getScratchRegister();
+                        CiRegister rscratch = tasm.frameMap.registerConfig.getScratchRegister();
                         masm.pop(rscratch);
                         AMD64MoveOpcode.move(tasm, masm, result, rscratch.asValue());
                     }
@@ -569,7 +556,7 @@
 
     private static CiValue assureNot64BitConstant(TargetMethodAssembler tasm, AMD64MacroAssembler masm, CiValue value) {
         if (isConstant(value) && (value.kind == CiKind.Long || value.kind == CiKind.Object)) {
-            CiRegisterValue register = tasm.compilation.registerConfig.getScratchRegister().asValue(value.kind);
+            CiRegisterValue register = tasm.frameMap.registerConfig.getScratchRegister().asValue(value.kind);
             AMD64MoveOpcode.move(tasm, masm, register, value);
             return register;
         }
@@ -578,7 +565,7 @@
 
     private static CiRegisterValue assureInRegister(TargetMethodAssembler tasm, AMD64MacroAssembler masm, CiValue pointer) {
         if (isConstant(pointer)) {
-            CiRegisterValue register = tasm.compilation.registerConfig.getScratchRegister().asValue(pointer.kind);
+            CiRegisterValue register = tasm.frameMap.registerConfig.getScratchRegister().asValue(pointer.kind);
             AMD64MoveOpcode.move(tasm, masm, register, pointer);
             return register;
         }
--- a/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/Util.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/util/Util.java	Wed Jan 11 13:35:49 2012 +0100
@@ -26,7 +26,6 @@
 
 import com.oracle.max.cri.ci.*;
 import com.oracle.max.criutils.*;
-import com.oracle.max.graal.compiler.*;
 import com.oracle.max.graal.graph.*;
 import com.oracle.max.graal.nodes.*;
 
@@ -346,24 +345,6 @@
     }
 
     /**
-     * Determines if the kinds of two given IR nodes are equal at the {@linkplain #archKind(CiKind) architecture}
-     * level in the context of the {@linkplain GraalCompilation#compilation()} compilation.
-     */
-    public static boolean archKindsEqual(ValueNode i, ValueNode other) {
-        return archKindsEqual(i.kind(), other.kind());
-    }
-
-    /**
-     * Determines if two given kinds are equal at the {@linkplain #archKind(CiKind) architecture} level
-     * in the context of the {@linkplain GraalCompilation#compilation()} compilation.
-     */
-    public static boolean archKindsEqual(CiKind k1, CiKind k2) {
-        // TODO(cwi): I think that implementation should do it with the new handling of Word types.
-        return k1 == k2;
-    }
-
-
-    /**
      * Checks that two instructions are equivalent, optionally comparing constants.
      * @param x the first instruction
      * @param y the second instruction
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/CompilerImpl.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/CompilerImpl.java	Wed Jan 11 13:35:49 2012 +0100
@@ -151,17 +151,14 @@
     @Override
     public GraalCompiler getCompiler() {
         if (compiler == null) {
-            RiRegisterConfig registerConfig;
-
             // these options are important - graal will not generate correct code without them
             GraalOptions.StackShadowPages = config.stackShadowPages;
 
-            registerConfig = getRuntime().globalStubRegConfig;
-            RiXirGenerator generator = new HotSpotXirGenerator(config, getTarget(), registerConfig, this);
+            RiXirGenerator generator = new HotSpotXirGenerator(config, getTarget(), getRuntime().getGlobalStubRegisterConfig(), this);
             if (Logger.ENABLED) {
                 generator = LoggingProxy.getProxy(RiXirGenerator.class, generator);
             }
-            compiler = new GraalCompiler(context, getRuntime(), getTarget(), generator, registerConfig);
+            compiler = new GraalCompiler(context, getRuntime(), getTarget(), generator);
         }
         return compiler;
     }
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotRuntime.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotRuntime.java	Wed Jan 11 13:35:49 2012 +0100
@@ -51,7 +51,7 @@
     final GraalContext context;
     final HotSpotVMConfig config;
     final HotSpotRegisterConfig regConfig;
-    public final HotSpotRegisterConfig globalStubRegConfig;
+    private final HotSpotRegisterConfig globalStubRegConfig;
     private final Compiler compiler;
 
     public HotSpotRuntime(GraalContext context, HotSpotVMConfig config, Compiler compiler) {
@@ -430,4 +430,9 @@
         Compiler compilerInstance = CompilerImpl.getInstance();
         return HotSpotTargetMethod.installMethod(compilerInstance, (HotSpotMethodResolved) method, code, false);
     }
+
+    @Override
+    public RiRegisterConfig getGlobalStubRegisterConfig() {
+        return globalStubRegConfig;
+    }
 }
--- a/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotXirGenerator.java	Wed Jan 11 12:13:33 2012 +0100
+++ b/graal/com.oracle.max.graal.hotspot/src/com/oracle/max/graal/hotspot/ri/HotSpotXirGenerator.java	Wed Jan 11 13:35:49 2012 +0100
@@ -1306,10 +1306,8 @@
     }
 
     @Override
-    public List<XirTemplate> makeTemplates(CiXirAssembler asm) {
+    public void initialize(CiXirAssembler asm) {
         this.globalAsm = asm;
-        List<XirTemplate> templates = new ArrayList<>();
-        return templates;
     }
 
     private void verifyPointer(CiXirAssembler asm, XirOperand pointer) {