comparison graal/com.oracle.max.cri/src/com/oracle/max/cri/xir/CiXirAssembler.java @ 5540:a891c53a295b

Renaming RiKind => Kind.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 08 Jun 2012 23:47:42 +0200
parents bc647d8b0080
children b6617d13ea44
comparison
equal deleted inserted replaced
5539:bc647d8b0080 5540:a891c53a295b
151 * Operands for {@link XirInstruction instructions}. 151 * Operands for {@link XirInstruction instructions}.
152 * There are three basic variants, {@link XirConstant constant}, {@link XirParameter parameter} and {@link XirTemp}. 152 * There are three basic variants, {@link XirConstant constant}, {@link XirParameter parameter} and {@link XirTemp}.
153 */ 153 */
154 public abstract static class XirOperand { 154 public abstract static class XirOperand {
155 155
156 public final RiKind kind; 156 public final Kind kind;
157 157
158 /** 158 /**
159 * Unique id in range {@code 0} to {@link #variableCount variableCount - 1}. 159 * Unique id in range {@code 0} to {@link #variableCount variableCount - 1}.
160 */ 160 */
161 public final int index; 161 public final int index;
163 /** 163 /**
164 * Value whose {@link #toString()} method provides a name for this operand. 164 * Value whose {@link #toString()} method provides a name for this operand.
165 */ 165 */
166 public final Object name; 166 public final Object name;
167 167
168 public XirOperand(CiXirAssembler asm, Object name, RiKind kind) { 168 public XirOperand(CiXirAssembler asm, Object name, Kind kind) {
169 this.kind = kind; 169 this.kind = kind;
170 this.name = name; 170 this.name = name;
171 this.index = asm.variableCount++; 171 this.index = asm.variableCount++;
172 } 172 }
173 173
196 */ 196 */
197 public final int parameterIndex; 197 public final int parameterIndex;
198 198
199 public final boolean canBeConstant; 199 public final boolean canBeConstant;
200 200
201 XirParameter(CiXirAssembler asm, String name, RiKind kind, boolean canBeConstant) { 201 XirParameter(CiXirAssembler asm, String name, Kind kind, boolean canBeConstant) {
202 super(asm, name, kind); 202 super(asm, name, kind);
203 this.parameterIndex = asm.parameters.size(); 203 this.parameterIndex = asm.parameters.size();
204 this.canBeConstant = canBeConstant; 204 this.canBeConstant = canBeConstant;
205 asm.parameters.add(this); 205 asm.parameters.add(this);
206 } 206 }
207 207
208 } 208 }
209 209
210 public static class XirConstantParameter extends XirParameter implements XirConstantOperand { 210 public static class XirConstantParameter extends XirParameter implements XirConstantOperand {
211 XirConstantParameter(CiXirAssembler asm, String name, RiKind kind) { 211 XirConstantParameter(CiXirAssembler asm, String name, Kind kind) {
212 super(asm, name, kind, true); 212 super(asm, name, kind, true);
213 } 213 }
214 214
215 public int getIndex() { 215 public int getIndex() {
216 return index; 216 return index;
217 } 217 }
218 } 218 }
219 219
220 public static class XirVariableParameter extends XirParameter { 220 public static class XirVariableParameter extends XirParameter {
221 XirVariableParameter(CiXirAssembler asm, String name, RiKind kind, boolean canBeConstant) { 221 XirVariableParameter(CiXirAssembler asm, String name, Kind kind, boolean canBeConstant) {
222 super(asm, name, kind, canBeConstant); 222 super(asm, name, kind, canBeConstant);
223 } 223 }
224 } 224 }
225 225
226 public static class XirConstant extends XirOperand implements XirConstantOperand { 226 public static class XirConstant extends XirOperand implements XirConstantOperand {
237 } 237 }
238 238
239 public static class XirTemp extends XirOperand { 239 public static class XirTemp extends XirOperand {
240 public final boolean reserve; 240 public final boolean reserve;
241 241
242 XirTemp(CiXirAssembler asm, String name, RiKind kind, boolean reserve) { 242 XirTemp(CiXirAssembler asm, String name, Kind kind, boolean reserve) {
243 super(asm, name, kind); 243 super(asm, name, kind);
244 this.reserve = reserve; 244 this.reserve = reserve;
245 } 245 }
246 } 246 }
247 247
265 /** 265 /**
266 * Start a new assembly with a {@link #resultOperand result operand} of type {@code kind}. 266 * Start a new assembly with a {@link #resultOperand result operand} of type {@code kind}.
267 * @param kind the result kind 267 * @param kind the result kind
268 * @return an {@code XirOperand} for the result operand 268 * @return an {@code XirOperand} for the result operand
269 */ 269 */
270 public XirOperand restart(RiKind kind) { 270 public XirOperand restart(Kind kind) {
271 reset(); 271 reset();
272 resultOperand = new XirTemp(this, "result", kind, true); 272 resultOperand = new XirTemp(this, "result", kind, true);
273 allocateResultOperand = true; 273 allocateResultOperand = true;
274 return resultOperand; 274 return resultOperand;
275 } 275 }
290 marks.clear(); 290 marks.clear();
291 outgoingStackSize = 0; 291 outgoingStackSize = 0;
292 } 292 }
293 293
294 /** 294 /**
295 * Represents an XIR instruction, characterized by an {@link XirOp operation}, a {@link RiKind kind}, an optional {@link XirOperand result}, a variable number of {@link XirOperand arguments}, 295 * Represents an XIR instruction, characterized by an {@link XirOp operation}, a {@link Kind kind}, an optional {@link XirOperand result}, a variable number of {@link XirOperand arguments},
296 * and some optional instruction-specific state. The {@link #x}, {@link #y} and {@link #z} methods are convenient ways to access the first, second and third 296 * and some optional instruction-specific state. The {@link #x}, {@link #y} and {@link #z} methods are convenient ways to access the first, second and third
297 * arguments, respectively. Only the {@link XirOp#CallStub} and {@link XirOp#CallRuntime} instructions can have more than three arguments. 297 * arguments, respectively. Only the {@link XirOp#CallStub} and {@link XirOp#CallRuntime} instructions can have more than three arguments.
298 * 298 *
299 */ 299 */
300 public static final class XirInstruction { 300 public static final class XirInstruction {
301 /** 301 /**
302 * The {@link RiKind kind} of values the instruction operates on. 302 * The {@link Kind kind} of values the instruction operates on.
303 */ 303 */
304 public final RiKind kind; 304 public final Kind kind;
305 /** 305 /**
306 * The {@link XirOp operation}. 306 * The {@link XirOp operation}.
307 */ 307 */
308 public final XirOp op; 308 public final XirOp op;
309 /** 309 /**
317 /** 317 /**
318 * Arbitrary additional data associated with the instruction. 318 * Arbitrary additional data associated with the instruction.
319 */ 319 */
320 public final Object extra; 320 public final Object extra;
321 321
322 public XirInstruction(RiKind kind, XirOp op, XirOperand result, XirOperand... arguments) { 322 public XirInstruction(Kind kind, XirOp op, XirOperand result, XirOperand... arguments) {
323 this(kind, null, op, result, arguments); 323 this(kind, null, op, result, arguments);
324 } 324 }
325 325
326 public XirInstruction(RiKind kind, Object extra, XirOp op, XirOperand result, XirOperand... arguments) { 326 public XirInstruction(Kind kind, Object extra, XirOp op, XirOperand result, XirOperand... arguments) {
327 this.extra = extra; 327 this.extra = extra;
328 this.kind = kind; 328 this.kind = kind;
329 this.op = op; 329 this.op = op;
330 this.result = result; 330 this.result = result;
331 this.arguments = arguments; 331 this.arguments = arguments;
355 sb.append(" = "); 355 sb.append(" = ");
356 } 356 }
357 357
358 sb.append(op.name()); 358 sb.append(op.name());
359 359
360 if (kind != RiKind.Void) { 360 if (kind != Kind.Void) {
361 sb.append('$'); 361 sb.append('$');
362 sb.append(kind.typeChar); 362 sb.append(kind.typeChar);
363 } 363 }
364 364
365 if (arguments != null && arguments.length > 0) { 365 if (arguments != null && arguments.length > 0) {
638 public void xor(XirOperand result, XirOperand a, XirOperand b) { 638 public void xor(XirOperand result, XirOperand a, XirOperand b) {
639 append(new XirInstruction(result.kind, Xor, result, a, b)); 639 append(new XirInstruction(result.kind, Xor, result, a, b));
640 } 640 }
641 641
642 public void nullCheck(XirOperand pointer) { 642 public void nullCheck(XirOperand pointer) {
643 append(new XirInstruction(RiKind.Object, NullCheck, VOID, pointer)); 643 append(new XirInstruction(Kind.Object, NullCheck, VOID, pointer));
644 } 644 }
645 645
646 public void pload(RiKind kind, XirOperand result, XirOperand pointer, boolean canTrap) { 646 public void pload(Kind kind, XirOperand result, XirOperand pointer, boolean canTrap) {
647 append(new XirInstruction(kind, canTrap, PointerLoad, result, pointer)); 647 append(new XirInstruction(kind, canTrap, PointerLoad, result, pointer));
648 } 648 }
649 649
650 public void pstore(RiKind kind, XirOperand pointer, XirOperand value, boolean canTrap) { 650 public void pstore(Kind kind, XirOperand pointer, XirOperand value, boolean canTrap) {
651 append(new XirInstruction(kind, canTrap, PointerStore, null, pointer, value)); 651 append(new XirInstruction(kind, canTrap, PointerStore, null, pointer, value));
652 } 652 }
653 653
654 public void pload(RiKind kind, XirOperand result, XirOperand pointer, XirOperand offset, boolean canTrap) { 654 public void pload(Kind kind, XirOperand result, XirOperand pointer, XirOperand offset, boolean canTrap) {
655 append(new XirInstruction(kind, new AddressAccessInformation(canTrap), PointerLoadDisp, result, pointer, offset)); 655 append(new XirInstruction(kind, new AddressAccessInformation(canTrap), PointerLoadDisp, result, pointer, offset));
656 } 656 }
657 657
658 public void pstore(RiKind kind, XirOperand pointer, XirOperand offset, XirOperand value, boolean canTrap) { 658 public void pstore(Kind kind, XirOperand pointer, XirOperand offset, XirOperand value, boolean canTrap) {
659 append(new XirInstruction(kind, new AddressAccessInformation(canTrap), PointerStoreDisp, VOID, pointer, offset, value)); 659 append(new XirInstruction(kind, new AddressAccessInformation(canTrap), PointerStoreDisp, VOID, pointer, offset, value));
660 } 660 }
661 661
662 public void pload(RiKind kind, XirOperand result, XirOperand pointer, XirOperand index, int disp, Scale scale, boolean canTrap) { 662 public void pload(Kind kind, XirOperand result, XirOperand pointer, XirOperand index, int disp, Scale scale, boolean canTrap) {
663 append(new XirInstruction(kind, new AddressAccessInformation(canTrap, disp, scale), PointerLoadDisp, result, pointer, index)); 663 append(new XirInstruction(kind, new AddressAccessInformation(canTrap, disp, scale), PointerLoadDisp, result, pointer, index));
664 } 664 }
665 665
666 public void lea(XirOperand result, XirOperand pointer, XirOperand index, int disp, Scale scale) { 666 public void lea(XirOperand result, XirOperand pointer, XirOperand index, int disp, Scale scale) {
667 append(new XirInstruction(target.wordKind, new AddressAccessInformation(false, disp, scale), LoadEffectiveAddress, result, pointer, index)); 667 append(new XirInstruction(target.wordKind, new AddressAccessInformation(false, disp, scale), LoadEffectiveAddress, result, pointer, index));
677 677
678 public void repmovb(XirOperand src, XirOperand dest, XirOperand length) { 678 public void repmovb(XirOperand src, XirOperand dest, XirOperand length) {
679 append(new XirInstruction(target.wordKind, null, RepeatMoveBytes, null, src, dest, length)); 679 append(new XirInstruction(target.wordKind, null, RepeatMoveBytes, null, src, dest, length));
680 } 680 }
681 681
682 public void pstore(RiKind kind, XirOperand pointer, XirOperand index, XirOperand value, int disp, Scale scale, boolean canTrap) { 682 public void pstore(Kind kind, XirOperand pointer, XirOperand index, XirOperand value, int disp, Scale scale, boolean canTrap) {
683 append(new XirInstruction(kind, new AddressAccessInformation(canTrap, disp, scale), PointerStoreDisp, VOID, pointer, index, value)); 683 append(new XirInstruction(kind, new AddressAccessInformation(canTrap, disp, scale), PointerStoreDisp, VOID, pointer, index, value));
684 } 684 }
685 685
686 public void pcas(RiKind kind, XirOperand result, XirOperand pointer, XirOperand newValue, XirOperand oldValue) { 686 public void pcas(Kind kind, XirOperand result, XirOperand pointer, XirOperand newValue, XirOperand oldValue) {
687 append(new XirInstruction(kind, null, PointerCAS, result, pointer, newValue, oldValue)); 687 append(new XirInstruction(kind, null, PointerCAS, result, pointer, newValue, oldValue));
688 } 688 }
689 689
690 public void jmp(XirLabel l) { 690 public void jmp(XirLabel l) {
691 append(new XirInstruction(RiKind.Void, l, Jmp, null)); 691 append(new XirInstruction(Kind.Void, l, Jmp, null));
692 } 692 }
693 693
694 public void decAndJumpNotZero(XirLabel l, XirOperand val) { 694 public void decAndJumpNotZero(XirLabel l, XirOperand val) {
695 append(new XirInstruction(RiKind.Void, l, DecAndJumpNotZero, null, val)); 695 append(new XirInstruction(Kind.Void, l, DecAndJumpNotZero, null, val));
696 } 696 }
697 697
698 public void jmpRuntime(Object rt) { 698 public void jmpRuntime(Object rt) {
699 append(new XirInstruction(RiKind.Void, rt, Jmp, null)); 699 append(new XirInstruction(Kind.Void, rt, Jmp, null));
700 } 700 }
701 701
702 public void jeq(XirLabel l, XirOperand a, XirOperand b) { 702 public void jeq(XirLabel l, XirOperand a, XirOperand b) {
703 jcc(Jeq, l, a, b); 703 jcc(Jeq, l, a, b);
704 } 704 }
705 705
706 private void jcc(XirOp op, XirLabel l, XirOperand a, XirOperand b) { 706 private void jcc(XirOp op, XirLabel l, XirOperand a, XirOperand b) {
707 append(new XirInstruction(RiKind.Void, l, op, null, a, b)); 707 append(new XirInstruction(Kind.Void, l, op, null, a, b));
708 } 708 }
709 709
710 public void jneq(XirLabel l, XirOperand a, XirOperand b) { 710 public void jneq(XirLabel l, XirOperand a, XirOperand b) {
711 jcc(Jneq, l, a, b); 711 jcc(Jneq, l, a, b);
712 } 712 }
730 public void jlteq(XirLabel l, XirOperand a, XirOperand b) { 730 public void jlteq(XirLabel l, XirOperand a, XirOperand b) {
731 jcc(Jlteq, l, a, b); 731 jcc(Jlteq, l, a, b);
732 } 732 }
733 733
734 public void jbset(XirLabel l, XirOperand a, XirOperand b, XirOperand c) { 734 public void jbset(XirLabel l, XirOperand a, XirOperand b, XirOperand c) {
735 append(new XirInstruction(RiKind.Void, l, Jbset, null, a, b, c)); 735 append(new XirInstruction(Kind.Void, l, Jbset, null, a, b, c));
736 } 736 }
737 737
738 public void bindInline(XirLabel l) { 738 public void bindInline(XirLabel l) {
739 assert l.inline; 739 assert l.inline;
740 append(new XirInstruction(RiKind.Void, l, Bind, null)); 740 append(new XirInstruction(Kind.Void, l, Bind, null));
741 } 741 }
742 742
743 public void bindOutOfLine(XirLabel l) { 743 public void bindOutOfLine(XirLabel l) {
744 assert !l.inline; 744 assert !l.inline;
745 append(new XirInstruction(RiKind.Void, l, Bind, null)); 745 append(new XirInstruction(Kind.Void, l, Bind, null));
746 } 746 }
747 747
748 public void safepoint() { 748 public void safepoint() {
749 append(new XirInstruction(RiKind.Void, null, Safepoint, null)); 749 append(new XirInstruction(Kind.Void, null, Safepoint, null));
750 } 750 }
751 751
752 public void push(XirOperand value) { 752 public void push(XirOperand value) {
753 append(new XirInstruction(RiKind.Void, Push, VOID, value)); 753 append(new XirInstruction(Kind.Void, Push, VOID, value));
754 } 754 }
755 755
756 public void pop(XirOperand result) { 756 public void pop(XirOperand result) {
757 append(new XirInstruction(result.kind, Pop, result)); 757 append(new XirInstruction(result.kind, Pop, result));
758 } 758 }
759 759
760 public XirMark mark(Object id, XirMark... references) { 760 public XirMark mark(Object id, XirMark... references) {
761 XirMark mark = new XirMark(id, references); 761 XirMark mark = new XirMark(id, references);
762 marks.add(mark); 762 marks.add(mark);
763 append(new XirInstruction(RiKind.Void, mark, Mark, null)); 763 append(new XirInstruction(Kind.Void, mark, Mark, null));
764 return mark; 764 return mark;
765 } 765 }
766 766
767 public void nop(int size) { 767 public void nop(int size) {
768 append(new XirInstruction(RiKind.Void, size, Nop, null)); 768 append(new XirInstruction(Kind.Void, size, Nop, null));
769 } 769 }
770 770
771 public void shouldNotReachHere() { 771 public void shouldNotReachHere() {
772 append(new XirInstruction(RiKind.Void, null, ShouldNotReachHere, null)); 772 append(new XirInstruction(Kind.Void, null, ShouldNotReachHere, null));
773 } 773 }
774 774
775 public void shouldNotReachHere(String message) { 775 public void shouldNotReachHere(String message) {
776 append(new XirInstruction(RiKind.Void, message, ShouldNotReachHere, null)); 776 append(new XirInstruction(Kind.Void, message, ShouldNotReachHere, null));
777 } 777 }
778 778
779 public void callRuntime(Object rt, XirOperand result, XirOperand... args) { 779 public void callRuntime(Object rt, XirOperand result, XirOperand... args) {
780 callRuntime(rt, result, false, args); 780 callRuntime(rt, result, false, args);
781 } 781 }
782 782
783 public void callRuntime(Object rt, XirOperand result, boolean useInfoAfter, XirOperand... args) { 783 public void callRuntime(Object rt, XirOperand result, boolean useInfoAfter, XirOperand... args) {
784 RiKind resultKind = result == null ? RiKind.Void : result.kind; 784 Kind resultKind = result == null ? Kind.Void : result.kind;
785 append(new XirInstruction(resultKind, new RuntimeCallInformation(rt, useInfoAfter), CallRuntime, result, args)); 785 append(new XirInstruction(resultKind, new RuntimeCallInformation(rt, useInfoAfter), CallRuntime, result, args));
786 } 786 }
787 787
788 /** 788 /**
789 * Terminates the assembly, checking invariants, in particular that {@link resultOperand} is set, and setting {@link #finished} to {@code true}. 789 * Terminates the assembly, checking invariants, in particular that {@link resultOperand} is set, and setting {@link #finished} to {@code true}.
793 assert resultOperand != null : "result operand should be set"; 793 assert resultOperand != null : "result operand should be set";
794 finished = true; 794 finished = true;
795 } 795 }
796 796
797 /** 797 /**
798 * Creates an {@link XirVariableParameter variable input parameter} of given name and {@link RiKind kind}. 798 * Creates an {@link XirVariableParameter variable input parameter} of given name and {@link Kind kind}.
799 * @param name a name for the parameter 799 * @param name a name for the parameter
800 * @param kind the parameter kind 800 * @param kind the parameter kind
801 * @return the {@link XirVariableParameter} 801 * @return the {@link XirVariableParameter}
802 */ 802 */
803 public XirVariableParameter createInputParameter(String name, RiKind kind, boolean canBeConstant) { 803 public XirVariableParameter createInputParameter(String name, Kind kind, boolean canBeConstant) {
804 assert !finished; 804 assert !finished;
805 return new XirVariableParameter(this, name, kind, canBeConstant); 805 return new XirVariableParameter(this, name, kind, canBeConstant);
806 } 806 }
807 807
808 public XirVariableParameter createInputParameter(String name, RiKind kind) { 808 public XirVariableParameter createInputParameter(String name, Kind kind) {
809 return createInputParameter(name, kind, false); 809 return createInputParameter(name, kind, false);
810 } 810 }
811 811
812 /** 812 /**
813 * Creates an {@link XirConstantParameter constant input parameter} of given name and {@link RiKind kind}. 813 * Creates an {@link XirConstantParameter constant input parameter} of given name and {@link Kind kind}.
814 * @param name a name for the parameter 814 * @param name a name for the parameter
815 * @param kind the parameter kind 815 * @param kind the parameter kind
816 * @return the {@link XirConstantParameter} 816 * @return the {@link XirConstantParameter}
817 */ 817 */
818 public XirConstantParameter createConstantInputParameter(String name, RiKind kind) { 818 public XirConstantParameter createConstantInputParameter(String name, Kind kind) {
819 assert !finished; 819 assert !finished;
820 return new XirConstantParameter(this, name, kind); 820 return new XirConstantParameter(this, name, kind);
821 } 821 }
822 822
823 public XirConstant createConstant(Constant constant) { 823 public XirConstant createConstant(Constant constant) {
825 XirConstant temp = new XirConstant(this, constant); 825 XirConstant temp = new XirConstant(this, constant);
826 constants.add(temp); 826 constants.add(temp);
827 return temp; 827 return temp;
828 } 828 }
829 829
830 public XirOperand createTemp(String name, RiKind kind) { 830 public XirOperand createTemp(String name, Kind kind) {
831 assert !finished; 831 assert !finished;
832 XirTemp temp = new XirTemp(this, name, kind, true); 832 XirTemp temp = new XirTemp(this, name, kind, true);
833 temps.add(temp); 833 temps.add(temp);
834 return temp; 834 return temp;
835 } 835 }
836 836
837 public XirOperand createRegister(String name, RiKind kind, CiRegister register) { 837 public XirOperand createRegister(String name, Kind kind, CiRegister register) {
838 return createRegister(name, kind, register, false); 838 return createRegister(name, kind, register, false);
839 } 839 }
840 840
841 public XirOperand createRegisterTemp(String name, RiKind kind, CiRegister register) { 841 public XirOperand createRegisterTemp(String name, Kind kind, CiRegister register) {
842 return createRegister(name, kind, register, true); 842 return createRegister(name, kind, register, true);
843 } 843 }
844 844
845 private XirOperand createRegister(String name, RiKind kind, CiRegister register, boolean reserve) { 845 private XirOperand createRegister(String name, Kind kind, CiRegister register, boolean reserve) {
846 assert !finished; 846 assert !finished;
847 XirRegister fixed = new XirRegister(this, name, register.asValue(kind), reserve); 847 XirRegister fixed = new XirRegister(this, name, register.asValue(kind), reserve);
848 temps.add(fixed); 848 temps.add(fixed);
849 return fixed; 849 return fixed;
850 } 850 }