1 /*
   2  * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.hotspot.amd64;
  24 
  25 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
  26 import static jdk.vm.ci.code.ValueUtil.asRegister;
  27 
  28 import jdk.vm.ci.amd64.AMD64Kind;
  29 import jdk.vm.ci.code.Register;
  30 import jdk.vm.ci.meta.AllocatableValue;
  31 
  32 import org.graalvm.compiler.asm.amd64.AMD64Address;
  33 import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler;
  34 import org.graalvm.compiler.debug.GraalError;
  35 import org.graalvm.compiler.lir.LIRInstructionClass;
  36 import org.graalvm.compiler.lir.amd64.AMD64LIRInstruction;
  37 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
  38 
  39 public final class AMD64HotSpotLoadConfigValueOp extends AMD64LIRInstruction {
  40 
  41     public static final LIRInstructionClass<AMD64HotSpotLoadConfigValueOp> TYPE = LIRInstructionClass.create(AMD64HotSpotLoadConfigValueOp.class);
  42 
  43     @Def({OperandFlag.REG}) protected AllocatableValue result;
  44     private final int markId;
  45 
  46     public AMD64HotSpotLoadConfigValueOp(int markId, AllocatableValue result) {
  47         super(TYPE);
  48         this.result = result;
  49         this.markId = markId;
  50     }
  51 
  52     @Override
  53     public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
  54         if (GeneratePIC.getValue(crb.getOptions())) {
  55             AMD64Kind kind = (AMD64Kind) result.getPlatformKind();
  56             Register reg = asRegister(result);
  57             AMD64Address placeholder = masm.getPlaceholder(-1);
  58             switch (kind) {
  59                 case BYTE:
  60                     masm.movsbl(reg, placeholder);
  61                     break;
  62                 case WORD:
  63                     masm.movswl(reg, placeholder);
  64                     break;
  65                 case DWORD:
  66                     masm.movl(reg, placeholder);
  67                     break;
  68                 case QWORD:
  69                     masm.movq(reg, placeholder);
  70                     break;
  71                 default:
  72                     throw GraalError.unimplemented();
  73             }
  74         } else {
  75             throw GraalError.unimplemented();
  76         }
  77         crb.recordMark(markId);
  78     }
  79 
  80 }