001/*
002 * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package jdk.internal.jvmci.code;
024
025import jdk.internal.jvmci.meta.*;
026import static jdk.internal.jvmci.meta.MetaUtil.*;
027
028/**
029 * Represents the target machine for a compiler, including the CPU architecture, the size of
030 * pointers and references, alignment of stacks, caches, etc.
031 */
032public class TargetDescription {
033
034    public final Architecture arch;
035
036    /**
037     * Specifies if this is a multi-processor system.
038     */
039    public final boolean isMP;
040
041    /**
042     * Specifies if this target supports encoding objects inline in the machine code.
043     */
044    public final boolean inlineObjects;
045
046    /**
047     * The machine word size on this target.
048     */
049    public final int wordSize;
050
051    /**
052     * The kind to be used for representing raw pointers and CPU registers.
053     */
054    public final Kind wordKind;
055
056    /**
057     * The stack alignment requirement of the platform. For example, from Appendix D of <a
058     * href="http://www.intel.com/Assets/PDF/manual/248966.pdf">Intel 64 and IA-32 Architectures
059     * Optimization Reference Manual</a>:
060     *
061     * <pre>
062     *     "It is important to ensure that the stack frame is aligned to a
063     *      16-byte boundary upon function entry to keep local __m128 data,
064     *      parameters, and XMM register spill locations aligned throughout
065     *      a function invocation."
066     * </pre>
067     */
068    public final int stackAlignment;
069
070    /**
071     * Maximum constant displacement at which a memory access can no longer be an implicit null
072     * check.
073     */
074    public final int implicitNullCheckLimit;
075
076    public TargetDescription(Architecture arch, boolean isMP, int stackAlignment, int implicitNullCheckLimit, boolean inlineObjects) {
077        this.arch = arch;
078        this.isMP = isMP;
079        this.wordSize = arch.getWordSize();
080        this.wordKind = Kind.fromWordSize(wordSize);
081        this.stackAlignment = stackAlignment;
082        this.implicitNullCheckLimit = implicitNullCheckLimit;
083        this.inlineObjects = inlineObjects;
084    }
085
086    @Override
087    public final int hashCode() {
088        throw new UnsupportedOperationException();
089    }
090
091    @Override
092    public final boolean equals(Object obj) {
093        if (this == obj) {
094            return true;
095        }
096        if (obj instanceof TargetDescription) {
097            TargetDescription that = (TargetDescription) obj;
098            // @formatter:off
099            if (this.implicitNullCheckLimit == that.implicitNullCheckLimit &&
100                this.inlineObjects == that.inlineObjects &&
101                this.isMP == that.isMP &&
102                this.stackAlignment == that.stackAlignment &&
103                this.wordKind.equals(that.wordKind) &&
104                this.wordSize == that.wordSize &&
105                this.arch.equals(that.arch)) {
106                return true;
107            }
108            // @formatter:on
109        }
110        return false;
111    }
112
113    @Override
114    public String toString() {
115        return identityHashCodeString(this);
116    }
117
118    public int getSizeInBytes(PlatformKind kind) {
119        return arch.getSizeInBytes(kind);
120    }
121
122    public LIRKind getLIRKind(Kind javaKind) {
123        switch (javaKind) {
124            case Boolean:
125            case Byte:
126            case Short:
127            case Char:
128            case Int:
129            case Long:
130            case Float:
131            case Double:
132                return LIRKind.value(javaKind);
133            case Object:
134                return LIRKind.reference(javaKind);
135            default:
136                return LIRKind.Illegal;
137        }
138    }
139}