# HG changeset patch # User Roland Schatz # Date 1412239697 -7200 # Node ID 3b6759c384a93cb6254a85f4be39f52e18d9d0e8 # Parent d6e4c9031ff6fa325dcecbd42c1298a1978d7e80 Introduce emitLoadConstant in LIRGeneratorTool. diff -r d6e4c9031ff6 -r 3b6759c384a9 graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineBytecodeParser.java --- a/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineBytecodeParser.java Thu Oct 02 10:36:12 2014 +0200 +++ b/graal/com.oracle.graal.baseline/src/com/oracle/graal/baseline/BaselineBytecodeParser.java Thu Oct 02 10:48:17 2014 +0200 @@ -595,10 +595,7 @@ @Override protected Value appendConstant(Constant constant) { - if (gen.canInlineConstant(constant)) { - return constant; - } - return gen.emitMove(constant); + return gen.emitLoadConstant(constant); } @Override diff -r d6e4c9031ff6 -r 3b6759c384a9 graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java --- a/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java Thu Oct 02 10:36:12 2014 +0200 +++ b/graal/com.oracle.graal.compiler.amd64/src/com/oracle/graal/compiler/amd64/AMD64LIRGenerator.java Thu Oct 02 10:48:17 2014 +0200 @@ -93,21 +93,6 @@ } @Override - public boolean canStoreConstant(Constant c) { - // there is no immediate move of 64-bit constants on Intel - switch (c.getKind()) { - case Long: - return Util.isInt(c.asLong()) && !getCodeCache().needsDataPatch(c); - case Double: - return false; - case Object: - return c.isNull(); - default: - return true; - } - } - - @Override public boolean canInlineConstant(Constant c) { switch (c.getKind()) { case Long: @@ -119,13 +104,6 @@ } } - @Override - public Variable emitMove(Value input) { - Variable result = newVariable(input.getLIRKind()); - emitMove(result, input); - return result; - } - protected AMD64LIRInstruction createMove(AllocatableValue dst, Value src) { if (src instanceof AMD64AddressValue) { return new LeaOp(dst, (AMD64AddressValue) src); diff -r d6e4c9031ff6 -r 3b6759c384a9 graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILLIRGenerator.java --- a/graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILLIRGenerator.java Thu Oct 02 10:36:12 2014 +0200 +++ b/graal/com.oracle.graal.compiler.hsail/src/com/oracle/graal/compiler/hsail/HSAILLIRGenerator.java Thu Oct 02 10:48:17 2014 +0200 @@ -62,12 +62,6 @@ } @Override - public boolean canStoreConstant(Constant c) { - // Operand b must be in the .reg state space. - return false; - } - - @Override public boolean canInlineConstant(Constant c) { switch (c.getKind()) { case Long: @@ -79,13 +73,6 @@ } } - @Override - public Variable emitMove(Value input) { - Variable result = newVariable(input.getLIRKind()); - emitMove(result, input); - return result; - } - protected HSAILLIRInstruction createMove(AllocatableValue dst, Value src) { if (src instanceof HSAILAddressValue) { return new LeaOp(dst, (HSAILAddressValue) src); diff -r d6e4c9031ff6 -r 3b6759c384a9 graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java --- a/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java Thu Oct 02 10:36:12 2014 +0200 +++ b/graal/com.oracle.graal.compiler.ptx/src/com/oracle/graal/compiler/ptx/PTXLIRGenerator.java Thu Oct 02 10:48:17 2014 +0200 @@ -93,12 +93,6 @@ } @Override - public boolean canStoreConstant(Constant c) { - // Operand b must be in the .reg state space. - return false; - } - - @Override public boolean canInlineConstant(Constant c) { switch (c.getKind()) { case Long: @@ -131,13 +125,6 @@ } @Override - public Variable emitMove(Value input) { - Variable result = newVariable(input.getLIRKind()); - emitMove(result, input); - return result; - } - - @Override public void emitMove(AllocatableValue dst, Value src) { if (isRegister(src) || isStackSlot(dst)) { append(new MoveFromRegOp(dst, src)); diff -r d6e4c9031ff6 -r 3b6759c384a9 graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java --- a/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java Thu Oct 02 10:36:12 2014 +0200 +++ b/graal/com.oracle.graal.compiler.sparc/src/com/oracle/graal/compiler/sparc/SPARCLIRGenerator.java Thu Oct 02 10:48:17 2014 +0200 @@ -83,18 +83,6 @@ } @Override - public boolean canStoreConstant(Constant c) { - // SPARC can only store integer null constants (via g0) - switch (c.getKind()) { - case Float: - case Double: - return false; - default: - return c.isDefaultForKind(); - } - } - - @Override public boolean canInlineConstant(Constant c) { switch (c.getKind()) { case Int: @@ -108,13 +96,6 @@ } } - @Override - public Variable emitMove(Value input) { - Variable result = newVariable(input.getLIRKind()); - emitMove(result, input); - return result; - } - protected SPARCLIRInstruction createMove(AllocatableValue dst, Value src) { if (src instanceof SPARCAddressValue) { return new LoadAddressOp(dst, (SPARCAddressValue) src); diff -r d6e4c9031ff6 -r 3b6759c384a9 graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu Oct 02 10:36:12 2014 +0200 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotLIRGenerator.java Thu Oct 02 10:48:17 2014 +0200 @@ -51,6 +51,7 @@ import com.oracle.graal.lir.amd64.AMD64Move.MoveFromRegOp; import com.oracle.graal.lir.amd64.AMD64Move.StoreOp; import com.oracle.graal.lir.gen.*; +import com.oracle.graal.phases.util.*; /** * LIR generator specialized for AMD64 HotSpot. @@ -459,6 +460,28 @@ return result; } + /** + * Checks whether the supplied constant can be used without loading it into a register for store + * operations, i.e., on the right hand side of a memory access. + * + * @param c The constant to check. + * @return True if the constant can be used directly, false if the constant needs to be in a + * register. + */ + protected boolean canStoreConstant(Constant c) { + // there is no immediate move of 64-bit constants on Intel + switch (c.getKind()) { + case Long: + return Util.isInt(c.asLong()) && !getCodeCache().needsDataPatch(c); + case Double: + return false; + case Object: + return c.isNull(); + default: + return true; + } + } + @Override public void emitStore(LIRKind kind, Value address, Value inputVal, LIRFrameState state) { AMD64AddressValue storeAddress = asAddressValue(address); diff -r d6e4c9031ff6 -r 3b6759c384a9 graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotLIRGenerator.java Thu Oct 02 10:36:12 2014 +0200 +++ b/graal/com.oracle.graal.hotspot.hsail/src/com/oracle/graal/hotspot/hsail/HSAILHotSpotLIRGenerator.java Thu Oct 02 10:48:17 2014 +0200 @@ -93,8 +93,7 @@ return config.narrowKlassBase; } - @Override - public boolean canStoreConstant(Constant c) { + private static boolean canStoreConstant(Constant c) { return !(c instanceof HotSpotObjectConstant); } diff -r d6e4c9031ff6 -r 3b6759c384a9 graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLIRGenerator.java --- a/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLIRGenerator.java Thu Oct 02 10:36:12 2014 +0200 +++ b/graal/com.oracle.graal.hotspot.sparc/src/com/oracle/graal/hotspot/sparc/SPARCHotSpotLIRGenerator.java Thu Oct 02 10:48:17 2014 +0200 @@ -191,6 +191,17 @@ return result; } + private static boolean canStoreConstant(Constant c) { + // SPARC can only store integer null constants (via g0) + switch (c.getKind()) { + case Float: + case Double: + return false; + default: + return c.isDefaultForKind(); + } + } + @Override public void emitStore(LIRKind kind, Value address, Value inputVal, LIRFrameState state) { SPARCAddressValue storeAddress = asAddressValue(address); diff -r d6e4c9031ff6 -r 3b6759c384a9 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java Thu Oct 02 10:36:12 2014 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGenerator.java Thu Oct 02 10:48:17 2014 +0200 @@ -111,7 +111,20 @@ } @Override - public abstract Variable emitMove(Value input); + public Variable emitMove(Value input) { + Variable result = newVariable(input.getLIRKind()); + emitMove(result, input); + return result; + } + + @Override + public Value emitLoadConstant(Constant constant) { + if (canInlineConstant(constant)) { + return constant; + } else { + return emitMove(constant); + } + } public AllocatableValue asAllocatable(Value value) { if (isAllocatableValue(value)) { @@ -128,6 +141,16 @@ return (Variable) value; } + /** + * Checks whether the supplied constant can be used without loading it into a register for most + * operations, i.e., for commonly used arithmetic, logical, and comparison operations. + * + * @param c The constant to check. + * @return True if the constant can be used directly, false if the constant needs to be in a + * register. + */ + protected abstract boolean canInlineConstant(Constant c); + public Value loadNonConst(Value value) { if (isConstant(value) && !canInlineConstant((Constant) value)) { return emitMove(value); diff -r d6e4c9031ff6 -r 3b6759c384a9 graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java --- a/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java Thu Oct 02 10:36:12 2014 +0200 +++ b/graal/com.oracle.graal.lir/src/com/oracle/graal/lir/gen/LIRGeneratorTool.java Thu Oct 02 10:48:17 2014 +0200 @@ -52,6 +52,8 @@ void doBlockEnd(AbstractBlock block); + Value emitLoadConstant(Constant constant); + Value emitLoad(LIRKind kind, Value address, LIRFrameState state); void emitStore(LIRKind kind, Value address, Value input, LIRFrameState state); @@ -84,26 +86,6 @@ Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState state, Value... args); - /** - * Checks whether the supplied constant can be used without loading it into a register for most - * operations, i.e., for commonly used arithmetic, logical, and comparison operations. - * - * @param c The constant to check. - * @return True if the constant can be used directly, false if the constant needs to be in a - * register. - */ - boolean canInlineConstant(Constant c); - - /** - * Checks whether the supplied constant can be used without loading it into a register for store - * operations, i.e., on the right hand side of a memory access. - * - * @param c The constant to check. - * @return True if the constant can be used directly, false if the constant needs to be in a - * register. - */ - boolean canStoreConstant(Constant c); - RegisterAttributes attributes(Register register); /** diff -r d6e4c9031ff6 -r 3b6759c384a9 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ConstantNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ConstantNode.java Thu Oct 02 10:36:12 2014 +0200 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ConstantNode.java Thu Oct 02 10:48:17 2014 +0200 @@ -91,10 +91,10 @@ @Override public void generate(NodeLIRBuilderTool gen) { - if (gen.getLIRGeneratorTool().canInlineConstant(value) || onlyUsedInVirtualState()) { + if (onlyUsedInVirtualState()) { gen.setResult(this, value); } else { - gen.setResult(this, gen.getLIRGeneratorTool().emitMove(value)); + gen.setResult(this, gen.getLIRGeneratorTool().emitLoadConstant(value)); } }