1 /*
   2  * Copyright (c) 2013, 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 com.oracle.graal.hotspot.hsail;
  24 
  25 import java.lang.reflect.*;
  26 
  27 import com.oracle.graal.api.code.*;
  28 import com.oracle.graal.api.meta.*;
  29 import com.oracle.graal.nodes.*;
  30 import com.oracle.graal.nodes.spi.*;
  31 import com.oracle.graal.phases.util.*;
  32 import com.oracle.graal.replacements.*;
  33 
  34 /**
  35  * The substitutions and snippets supported by HSAIL.
  36  */
  37 public class HSAILHotSpotReplacementsImpl extends ReplacementsImpl {
  38 
  39     private final Replacements host;
  40 
  41     public HSAILHotSpotReplacementsImpl(Providers providers, Assumptions assumptions, TargetDescription target, Replacements host) {
  42         super(providers, assumptions, target);
  43         this.host = host;
  44     }
  45 
  46     @Override
  47     protected ResolvedJavaMethod registerMethodSubstitution(Member originalMethod, Method substituteMethod) {
  48         // TODO: decide if we want to override this in any way
  49         return super.registerMethodSubstitution(originalMethod, substituteMethod);
  50     }
  51 
  52     @Override
  53     public Class<? extends FixedWithNextNode> getMacroSubstitution(ResolvedJavaMethod method) {
  54         Class<? extends FixedWithNextNode> klass = super.getMacroSubstitution(method);
  55         if (klass == null) {
  56             // eventually we want to only defer certain macro substitutions to the host, but for now
  57             // we will do everything
  58             return host.getMacroSubstitution(method);
  59         }
  60         return klass;
  61     }
  62 
  63     @Override
  64     public StructuredGraph getSnippet(ResolvedJavaMethod method) {
  65         // Must work in cooperation with HSAILHotSpotLoweringProvider
  66         return host.getSnippet(method);
  67     }
  68 
  69     @Override
  70     public StructuredGraph getMethodSubstitution(ResolvedJavaMethod original) {
  71         StructuredGraph m = super.getMethodSubstitution(original);
  72         if (m == null) {
  73             // eventually we want to only defer certain substitutions to the host, but for now we
  74             // will defer everything
  75             return host.getMethodSubstitution(original);
  76         }
  77         return m;
  78     }
  79 
  80 }