001/*
002 * Copyright (c) 2013, 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 com.oracle.graal.lir.amd64;
024
025import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*;
026import static com.oracle.graal.lir.amd64.AMD64SaveRegistersOp.*;
027
028import java.util.*;
029
030import jdk.internal.jvmci.code.*;
031import jdk.internal.jvmci.meta.*;
032
033import com.oracle.graal.asm.amd64.*;
034import com.oracle.graal.lir.*;
035import com.oracle.graal.lir.StandardOp.SaveRegistersOp;
036import com.oracle.graal.lir.asm.*;
037import com.oracle.graal.lir.framemap.*;
038
039/**
040 * Writes well known garbage values to registers.
041 */
042@Opcode("ZAP_REGISTER")
043public final class AMD64ZapRegistersOp extends AMD64LIRInstruction implements SaveRegistersOp {
044    public static final LIRInstructionClass<AMD64ZapRegistersOp> TYPE = LIRInstructionClass.create(AMD64ZapRegistersOp.class);
045
046    /**
047     * The registers that are zapped.
048     */
049    protected final Register[] zappedRegisters;
050
051    /**
052     * The garbage values that are written to the registers.
053     */
054    @Use({CONST}) protected JavaConstant[] zapValues;
055
056    public AMD64ZapRegistersOp(Register[] zappedRegisters, JavaConstant[] zapValues) {
057        super(TYPE);
058        this.zappedRegisters = zappedRegisters;
059        this.zapValues = zapValues;
060    }
061
062    @Override
063    public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
064        for (int i = 0; i < zappedRegisters.length; i++) {
065            if (zappedRegisters[i] != null) {
066                RegisterValue registerValue = zappedRegisters[i].asValue(zapValues[i].getLIRKind());
067                AMD64Move.move(crb, masm, registerValue, zapValues[i]);
068            }
069        }
070    }
071
072    public boolean supportsRemove() {
073        return true;
074    }
075
076    public int remove(Set<Register> doNotSave) {
077        return prune(doNotSave, zappedRegisters);
078    }
079
080    public RegisterSaveLayout getMap(FrameMap frameMap) {
081        return new RegisterSaveLayout(new Register[0], new int[0]);
082    }
083}