For the purposes of alias analysis, we should only consider provenance captures, not address captures. To support this, change (or add) CaptureTracking APIs to accept a Mask and StopFn argument. The Mask determines which components we are interested in (for AA that would be Provenance). The StopFn determines when we can abort the walk early. Currently, we want to do this as soon as any of the components in the Mask is captured. The purpose of making this a separate predicate is that in the future we will also want to distinguish between capturing full provenance and read-only provenance. In that case, we can only stop early once full provenance is captured. The earliest escape analysis does not get a StopFn, because it must always inspect all captures.
43 lines
1.2 KiB
LLVM
43 lines
1.2 KiB
LLVM
; RUN: opt < %s -passes=aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
|
|
|
|
declare void @capture(ptr)
|
|
declare ptr @get_ptr()
|
|
|
|
; CHECK-LABEL: address_capture
|
|
; CHECK: NoAlias: i32* %a, i32* %p
|
|
; CHECK: NoModRef: Ptr: i32* %a <-> %p = call ptr @get_ptr()
|
|
define void @address_capture() {
|
|
%a = alloca i32
|
|
call void @capture(ptr captures(address) %a)
|
|
%p = call ptr @get_ptr()
|
|
store i32 0, ptr %p
|
|
load i32, ptr %a
|
|
ret void
|
|
}
|
|
|
|
; CHECK-LABEL: read_only_capture
|
|
; CHECK: MayAlias: i32* %a, i32* %p
|
|
; CHECK: Both ModRef: Ptr: i32* %a <-> %p = call ptr @get_ptr()
|
|
; TODO: The ModRef could be just Ref.
|
|
define void @read_only_capture() {
|
|
%a = alloca i32
|
|
call void @capture(ptr captures(address, read_provenance) %a)
|
|
%p = call ptr @get_ptr()
|
|
store i32 0, ptr %p
|
|
load i32, ptr %a
|
|
ret void
|
|
}
|
|
|
|
; CHECK-LABEL: address_capture_and_full_capture
|
|
; CHECK: MayAlias: i32* %a, i32* %p
|
|
; CHECK: Both ModRef: Ptr: i32* %a <-> %p = call ptr @get_ptr()
|
|
define void @address_capture_and_full_capture() {
|
|
%a = alloca i32
|
|
call void @capture(ptr captures(address) %a)
|
|
call void @capture(ptr %a)
|
|
%p = call ptr @get_ptr()
|
|
store i32 0, ptr %p
|
|
load i32, ptr %a
|
|
ret void
|
|
}
|