Mercurial > hg > graal-jvmci-8
diff graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiRegisterConfig.java @ 5506:56860d3f9f39
More refactorings and renamings in preparation of ci/ri split.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Thu, 07 Jun 2012 18:12:01 +0200 |
parents | graal/com.oracle.max.cri/src/com/oracle/max/cri/ri/RiRegisterConfig.java@438ab53efdd0 |
children | dc71b06d09f8 |
line wrap: on
line diff
--- a/graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiRegisterConfig.java Thu Jun 07 17:25:52 2012 +0200 +++ b/graal/com.oracle.max.cri/src/com/oracle/max/cri/ci/CiRegisterConfig.java Thu Jun 07 18:12:01 2012 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2011, 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 @@ -29,270 +29,85 @@ import com.oracle.max.cri.ri.*; /** - * A default implementation of {@link RiRegisterConfig}. + * A register configuration binds roles and {@linkplain CiRegisterAttributes attributes} + * to physical registers. */ -public class CiRegisterConfig implements RiRegisterConfig { - - /** - * The object describing the callee save area of this register configuration. - */ - public CiCalleeSaveLayout csl; - - /** - * The minimum register role identifier. - */ - public final int minRole; +public interface CiRegisterConfig { /** - * The map from register role IDs to registers. + * Gets the register to be used for returning a value of a given kind. */ - public final CiRegister[] registersRoleMap; + CiRegister getReturnRegister(RiKind kind); /** - * The set of registers that can be used by the register allocator. + * Gets the register to which {@link CiRegister#Frame} and {@link CiRegister#CallerFrame} are bound. */ - public final CiRegister[] allocatable; + CiRegister getFrameRegister(); - /** - * The set of registers that can be used by the register allocator, - * {@linkplain CiRegister#categorize(CiRegister[]) categorized} by register - * {@linkplain RegisterFlag flags}. - */ - public final EnumMap<RegisterFlag, CiRegister[]> categorized; + CiRegister getScratchRegister(); /** - * The ordered set of registers used to pass integral arguments. - */ - public final CiRegister[] cpuParameters; - - /** - * The ordered set of registers used to pass floating point arguments. + * Gets the calling convention describing how arguments are passed. + * + * @param type the type of calling convention being requested + * @param parameters the types of the arguments of the call + * @param target the target platform + * @param stackOnly ignore registers */ - public final CiRegister[] fpuParameters; - - /** - * The caller saved registers. - */ - public final CiRegister[] callerSave; - - /** - * The register to which {@link CiRegister#Frame} and {@link CiRegister#CallerFrame} are bound. - */ - public final CiRegister frame; + CiCallingConvention getCallingConvention(Type type, RiKind[] parameters, CiTarget target, boolean stackOnly); /** - * Register for returning an integral value. - */ - public final CiRegister integralReturn; - - /** - * Register for returning a floating point value. + * Gets the ordered set of registers that are can be used to pass parameters + * according to a given calling convention. + * + * @param type the type of calling convention + * @param flag specifies whether registers for {@linkplain RegisterFlag#CPU integral} or + * {@linkplain} RegisterFlag#FPU floating point} parameters are being requested + * @return the ordered set of registers that may be used to pass parameters in a call conforming to {@code type} */ - public final CiRegister floatingPointReturn; - - /** - * The map from register {@linkplain CiRegister#number numbers} to register - * {@linkplain RiRegisterAttributes attributes} for this register configuration. - */ - public final RiRegisterAttributes[] attributesMap; - - /** - * The scratch register. - */ - public final CiRegister scratch; + CiRegister[] getCallingConventionRegisters(Type type, RegisterFlag flag); /** - * The frame offset of the first stack argument for each calling convention {@link CiCallingConvention.Type}. + * Gets the set of registers that can be used by the register allocator. */ - public final int[] stackArg0Offsets = new int[CiCallingConvention.Type.VALUES.length]; + CiRegister[] getAllocatableRegisters(); - public CiRegisterConfig( - CiRegister frame, - CiRegister integralReturn, - CiRegister floatingPointReturn, - CiRegister scratch, - CiRegister[] allocatable, - CiRegister[] callerSave, - CiRegister[] parameters, - CiCalleeSaveLayout csl, - CiRegister[] allRegisters, - Map<Integer, CiRegister> roles) { - this.frame = frame; - this.csl = csl; - this.allocatable = allocatable; - this.callerSave = callerSave; - assert !Arrays.asList(allocatable).contains(scratch); - this.scratch = scratch; - EnumMap<RegisterFlag, CiRegister[]> categorizedParameters = CiRegister.categorize(parameters); - this.cpuParameters = categorizedParameters.get(RegisterFlag.CPU); - this.fpuParameters = categorizedParameters.get(RegisterFlag.FPU); - categorized = CiRegister.categorize(allocatable); - attributesMap = RiRegisterAttributes.createMap(this, allRegisters); - this.floatingPointReturn = floatingPointReturn; - this.integralReturn = integralReturn; - int minRoleId = Integer.MAX_VALUE; - int maxRoleId = Integer.MIN_VALUE; - for (Map.Entry<Integer, CiRegister> e : roles.entrySet()) { - int id = e.getKey(); - assert id >= 0; - if (minRoleId > id) { - minRoleId = id; - } - if (maxRoleId < id) { - maxRoleId = id; - } - } - registersRoleMap = new CiRegister[(maxRoleId - minRoleId) + 1]; - for (Map.Entry<Integer, CiRegister> e : roles.entrySet()) { - int id = e.getKey(); - registersRoleMap[id] = e.getValue(); - } - minRole = minRoleId; - } + /** + * Gets the set of registers that can be used by the register allocator, + * {@linkplain CiRegister#categorize(CiRegister[]) categorized} by register {@linkplain RegisterFlag flags}. + * + * @return a map from each {@link RegisterFlag} constant to the list of {@linkplain #getAllocatableRegisters() + * allocatable} registers for which the flag is {@linkplain #isSet(RegisterFlag) set} + * + */ + EnumMap<RegisterFlag, CiRegister[]> getCategorizedAllocatableRegisters(); - public CiRegisterConfig(CiRegisterConfig src, CiCalleeSaveLayout csl) { - this.frame = src.frame; - this.csl = csl; - this.allocatable = src.allocatable; - this.callerSave = src.callerSave; - this.scratch = src.scratch; - this.cpuParameters = src.cpuParameters; - this.fpuParameters = src.fpuParameters; - this.categorized = src.categorized; - this.attributesMap = src.attributesMap; - this.floatingPointReturn = src.floatingPointReturn; - this.integralReturn = src.integralReturn; - this.registersRoleMap = src.registersRoleMap; - this.minRole = src.minRole; - System.arraycopy(src.stackArg0Offsets, 0, stackArg0Offsets, 0, stackArg0Offsets.length); - } - - public CiRegister getReturnRegister(RiKind kind) { - if (kind.isDouble() || kind.isFloat()) { - return floatingPointReturn; - } - return integralReturn; - } - - public CiRegister getFrameRegister() { - return frame; - } - - public CiRegister getScratchRegister() { - return scratch; - } + /** + * Gets the registers whose values must be preserved by a method across any call it makes. + */ + CiRegister[] getCallerSaveRegisters(); /** - * {@inheritDoc} + * Gets the layout of the callee save area of this register configuration. * - * This implementation assigns all available registers to parameters before assigning - * any stack slots to parameters. + * @return {@code null} if there is no callee save area */ - public CiCallingConvention getCallingConvention(Type type, RiKind[] parameters, CiTarget target, boolean stackOnly) { - CiValue[] locations = new CiValue[parameters.length]; - - int currentGeneral = 0; - int currentXMM = 0; - int currentStackOffset = stackArg0Offsets[type.ordinal()]; - - for (int i = 0; i < parameters.length; i++) { - final RiKind kind = parameters[i]; - - switch (kind) { - case Byte: - case Boolean: - case Short: - case Char: - case Int: - case Long: - case Object: - if (!stackOnly && currentGeneral < cpuParameters.length) { - CiRegister register = cpuParameters[currentGeneral++]; - locations[i] = register.asValue(kind); - } - break; - - case Float: - case Double: - if (!stackOnly && currentXMM < fpuParameters.length) { - CiRegister register = fpuParameters[currentXMM++]; - locations[i] = register.asValue(kind); - } - break; - - default: - throw new InternalError("Unexpected parameter kind: " + kind); - } - - if (locations[i] == null) { - locations[i] = CiStackSlot.get(kind.stackKind(), currentStackOffset, !type.out); - currentStackOffset += Math.max(target.sizeInBytes(kind), target.wordSize); - } - } - - return new CiCallingConvention(locations, currentStackOffset); - } + CiCalleeSaveLayout getCalleeSaveLayout(); - public CiRegister[] getCallingConventionRegisters(Type type, RegisterFlag flag) { - if (flag == RegisterFlag.CPU) { - return cpuParameters; - } - assert flag == RegisterFlag.FPU; - return fpuParameters; - } - - public CiRegister[] getAllocatableRegisters() { - return allocatable; - } - - public EnumMap<RegisterFlag, CiRegister[]> getCategorizedAllocatableRegisters() { - return categorized; - } - - public CiRegister[] getCallerSaveRegisters() { - return callerSave; - } - - public CiCalleeSaveLayout getCalleeSaveLayout() { - return csl; - } - - public RiRegisterAttributes[] getAttributesMap() { - return attributesMap; - } - - public CiRegister getRegisterForRole(int id) { - return registersRoleMap[id - minRole]; - } + /** + * Gets a map from register {@linkplain CiRegister#number numbers} to register + * {@linkplain CiRegisterAttributes attributes} for this register configuration. + * + * @return an array where an element at index i holds the attributes of the register whose number is i + * @see CiRegister#categorize(CiRegister[]) + */ + CiRegisterAttributes[] getAttributesMap(); - @Override - public String toString() { - StringBuilder roleMap = new StringBuilder(); - for (int i = 0; i < registersRoleMap.length; ++i) { - CiRegister reg = registersRoleMap[i]; - if (reg != null) { - if (roleMap.length() != 0) { - roleMap.append(", "); - } - roleMap.append(i + minRole).append(" -> ").append(reg); - } - } - StringBuilder stackArg0OffsetsMap = new StringBuilder(); - for (Type t : Type.VALUES) { - if (stackArg0OffsetsMap.length() != 0) { - stackArg0OffsetsMap.append(", "); - } - stackArg0OffsetsMap.append(t).append(" -> ").append(stackArg0Offsets[t.ordinal()]); - } - String res = String.format( - "Allocatable: " + Arrays.toString(getAllocatableRegisters()) + "%n" + - "CallerSave: " + Arrays.toString(getCallerSaveRegisters()) + "%n" + - "CalleeSave: " + getCalleeSaveLayout() + "%n" + - "CPU Params: " + Arrays.toString(cpuParameters) + "%n" + - "FPU Params: " + Arrays.toString(fpuParameters) + "%n" + - "VMRoles: " + roleMap + "%n" + - "stackArg0: " + stackArg0OffsetsMap + "%n" + - "Scratch: " + getScratchRegister() + "%n"); - return res; - } + /** + * Gets the register corresponding to a runtime-defined role. + * + * @param id the identifier of a runtime-defined register role + * @return the register playing the role specified by {@code id} + */ + CiRegister getRegisterForRole(int id); }