< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/NodeIntrinsificationProvider.java

Print this page
rev 52509 : [mq]: graal2


   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 
  24 
  25 package org.graalvm.compiler.replacements;
  26 
  27 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
  28 import org.graalvm.compiler.core.common.spi.ArrayOffsetProvider;
  29 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
  30 import org.graalvm.compiler.core.common.type.Stamp;
  31 import org.graalvm.compiler.core.common.type.StampFactory;
  32 import org.graalvm.compiler.core.common.type.TypeReference;
  33 import org.graalvm.compiler.debug.GraalError;
  34 import org.graalvm.compiler.nodes.graphbuilderconf.NodeIntrinsicPluginFactory.InjectionProvider;
  35 import org.graalvm.compiler.word.WordTypes;
  36 
  37 import jdk.vm.ci.meta.JavaKind;
  38 import jdk.vm.ci.meta.MetaAccessProvider;
  39 import jdk.vm.ci.meta.ResolvedJavaType;
  40 
  41 public class NodeIntrinsificationProvider implements InjectionProvider {
  42 
  43     private final MetaAccessProvider metaAccess;
  44     private final SnippetReflectionProvider snippetReflection;
  45     private final ForeignCallsProvider foreignCalls;
  46     private final ArrayOffsetProvider arrayOffsetProvider;
  47     private final WordTypes wordTypes;
  48 
  49     public NodeIntrinsificationProvider(MetaAccessProvider metaAccess, SnippetReflectionProvider snippetReflection, ForeignCallsProvider foreignCalls, ArrayOffsetProvider arrayOffsetProvider,
  50                     WordTypes wordTypes) {
  51         this.metaAccess = metaAccess;
  52         this.snippetReflection = snippetReflection;
  53         this.foreignCalls = foreignCalls;
  54         this.arrayOffsetProvider = arrayOffsetProvider;
  55         this.wordTypes = wordTypes;
  56     }
  57 
  58     @Override
  59     public Stamp getInjectedStamp(Class<?> type, boolean nonNull) {
  60         JavaKind kind = JavaKind.fromJavaClass(type);
  61         if (kind == JavaKind.Object) {
  62             ResolvedJavaType returnType = metaAccess.lookupJavaType(type);
  63             if (wordTypes.isWord(returnType)) {
  64                 return wordTypes.getWordStamp(returnType);
  65             } else {
  66                 return StampFactory.object(TypeReference.createWithoutAssumptions(returnType), nonNull);
  67             }
  68         } else {
  69             return StampFactory.forKind(kind);
  70         }
  71     }
  72 
  73     @Override
  74     public <T> T getInjectedArgument(Class<T> type) {
  75         T injected = snippetReflection.getInjectedNodeIntrinsicParameter(type);
  76         if (injected != null) {
  77             return injected;
  78         } else if (type.equals(ForeignCallsProvider.class)) {
  79             return type.cast(foreignCalls);
  80         } else if (type.equals(SnippetReflectionProvider.class)) {
  81             return type.cast(snippetReflection);
  82         } else if (type.equals(ArrayOffsetProvider.class)) {
  83             return type.cast(arrayOffsetProvider);
  84         } else {
  85             throw new GraalError("Cannot handle injected argument of type %s.", type.getName());
  86         }
  87     }
  88 }


   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 
  24 
  25 package org.graalvm.compiler.replacements;
  26 
  27 import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;

  28 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
  29 import org.graalvm.compiler.core.common.type.Stamp;
  30 import org.graalvm.compiler.core.common.type.StampFactory;
  31 import org.graalvm.compiler.core.common.type.TypeReference;
  32 import org.graalvm.compiler.debug.GraalError;
  33 import org.graalvm.compiler.nodes.graphbuilderconf.NodeIntrinsicPluginFactory.InjectionProvider;
  34 import org.graalvm.compiler.word.WordTypes;
  35 
  36 import jdk.vm.ci.meta.JavaKind;
  37 import jdk.vm.ci.meta.MetaAccessProvider;
  38 import jdk.vm.ci.meta.ResolvedJavaType;
  39 
  40 public class NodeIntrinsificationProvider implements InjectionProvider {
  41 
  42     private final MetaAccessProvider metaAccess;
  43     private final SnippetReflectionProvider snippetReflection;
  44     private final ForeignCallsProvider foreignCalls;

  45     private final WordTypes wordTypes;
  46 
  47     public NodeIntrinsificationProvider(MetaAccessProvider metaAccess, SnippetReflectionProvider snippetReflection, ForeignCallsProvider foreignCalls, WordTypes wordTypes) {

  48         this.metaAccess = metaAccess;
  49         this.snippetReflection = snippetReflection;
  50         this.foreignCalls = foreignCalls;

  51         this.wordTypes = wordTypes;
  52     }
  53 
  54     @Override
  55     public Stamp getInjectedStamp(Class<?> type, boolean nonNull) {
  56         JavaKind kind = JavaKind.fromJavaClass(type);
  57         if (kind == JavaKind.Object) {
  58             ResolvedJavaType returnType = metaAccess.lookupJavaType(type);
  59             if (wordTypes.isWord(returnType)) {
  60                 return wordTypes.getWordStamp(returnType);
  61             } else {
  62                 return StampFactory.object(TypeReference.createWithoutAssumptions(returnType), nonNull);
  63             }
  64         } else {
  65             return StampFactory.forKind(kind);
  66         }
  67     }
  68 
  69     @Override
  70     public <T> T getInjectedArgument(Class<T> type) {
  71         T injected = snippetReflection.getInjectedNodeIntrinsicParameter(type);
  72         if (injected != null) {
  73             return injected;
  74         } else if (type.equals(ForeignCallsProvider.class)) {
  75             return type.cast(foreignCalls);
  76         } else if (type.equals(SnippetReflectionProvider.class)) {
  77             return type.cast(snippetReflection);


  78         } else {
  79             throw new GraalError("Cannot handle injected argument of type %s.", type.getName());
  80         }
  81     }
  82 }
< prev index next >