1 /* 2 * Copyright (c) 2014, 2016, 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.lir.gen; 24 25 import org.graalvm.compiler.core.common.CompilationIdentifier; 26 import org.graalvm.compiler.core.common.CompilationIdentifier.Verbosity; 27 import org.graalvm.compiler.lir.LIR; 28 import org.graalvm.compiler.lir.framemap.FrameMap; 29 import org.graalvm.compiler.lir.framemap.FrameMapBuilder; 30 31 import jdk.vm.ci.code.CallingConvention; 32 33 public class LIRGenerationResult { 34 35 private final LIR lir; 36 private final FrameMapBuilder frameMapBuilder; 37 private FrameMap frameMap; 38 private final CallingConvention callingConvention; 39 /** 40 * Records whether the code being generated makes at least one foreign call. 41 */ 42 private boolean hasForeignCall; 43 /** 44 * Unique identifier of this compilation. 45 */ 46 private final CompilationIdentifier compilationId; 47 48 public LIRGenerationResult(CompilationIdentifier compilationId, LIR lir, FrameMapBuilder frameMapBuilder, CallingConvention callingConvention) { 49 this.lir = lir; 50 this.frameMapBuilder = frameMapBuilder; 51 this.callingConvention = callingConvention; 52 this.compilationId = compilationId; 53 } 54 55 /** 56 * Returns the incoming calling convention for the parameters of the method that is compiled. 57 */ 58 public CallingConvention getCallingConvention() { 59 return callingConvention; 60 } 61 62 /** 63 * Returns the {@link FrameMapBuilder} for collecting the information to build a 64 * {@link FrameMap}. 65 * 66 * This method can only be used prior calling {@link #buildFrameMap}. 67 */ 68 public final FrameMapBuilder getFrameMapBuilder() { 69 assert frameMap == null : "getFrameMapBuilder() can only be used before calling buildFrameMap()!"; 70 return frameMapBuilder; 71 } 72 73 /** 74 * Creates a {@link FrameMap} out of the {@link FrameMapBuilder}. This method should only be 75 * called once. After calling it, {@link #getFrameMapBuilder()} can no longer be used. 76 * 77 * @see FrameMapBuilder#buildFrameMap 78 */ 79 public void buildFrameMap() { 80 assert frameMap == null : "buildFrameMap() can only be called once!"; 81 frameMap = frameMapBuilder.buildFrameMap(this); 82 } 83 84 /** 85 * Returns the {@link FrameMap} associated with this {@link LIRGenerationResult}. 86 * 87 * This method can only be called after {@link #buildFrameMap}. 88 */ 89 public FrameMap getFrameMap() { 90 assert frameMap != null : "getFrameMap() can only be used after calling buildFrameMap()!"; 91 return frameMap; 92 } 93 94 public LIR getLIR() { 95 return lir; 96 } 97 98 /** 99 * Determines whether the code being generated makes at least one foreign call. 100 */ 101 public boolean hasForeignCall() { 102 return hasForeignCall; 103 } 104 105 public final void setForeignCall(boolean hasForeignCall) { 106 this.hasForeignCall = hasForeignCall; 107 } 108 109 public String getCompilationUnitName() { 110 if (compilationId == null || compilationId == CompilationIdentifier.INVALID_COMPILATION_ID) { 111 return "<unknown>"; 112 } 113 return compilationId.toString(Verbosity.NAME); 114 } 115 116 /** 117 * Returns a unique identifier of the current compilation. 118 */ 119 public CompilationIdentifier getCompilationId() { 120 return compilationId; 121 } 122 }