forked from OSchip/llvm-project
[mlir] LocalAliasAnalysis: Assume allocation scope to function scope if cannot determine better
It helps when checking aliasing between AllocOp result and function arguments. Differential Revision: https://reviews.llvm.org/D102557
This commit is contained in:
parent
cb65419b1a
commit
91e0cb6598
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "mlir/Analysis/AliasAnalysis/LocalAliasAnalysis.h"
|
||||
|
||||
#include "mlir/IR/FunctionSupport.h"
|
||||
#include "mlir/IR/Matchers.h"
|
||||
#include "mlir/Interfaces/ControlFlowInterfaces.h"
|
||||
#include "mlir/Interfaces/SideEffectInterfaces.h"
|
||||
|
@ -231,7 +232,9 @@ getAllocEffectFor(Value value, Optional<MemoryEffects::EffectInstance> &effect,
|
|||
|
||||
// TODO: Here we could look at the users to see if the resource is either
|
||||
// freed on all paths within the region, or is just not captured by anything.
|
||||
allocScopeOp = nullptr;
|
||||
// For now assume allocation scope to the function scope (we don't care if
|
||||
// pointer escape outside function).
|
||||
allocScopeOp = op->getParentWithTrait<OpTrait::FunctionLike>();
|
||||
return success();
|
||||
}
|
||||
|
||||
|
|
|
@ -14,14 +14,12 @@
|
|||
// CHECK-DAG: alloca_2#0 <-> func.region0#0: NoAlias
|
||||
// CHECK-DAG: alloca_2#0 <-> func.region0#1: NoAlias
|
||||
|
||||
// TODO: The MayAlias below is overly conservative and should be provably
|
||||
// NoAlias with a proper escape analysis.
|
||||
// CHECK-DAG: alloc_1#0 <-> alloc_2#0: NoAlias
|
||||
// CHECK-DAG: alloc_1#0 <-> func.region0#0: MayAlias
|
||||
// CHECK-DAG: alloc_1#0 <-> func.region0#1: MayAlias
|
||||
// CHECK-DAG: alloc_1#0 <-> func.region0#0: NoAlias
|
||||
// CHECK-DAG: alloc_1#0 <-> func.region0#1: NoAlias
|
||||
|
||||
// CHECK-DAG: alloc_2#0 <-> func.region0#0: MayAlias
|
||||
// CHECK-DAG: alloc_2#0 <-> func.region0#1: MayAlias
|
||||
// CHECK-DAG: alloc_2#0 <-> func.region0#0: NoAlias
|
||||
// CHECK-DAG: alloc_2#0 <-> func.region0#1: NoAlias
|
||||
func @simple(%arg: memref<2xf32>, %arg1: memref<2xf32>) attributes {test.ptr = "func"} {
|
||||
%0 = memref.alloca() {test.ptr = "alloca_1"} : memref<8x64xf32>
|
||||
%1 = memref.alloca() {test.ptr = "alloca_2"} : memref<8x64xf32>
|
||||
|
@ -76,10 +74,10 @@ func @control_flow(%arg: memref<2xf32>, %cond: i1) attributes {test.ptr = "func"
|
|||
// CHECK-DAG: alloc_1#0 <-> func.region0.block2#0: MayAlias
|
||||
|
||||
// CHECK-DAG: func.region0#0 <-> func.region0.block1#0: NoAlias
|
||||
// CHECK-DAG: func.region0#0 <-> func.region0.block2#0: MayAlias
|
||||
// CHECK-DAG: func.region0#0 <-> func.region0.block2#0: NoAlias
|
||||
|
||||
// CHECK-DAG: func.region0#1 <-> func.region0.block1#0: NoAlias
|
||||
// CHECK-DAG: func.region0#1 <-> func.region0.block2#0: MayAlias
|
||||
// CHECK-DAG: func.region0#1 <-> func.region0.block2#0: NoAlias
|
||||
|
||||
// CHECK-DAG: func.region0.block1#0 <-> func.region0.block2#0: MayAlias
|
||||
func @control_flow_merge(%arg: memref<2xf32>, %cond: i1) attributes {test.ptr = "func"} {
|
||||
|
@ -120,8 +118,8 @@ func @control_flow_merge(%arg: memref<2xf32>, %cond: i1) attributes {test.ptr =
|
|||
// CHECK-DAG: if_alloca_merge#0 <-> func.region0#0: NoAlias
|
||||
// CHECK-DAG: if_alloca_merge#0 <-> func.region0#1: NoAlias
|
||||
|
||||
// CHECK-DAG: if_alloc#0 <-> func.region0#0: MayAlias
|
||||
// CHECK-DAG: if_alloc#0 <-> func.region0#1: MayAlias
|
||||
// CHECK-DAG: if_alloc#0 <-> func.region0#0: NoAlias
|
||||
// CHECK-DAG: if_alloc#0 <-> func.region0#1: NoAlias
|
||||
func @region_control_flow(%arg: memref<2xf32>, %cond: i1) attributes {test.ptr = "func"} {
|
||||
%0 = memref.alloca() {test.ptr = "alloca_1"} : memref<8x64xf32>
|
||||
%1 = memref.alloca() {test.ptr = "alloca_2"} : memref<8x64xf32>
|
||||
|
|
Loading…
Reference in New Issue