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 com.oracle.graal.compiler.target; 024 025import jdk.internal.jvmci.code.*; 026import jdk.internal.jvmci.code.stack.*; 027import jdk.internal.jvmci.common.*; 028import jdk.internal.jvmci.meta.*; 029 030import com.oracle.graal.asm.*; 031import com.oracle.graal.compiler.common.alloc.*; 032import com.oracle.graal.compiler.common.spi.*; 033import com.oracle.graal.compiler.gen.*; 034import com.oracle.graal.lir.*; 035import com.oracle.graal.lir.asm.*; 036import com.oracle.graal.lir.framemap.*; 037import com.oracle.graal.lir.gen.*; 038import com.oracle.graal.nodes.*; 039import com.oracle.graal.nodes.spi.*; 040import com.oracle.graal.phases.tiers.*; 041import com.oracle.graal.phases.util.*; 042 043/** 044 * Represents a compiler backend for Graal. 045 */ 046public abstract class Backend { 047 048 private final Providers providers; 049 050 public static final ForeignCallDescriptor ARITHMETIC_SIN = new ForeignCallDescriptor("arithmeticSin", double.class, double.class); 051 public static final ForeignCallDescriptor ARITHMETIC_COS = new ForeignCallDescriptor("arithmeticCos", double.class, double.class); 052 public static final ForeignCallDescriptor ARITHMETIC_TAN = new ForeignCallDescriptor("arithmeticTan", double.class, double.class); 053 public static final ForeignCallDescriptor ARITHMETIC_EXP = new ForeignCallDescriptor("arithmeticExp", double.class, double.class); 054 public static final ForeignCallDescriptor ARITHMETIC_LOG = new ForeignCallDescriptor("arithmeticLog", double.class, double.class); 055 public static final ForeignCallDescriptor ARITHMETIC_LOG10 = new ForeignCallDescriptor("arithmeticLog10", double.class, double.class); 056 public static final ForeignCallDescriptor ARITHMETIC_POW = new ForeignCallDescriptor("arithmeticPow", double.class, double.class, double.class); 057 058 protected Backend(Providers providers) { 059 this.providers = providers; 060 } 061 062 public Providers getProviders() { 063 return providers; 064 } 065 066 public CodeCacheProvider getCodeCache() { 067 return providers.getCodeCache(); 068 } 069 070 public MetaAccessProvider getMetaAccess() { 071 return providers.getMetaAccess(); 072 } 073 074 public ConstantReflectionProvider getConstantReflection() { 075 return providers.getConstantReflection(); 076 } 077 078 public ForeignCallsProvider getForeignCalls() { 079 return providers.getForeignCalls(); 080 } 081 082 public abstract SuitesProvider getSuites(); 083 084 public TargetDescription getTarget() { 085 return providers.getCodeCache().getTarget(); 086 } 087 088 /** 089 * The given registerConfig is optional, in case null is passed the default RegisterConfig from 090 * the CodeCacheProvider will be used. 091 */ 092 public abstract FrameMapBuilder newFrameMapBuilder(RegisterConfig registerConfig); 093 094 public abstract RegisterAllocationConfig newRegisterAllocationConfig(RegisterConfig registerConfig); 095 096 public abstract FrameMap newFrameMap(RegisterConfig registerConfig); 097 098 public abstract LIRGeneratorTool newLIRGenerator(CallingConvention cc, LIRGenerationResult lirGenRes); 099 100 public abstract LIRGenerationResult newLIRGenerationResult(String compilationUnitName, LIR lir, FrameMapBuilder frameMapBuilder, ResolvedJavaMethod method, Object stub); 101 102 public abstract NodeLIRBuilderTool newNodeLIRBuilder(StructuredGraph graph, LIRGeneratorTool lirGen); 103 104 /** 105 * @param gen the LIRGenerator the BytecodeLIRBuilder should use 106 * @param parser the bytecode parser the BytecodeLIRBuilder should use 107 */ 108 public BytecodeLIRBuilder newBytecodeLIRBuilder(LIRGeneratorTool gen, BytecodeParserTool parser) { 109 throw JVMCIError.unimplemented("Baseline compilation is not available for this Backend!"); 110 } 111 112 /** 113 * Creates the assembler used to emit the machine code. 114 */ 115 protected abstract Assembler createAssembler(FrameMap frameMap); 116 117 /** 118 * Creates the object used to fill in the details of a given compilation result. 119 */ 120 public abstract CompilationResultBuilder newCompilationResultBuilder(LIRGenerationResult lirGenResult, FrameMap frameMap, CompilationResult compilationResult, 121 CompilationResultBuilderFactory factory); 122 123 public abstract StackIntrospection getStackIntrospection(); 124 125 /** 126 * Emits the code for a given graph. 127 * 128 * @param installedCodeOwner the method the compiled code will be associated with once 129 * installed. This argument can be null. 130 */ 131 public abstract void emitCode(CompilationResultBuilder crb, LIR lir, ResolvedJavaMethod installedCodeOwner); 132 133}