src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.virtual/src/org/graalvm/compiler/virtual/phases/ea/ReadEliminationClosure.java
changeset 58877 aec7bf35d6f5
parent 52910 583fd71c47d6
equal deleted inserted replaced
58876:1a8d65e71a66 58877:aec7bf35d6f5
     1 /*
     1 /*
     2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   133                     state.addCacheEntry(identifier, read);
   133                     state.addCacheEntry(identifier, read);
   134                 }
   134                 }
   135             }
   135             }
   136         } else if (node instanceof WriteNode) {
   136         } else if (node instanceof WriteNode) {
   137             WriteNode write = (WriteNode) node;
   137             WriteNode write = (WriteNode) node;
   138             if (write.getLocationIdentity().isSingle()) {
   138             if (write.getKilledLocationIdentity().isSingle()) {
   139                 ValueNode object = GraphUtil.unproxify(write.getAddress());
   139                 ValueNode object = GraphUtil.unproxify(write.getAddress());
   140                 LoadCacheEntry identifier = new LoadCacheEntry(object, write.getLocationIdentity());
   140                 LoadCacheEntry identifier = new LoadCacheEntry(object, write.getKilledLocationIdentity());
   141                 ValueNode cachedValue = state.getCacheEntry(identifier);
   141                 ValueNode cachedValue = state.getCacheEntry(identifier);
   142 
   142 
   143                 ValueNode value = getScalarAlias(write.value());
   143                 ValueNode value = getScalarAlias(write.value());
   144                 if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) {
   144                 if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) {
   145                     effects.deleteNode(write);
   145                     effects.deleteNode(write);
   146                     deleted = true;
   146                     deleted = true;
   147                 }
   147                 }
   148                 processIdentity(state, write.getLocationIdentity());
   148                 processIdentity(state, write.getKilledLocationIdentity());
   149                 state.addCacheEntry(identifier, value);
   149                 state.addCacheEntry(identifier, value);
   150             } else {
   150             } else {
   151                 processIdentity(state, write.getLocationIdentity());
   151                 processIdentity(state, write.getKilledLocationIdentity());
   152             }
   152             }
   153         } else if (node instanceof UnsafeAccessNode) {
   153         } else if (node instanceof UnsafeAccessNode) {
   154             ResolvedJavaType type = StampTool.typeOrNull(((UnsafeAccessNode) node).object());
   154             ResolvedJavaType type = StampTool.typeOrNull(((UnsafeAccessNode) node).object());
   155             if (type != null && !type.isArray()) {
   155             if (type != null && !type.isArray()) {
   156                 if (node instanceof RawLoadNode) {
   156                 if (node instanceof RawLoadNode) {
   168                         }
   168                         }
   169                     }
   169                     }
   170                 } else {
   170                 } else {
   171                     assert node instanceof RawStoreNode;
   171                     assert node instanceof RawStoreNode;
   172                     RawStoreNode write = (RawStoreNode) node;
   172                     RawStoreNode write = (RawStoreNode) node;
   173                     if (write.getLocationIdentity().isSingle()) {
   173                     if (write.getKilledLocationIdentity().isSingle()) {
   174                         ValueNode object = GraphUtil.unproxify(write.object());
   174                         ValueNode object = GraphUtil.unproxify(write.object());
   175                         UnsafeLoadCacheEntry identifier = new UnsafeLoadCacheEntry(object, write.offset(), write.getLocationIdentity());
   175                         UnsafeLoadCacheEntry identifier = new UnsafeLoadCacheEntry(object, write.offset(), write.getKilledLocationIdentity());
   176                         ValueNode cachedValue = state.getCacheEntry(identifier);
   176                         ValueNode cachedValue = state.getCacheEntry(identifier);
   177 
   177 
   178                         ValueNode value = getScalarAlias(write.value());
   178                         ValueNode value = getScalarAlias(write.value());
   179                         if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) {
   179                         if (GraphUtil.unproxify(value) == GraphUtil.unproxify(cachedValue)) {
   180                             effects.deleteNode(write);
   180                             effects.deleteNode(write);
   181                             deleted = true;
   181                             deleted = true;
   182                         }
   182                         }
   183                         processIdentity(state, write.getLocationIdentity());
   183                         processIdentity(state, write.getKilledLocationIdentity());
   184                         state.addCacheEntry(identifier, value);
   184                         state.addCacheEntry(identifier, value);
   185                     } else {
   185                     } else {
   186                         processIdentity(state, write.getLocationIdentity());
   186                         processIdentity(state, write.getKilledLocationIdentity());
   187                     }
   187                     }
   188                 }
   188                 }
   189             }
   189             }
   190         } else if (node instanceof MemoryCheckpoint.Single) {
   190         } else if (node instanceof MemoryCheckpoint.Single) {
   191             LocationIdentity identity = ((MemoryCheckpoint.Single) node).getLocationIdentity();
   191             LocationIdentity identity = ((MemoryCheckpoint.Single) node).getKilledLocationIdentity();
   192             processIdentity(state, identity);
   192             processIdentity(state, identity);
   193         } else if (node instanceof MemoryCheckpoint.Multi) {
   193         } else if (node instanceof MemoryCheckpoint.Multi) {
   194             for (LocationIdentity identity : ((MemoryCheckpoint.Multi) node).getLocationIdentities()) {
   194             for (LocationIdentity identity : ((MemoryCheckpoint.Multi) node).getKilledLocationIdentities()) {
   195                 processIdentity(state, identity);
   195                 processIdentity(state, identity);
   196             }
   196             }
   197         }
   197         }
   198         return deleted;
   198         return deleted;
   199     }
   199     }