001/*
002 * Copyright (c) 2014, 2014, 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 com.oracle.graal.hotspot.amd64;
024
025import static jdk.internal.jvmci.amd64.AMD64.*;
026import jdk.internal.jvmci.code.*;
027import jdk.internal.jvmci.hotspot.*;
028import jdk.internal.jvmci.meta.*;
029
030import com.oracle.graal.compiler.gen.*;
031import com.oracle.graal.lir.gen.*;
032
033public class AMD64HotSpotBytecodeLIRBuilder extends BytecodeLIRBuilder {
034
035    public AMD64HotSpotBytecodeLIRBuilder(LIRGeneratorTool gen, BytecodeParserTool parser) {
036        super(gen, parser);
037    }
038
039    private AMD64HotSpotLIRGenerator getGen() {
040        return (AMD64HotSpotLIRGenerator) gen;
041    }
042
043    @Override
044    public void emitPrologue(ResolvedJavaMethod method) {
045        CallingConvention incomingArguments = gen.getCallingConvention();
046
047        Value[] params = new Value[incomingArguments.getArgumentCount() + 1];
048        for (int i = 0; i < params.length - 1; i++) {
049            params[i] = LIRGenerator.toStackKind(incomingArguments.getArgument(i));
050            if (ValueUtil.isStackSlot(params[i])) {
051                StackSlot slot = ValueUtil.asStackSlot(params[i]);
052                if (slot.isInCallerFrame() && !gen.getResult().getLIR().hasArgInCallerFrame()) {
053                    gen.getResult().getLIR().setHasArgInCallerFrame();
054                }
055            }
056        }
057        params[params.length - 1] = rbp.asValue(LIRKind.value(Kind.Long));
058
059        gen.emitIncomingValues(params);
060
061        getGen().emitSaveRbp();
062
063        Signature sig = method.getSignature();
064        boolean isStatic = method.isStatic();
065        for (int i = 0; i < sig.getParameterCount(!isStatic); i++) {
066            Value paramValue = params[i];
067            assert paramValue.getKind() == sig.getParameterKind(i).getStackKind();
068            parser.storeLocal(i, gen.emitMove(paramValue));
069        }
070    }
071
072    @Override
073    public int getArrayLengthOffset() {
074        return getGen().config.arrayLengthOffset;
075    }
076
077    @Override
078    public JavaConstant getClassConstant(ResolvedJavaType declaringClass) {
079        return declaringClass.getJavaClass();
080    }
081
082    @Override
083    public int getFieldOffset(ResolvedJavaField field) {
084        return ((HotSpotResolvedJavaField) field).offset();
085    }
086
087}