< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.phases.common/src/org/graalvm/compiler/phases/common/AddressLoweringByUsePhase.java

Print this page
rev 56282 : [mq]: graal
   1 /*
   2  * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2017, Red Hat Inc. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.


  52         public abstract AddressNode lower(ValueNode use, Stamp stamp, AddressNode address);
  53 
  54         public abstract AddressNode lower(AddressNode address);
  55     }
  56 
  57     private final AddressLoweringByUse lowering;
  58 
  59     public AddressLoweringByUsePhase(AddressLoweringByUse lowering) {
  60         this.lowering = lowering;
  61         assert lowering != null;
  62     }
  63 
  64     @Override
  65     protected void run(StructuredGraph graph) {
  66         // first replace address nodes hanging off known usages
  67         for (Node node : graph.getNodes()) {
  68             AddressNode address;
  69             AddressNode lowered;
  70             if (node instanceof ReadNode) {
  71                 ReadNode readNode = (ReadNode) node;
  72                 Stamp stamp = readNode.stamp(NodeView.DEFAULT);
  73                 address = readNode.getAddress();
  74                 lowered = lowering.lower(readNode, stamp, address);
  75             } else if (node instanceof JavaReadNode) {
  76                 JavaReadNode javaReadNode = (JavaReadNode) node;
  77                 Stamp stamp = javaReadNode.stamp(NodeView.DEFAULT);
  78                 address = javaReadNode.getAddress();
  79                 lowered = lowering.lower(javaReadNode, stamp, address);
  80             } else if (node instanceof FloatingReadNode) {
  81                 FloatingReadNode floatingReadNode = (FloatingReadNode) node;
  82                 Stamp stamp = floatingReadNode.stamp(NodeView.DEFAULT);
  83                 address = floatingReadNode.getAddress();
  84                 lowered = lowering.lower(floatingReadNode, stamp, address);
  85             } else if (node instanceof AbstractWriteNode) {
  86                 AbstractWriteNode abstractWriteNode = (AbstractWriteNode) node;
  87                 Stamp stamp = abstractWriteNode.value().stamp(NodeView.DEFAULT);
  88                 address = abstractWriteNode.getAddress();
  89                 lowered = lowering.lower(abstractWriteNode, stamp, address);
  90             } else if (node instanceof PrefetchAllocateNode) {
  91                 PrefetchAllocateNode prefetchAllocateNode = (PrefetchAllocateNode) node;
  92                 Stamp stamp = StampFactory.forKind(JavaKind.Object);
  93                 address = (AddressNode) prefetchAllocateNode.inputs().first();
  94                 lowered = lowering.lower(prefetchAllocateNode, stamp, address);
  95             } else {
  96                 continue;
  97             }
  98             // the lowered address may already be a replacement
  99             // in which case we want to use it not delete it!
 100             if (lowered != address) {
 101                 // replace original with lowered at this usage only
 102                 // n.b. lowered is added unique so repeat lowerings will elide
 103                 node.replaceFirstInput(address, lowered);
 104                 // if that was the last reference we can kill the old (dead) node
 105                 if (address.hasNoUsages()) {
 106                     GraphUtil.killWithUnusedFloatingInputs(address);
 107                 }
   1 /*
   2  * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2017, Red Hat Inc. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.


  52         public abstract AddressNode lower(ValueNode use, Stamp stamp, AddressNode address);
  53 
  54         public abstract AddressNode lower(AddressNode address);
  55     }
  56 
  57     private final AddressLoweringByUse lowering;
  58 
  59     public AddressLoweringByUsePhase(AddressLoweringByUse lowering) {
  60         this.lowering = lowering;
  61         assert lowering != null;
  62     }
  63 
  64     @Override
  65     protected void run(StructuredGraph graph) {
  66         // first replace address nodes hanging off known usages
  67         for (Node node : graph.getNodes()) {
  68             AddressNode address;
  69             AddressNode lowered;
  70             if (node instanceof ReadNode) {
  71                 ReadNode readNode = (ReadNode) node;
  72                 Stamp stamp = readNode.getAccessStamp();
  73                 address = readNode.getAddress();
  74                 lowered = lowering.lower(readNode, stamp, address);
  75             } else if (node instanceof JavaReadNode) {
  76                 JavaReadNode javaReadNode = (JavaReadNode) node;
  77                 Stamp stamp = javaReadNode.stamp(NodeView.DEFAULT);
  78                 address = javaReadNode.getAddress();
  79                 lowered = lowering.lower(javaReadNode, stamp, address);
  80             } else if (node instanceof FloatingReadNode) {
  81                 FloatingReadNode floatingReadNode = (FloatingReadNode) node;
  82                 Stamp stamp = floatingReadNode.getAccessStamp();
  83                 address = floatingReadNode.getAddress();
  84                 lowered = lowering.lower(floatingReadNode, stamp, address);
  85             } else if (node instanceof AbstractWriteNode) {
  86                 AbstractWriteNode abstractWriteNode = (AbstractWriteNode) node;
  87                 Stamp stamp = abstractWriteNode.getAccessStamp();
  88                 address = abstractWriteNode.getAddress();
  89                 lowered = lowering.lower(abstractWriteNode, stamp, address);
  90             } else if (node instanceof PrefetchAllocateNode) {
  91                 PrefetchAllocateNode prefetchAllocateNode = (PrefetchAllocateNode) node;
  92                 Stamp stamp = StampFactory.forKind(JavaKind.Object);
  93                 address = (AddressNode) prefetchAllocateNode.inputs().first();
  94                 lowered = lowering.lower(prefetchAllocateNode, stamp, address);
  95             } else {
  96                 continue;
  97             }
  98             // the lowered address may already be a replacement
  99             // in which case we want to use it not delete it!
 100             if (lowered != address) {
 101                 // replace original with lowered at this usage only
 102                 // n.b. lowered is added unique so repeat lowerings will elide
 103                 node.replaceFirstInput(address, lowered);
 104                 // if that was the last reference we can kill the old (dead) node
 105                 if (address.hasNoUsages()) {
 106                     GraphUtil.killWithUnusedFloatingInputs(address);
 107                 }
< prev index next >