< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir/src/org/graalvm/compiler/lir/gen/LIRGenerator.java

Print this page




  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.gen;
  24 
  25 import static jdk.vm.ci.code.ValueUtil.asAllocatableValue;
  26 import static jdk.vm.ci.code.ValueUtil.isAllocatableValue;
  27 import static jdk.vm.ci.code.ValueUtil.isLegal;
  28 import static jdk.vm.ci.code.ValueUtil.isStackSlot;
  29 import static org.graalvm.compiler.lir.LIRValueUtil.asConstant;
  30 import static org.graalvm.compiler.lir.LIRValueUtil.isConstantValue;
  31 import static org.graalvm.compiler.lir.LIRValueUtil.isVariable;
  32 import static org.graalvm.compiler.lir.LIRValueUtil.isVirtualStackSlot;
  33 
  34 import java.util.ArrayList;
  35 import java.util.List;
  36 

  37 import org.graalvm.compiler.asm.Label;
  38 import org.graalvm.compiler.core.common.LIRKind;
  39 import org.graalvm.compiler.core.common.calc.Condition;
  40 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
  41 import org.graalvm.compiler.core.common.spi.CodeGenProviders;
  42 import org.graalvm.compiler.core.common.spi.ForeignCallLinkage;
  43 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
  44 import org.graalvm.compiler.core.common.spi.LIRKindTool;
  45 import org.graalvm.compiler.core.common.type.Stamp;
  46 import org.graalvm.compiler.debug.GraalError;
  47 import org.graalvm.compiler.debug.TTY;
  48 import org.graalvm.compiler.graph.NodeSourcePosition;
  49 import org.graalvm.compiler.lir.ConstantValue;
  50 import org.graalvm.compiler.lir.LIR;
  51 import org.graalvm.compiler.lir.LIRFrameState;
  52 import org.graalvm.compiler.lir.LIRInstruction;
  53 import org.graalvm.compiler.lir.LIRVerifier;
  54 import org.graalvm.compiler.lir.LabelRef;
  55 import org.graalvm.compiler.lir.StandardOp;
  56 import org.graalvm.compiler.lir.StandardOp.BlockEndOp;


 184      * Hide {@link #nextVariable()} from other users.
 185      */
 186     public abstract static class VariableProvider {
 187         private int numVariables;
 188 
 189         public int numVariables() {
 190             return numVariables;
 191         }
 192 
 193         private int nextVariable() {
 194             return numVariables++;
 195         }
 196     }
 197 
 198     @Override
 199     public Variable newVariable(ValueKind<?> valueKind) {
 200         return new Variable(valueKind, ((VariableProvider) res.getLIR()).nextVariable());
 201     }
 202 
 203     @Override





 204     public RegisterAttributes attributes(Register register) {
 205         return res.getFrameMapBuilder().getRegisterConfig().getAttributesMap()[register.number];
 206     }
 207 
 208     @Override
 209     public Variable emitMove(Value input) {
 210         assert !(input instanceof Variable) : "Creating a copy of a variable via this method is not supported (and potentially a bug): " + input;
 211         Variable result = newVariable(input.getValueKind());
 212         emitMove(result, input);
 213         return result;
 214     }
 215 
 216     @Override
 217     public void emitMove(AllocatableValue dst, Value src) {
 218         append(moveFactory.createMove(dst, src));
 219     }
 220 
 221     @Override
 222     public void emitMoveConstant(AllocatableValue dst, Constant src) {
 223         append(moveFactory.createLoad(dst, src));
 224     }
 225 
 226     @Override
 227     public Value emitConstant(LIRKind kind, Constant constant) {
 228         if (moveFactory.canInlineConstant(constant)) {
 229             return new ConstantValue(toRegisterKind(kind), constant);
 230         } else {
 231             return emitLoadConstant(kind, constant);
 232         }
 233     }
 234 
 235     @Override
 236     public Value emitJavaConstant(JavaConstant constant) {
 237         return emitConstant(getValueKind(constant.getJavaKind()), constant);
 238     }
 239 
 240     @Override
 241     public AllocatableValue emitLoadConstant(ValueKind<?> kind, Constant constant) {
 242         Variable result = newVariable(kind);
 243         emitMoveConstant(result, constant);
 244         return result;
 245     }
 246 
 247     @Override
 248     public AllocatableValue asAllocatable(Value value) {
 249         if (isAllocatableValue(value)) {
 250             return asAllocatableValue(value);
 251         } else if (isConstantValue(value)) {


 272     }
 273 
 274     /**
 275      * Determines if only oop maps are required for the code generated from the LIR.
 276      */
 277     @Override
 278     public boolean needOnlyOopMaps() {
 279         return false;
 280     }
 281 
 282     /**
 283      * Gets the ABI specific operand used to return a value of a given kind from a method.
 284      *
 285      * @param javaKind the kind of value being returned
 286      * @param valueKind the backend type of the value being returned
 287      * @return the operand representing the ABI defined location used return a value of kind
 288      *         {@code kind}
 289      */
 290     @Override
 291     public AllocatableValue resultOperandFor(JavaKind javaKind, ValueKind<?> valueKind) {
 292         Register reg = res.getFrameMapBuilder().getRegisterConfig().getReturnRegister(javaKind);
 293         assert target().arch.canStoreValue(reg.getRegisterCategory(), valueKind.getPlatformKind()) : reg.getRegisterCategory() + " " + valueKind.getPlatformKind();
 294         return reg.asValue(valueKind);
 295     }
 296 
 297     NodeSourcePosition currentPosition;
 298 
 299     @Override
 300     public void setSourcePosition(NodeSourcePosition position) {
 301         currentPosition = position;
 302     }
 303 
 304     @Override
 305     public <I extends LIRInstruction> I append(I op) {
 306         LIR lir = res.getLIR();
 307         if (printIrWithLir) {
 308             TTY.println(op.toStringWithIdPrefix());
 309             TTY.println();
 310         }
 311         assert LIRVerifier.verify(op);
 312         ArrayList<LIRInstruction> lirForBlock = lir.getLIRforBlock(getCurrentBlock());




  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.gen;
  24 
  25 import static jdk.vm.ci.code.ValueUtil.asAllocatableValue;
  26 import static jdk.vm.ci.code.ValueUtil.isAllocatableValue;
  27 import static jdk.vm.ci.code.ValueUtil.isLegal;
  28 import static jdk.vm.ci.code.ValueUtil.isStackSlot;
  29 import static org.graalvm.compiler.lir.LIRValueUtil.asConstant;
  30 import static org.graalvm.compiler.lir.LIRValueUtil.isConstantValue;
  31 import static org.graalvm.compiler.lir.LIRValueUtil.isVariable;
  32 import static org.graalvm.compiler.lir.LIRValueUtil.isVirtualStackSlot;
  33 
  34 import java.util.ArrayList;
  35 import java.util.List;
  36 
  37 import jdk.vm.ci.code.RegisterConfig;
  38 import org.graalvm.compiler.asm.Label;
  39 import org.graalvm.compiler.core.common.LIRKind;
  40 import org.graalvm.compiler.core.common.calc.Condition;
  41 import org.graalvm.compiler.core.common.cfg.AbstractBlockBase;
  42 import org.graalvm.compiler.core.common.spi.CodeGenProviders;
  43 import org.graalvm.compiler.core.common.spi.ForeignCallLinkage;
  44 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
  45 import org.graalvm.compiler.core.common.spi.LIRKindTool;
  46 import org.graalvm.compiler.core.common.type.Stamp;
  47 import org.graalvm.compiler.debug.GraalError;
  48 import org.graalvm.compiler.debug.TTY;
  49 import org.graalvm.compiler.graph.NodeSourcePosition;
  50 import org.graalvm.compiler.lir.ConstantValue;
  51 import org.graalvm.compiler.lir.LIR;
  52 import org.graalvm.compiler.lir.LIRFrameState;
  53 import org.graalvm.compiler.lir.LIRInstruction;
  54 import org.graalvm.compiler.lir.LIRVerifier;
  55 import org.graalvm.compiler.lir.LabelRef;
  56 import org.graalvm.compiler.lir.StandardOp;
  57 import org.graalvm.compiler.lir.StandardOp.BlockEndOp;


 185      * Hide {@link #nextVariable()} from other users.
 186      */
 187     public abstract static class VariableProvider {
 188         private int numVariables;
 189 
 190         public int numVariables() {
 191             return numVariables;
 192         }
 193 
 194         private int nextVariable() {
 195             return numVariables++;
 196         }
 197     }
 198 
 199     @Override
 200     public Variable newVariable(ValueKind<?> valueKind) {
 201         return new Variable(valueKind, ((VariableProvider) res.getLIR()).nextVariable());
 202     }
 203 
 204     @Override
 205     public RegisterConfig getRegisterConfig() {
 206         return res.getRegisterConfig();
 207     }
 208 
 209     @Override
 210     public RegisterAttributes attributes(Register register) {
 211         return getRegisterConfig().getAttributesMap()[register.number];
 212     }
 213 
 214     @Override
 215     public Variable emitMove(Value input) {
 216         assert !(input instanceof Variable) : "Creating a copy of a variable via this method is not supported (and potentially a bug): " + input;
 217         Variable result = newVariable(input.getValueKind());
 218         emitMove(result, input);
 219         return result;
 220     }
 221 
 222     @Override
 223     public void emitMove(AllocatableValue dst, Value src) {
 224         append(moveFactory.createMove(dst, src));
 225     }
 226 
 227     @Override
 228     public void emitMoveConstant(AllocatableValue dst, Constant src) {
 229         append(moveFactory.createLoad(dst, src));
 230     }
 231 
 232     @Override
 233     public Value emitConstant(LIRKind kind, Constant constant) {
 234         if (moveFactory.canInlineConstant(constant)) {
 235             return new ConstantValue(toRegisterKind(kind), constant);
 236         } else {
 237             return emitLoadConstant(toRegisterKind(kind), constant);
 238         }
 239     }
 240 
 241     @Override
 242     public Value emitJavaConstant(JavaConstant constant) {
 243         return emitConstant(getValueKind(constant.getJavaKind()), constant);
 244     }
 245 
 246     @Override
 247     public AllocatableValue emitLoadConstant(ValueKind<?> kind, Constant constant) {
 248         Variable result = newVariable(kind);
 249         emitMoveConstant(result, constant);
 250         return result;
 251     }
 252 
 253     @Override
 254     public AllocatableValue asAllocatable(Value value) {
 255         if (isAllocatableValue(value)) {
 256             return asAllocatableValue(value);
 257         } else if (isConstantValue(value)) {


 278     }
 279 
 280     /**
 281      * Determines if only oop maps are required for the code generated from the LIR.
 282      */
 283     @Override
 284     public boolean needOnlyOopMaps() {
 285         return false;
 286     }
 287 
 288     /**
 289      * Gets the ABI specific operand used to return a value of a given kind from a method.
 290      *
 291      * @param javaKind the kind of value being returned
 292      * @param valueKind the backend type of the value being returned
 293      * @return the operand representing the ABI defined location used return a value of kind
 294      *         {@code kind}
 295      */
 296     @Override
 297     public AllocatableValue resultOperandFor(JavaKind javaKind, ValueKind<?> valueKind) {
 298         Register reg = getRegisterConfig().getReturnRegister(javaKind);
 299         assert target().arch.canStoreValue(reg.getRegisterCategory(), valueKind.getPlatformKind()) : reg.getRegisterCategory() + " " + valueKind.getPlatformKind();
 300         return reg.asValue(valueKind);
 301     }
 302 
 303     NodeSourcePosition currentPosition;
 304 
 305     @Override
 306     public void setSourcePosition(NodeSourcePosition position) {
 307         currentPosition = position;
 308     }
 309 
 310     @Override
 311     public <I extends LIRInstruction> I append(I op) {
 312         LIR lir = res.getLIR();
 313         if (printIrWithLir) {
 314             TTY.println(op.toStringWithIdPrefix());
 315             TTY.println();
 316         }
 317         assert LIRVerifier.verify(op);
 318         ArrayList<LIRInstruction> lirForBlock = lir.getLIRforBlock(getCurrentBlock());


< prev index next >