1 /*
   2  * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.lir.framemap;
  24 
  25 import java.util.BitSet;
  26 import java.util.List;
  27 
  28 import org.graalvm.compiler.lir.VirtualStackSlot;
  29 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  30 
  31 import jdk.vm.ci.code.CallingConvention;
  32 import jdk.vm.ci.code.CodeCacheProvider;
  33 import jdk.vm.ci.code.RegisterConfig;
  34 import jdk.vm.ci.meta.ValueKind;
  35 
  36 /**
  37  * A {@link FrameMapBuilder} is used to collect all information necessary to
  38  * {@linkplain #buildFrameMap create} a {@link FrameMap}.
  39  */
  40 public abstract class FrameMapBuilder {
  41 
  42     /**
  43      * Reserves a spill slot in the frame of the method being compiled. The returned slot is aligned
  44      * on its natural alignment, i.e., an 8-byte spill slot is aligned at an 8-byte boundary, unless
  45      * overridden by a subclass.
  46      *
  47      * @param kind The kind of the spill slot to be reserved.
  48      * @return A spill slot denoting the reserved memory area.
  49      */
  50     public abstract VirtualStackSlot allocateSpillSlot(ValueKind<?> kind);
  51 
  52     /**
  53      * Reserves a number of contiguous slots in the frame of the method being compiled. If the
  54      * requested number of slots is 0, this method returns {@code null}.
  55      *
  56      * @param slots the number of slots to reserve
  57      * @param objects specifies the indexes of the object pointer slots. The caller is responsible
  58      *            for guaranteeing that each such object pointer slot is initialized before any
  59      *            instruction that uses a reference map. Without this guarantee, the garbage
  60      *            collector could see garbage object values.
  61      * @param outObjectStackSlots if non-null, the object pointer slots allocated are added to this
  62      *            list
  63      * @return the first reserved stack slot (i.e., at the lowest address)
  64      */
  65     public abstract VirtualStackSlot allocateStackSlots(int slots, BitSet objects, List<VirtualStackSlot> outObjectStackSlots);
  66 
  67     public abstract RegisterConfig getRegisterConfig();
  68 
  69     public abstract CodeCacheProvider getCodeCache();
  70 
  71     /**
  72      * Informs the frame map that the compiled code calls a particular method, which may need stack
  73      * space for outgoing arguments.
  74      *
  75      * @param cc The calling convention for the called method.
  76      */
  77     public abstract void callsMethod(CallingConvention cc);
  78 
  79     /**
  80      * Creates a {@linkplain FrameMap} based on the information collected by this
  81      * {@linkplain FrameMapBuilder}.
  82      */
  83     public abstract FrameMap buildFrameMap(LIRGenerationResult result);
  84 }