| 1011 | } |
| 1012 | |
| 1013 | Memory::AliasSet Memory::computeAliasing(const Pointer &ptr, const expr &bytes, |
| 1014 | uint64_t align, bool write) const { |
| 1015 | AliasSet aliasing(*this); |
| 1016 | auto sz_local = min(next_local_bid, (unsigned)aliasing.size(true)); |
| 1017 | auto sz_nonlocal = aliasing.size(false); |
| 1018 | |
| 1019 | auto check_alias = [&](AliasSet &alias, bool local, unsigned bid, |
| 1020 | const expr &offset) { |
| 1021 | if (!alias.mayAlias(local, bid) && |
| 1022 | mayalias(local, bid, offset, bytes, align, write)) |
| 1023 | alias.setMayAlias(local, bid); |
| 1024 | }; |
| 1025 | |
| 1026 | // collect over-approximation of possible touched bids |
| 1027 | for (auto &p : all_leaf_ptrs(*this, ptr())) { |
| 1028 | if (has_noread && !write && p.isNoRead().isTrue()) |
| 1029 | continue; |
| 1030 | if (has_nowrite && write && p.isNoWrite().isTrue()) |
| 1031 | continue; |
| 1032 | |
| 1033 | AliasSet this_alias = aliasing; |
| 1034 | auto is_local = p.isLocal(); |
| 1035 | auto shortbid = p.getShortBid(); |
| 1036 | expr offset = p.getOffset(); |
| 1037 | uint64_t bid; |
| 1038 | if (shortbid.isUInt(bid) && |
| 1039 | (!isAsmMode() || state->isImplied(p.isInbounds(true), true))) { |
| 1040 | if (!is_local.isFalse() && bid < sz_local) |
| 1041 | check_alias(this_alias, true, bid, offset); |
| 1042 | if (!is_local.isTrue() && bid < sz_nonlocal) |
| 1043 | check_alias(this_alias, false, bid, offset); |
| 1044 | goto end; |
| 1045 | } |
| 1046 | |
| 1047 | { |
| 1048 | bool is_init_memory = isInitialMemoryOrLoad(shortbid, false); |
| 1049 | bool is_from_fn_or_load = !is_init_memory && |
| 1050 | (isInitialMemoryOrLoad(shortbid, true) || |
| 1051 | isFnReturnValue(shortbid) || |
| 1052 | isDerivedFromLoad(shortbid)); |
| 1053 | |
| 1054 | for (auto local : { true, false }) { |
| 1055 | if ((local && is_local.isFalse()) || (!local && is_local.isTrue())) |
| 1056 | continue; |
| 1057 | for (unsigned i = 0, e = local ? sz_local : sz_nonlocal; i < e; ++i) { |
| 1058 | // initial memory doesn't have local ptrs stored |
| 1059 | if (local && is_init_memory) |
| 1060 | continue; |
| 1061 | // functions and memory loads can only return escaped ptrs |
| 1062 | if (local && |
| 1063 | is_from_fn_or_load && |
| 1064 | !escaped_local_blks.mayAlias(true, i)) |
| 1065 | continue; |
| 1066 | check_alias(this_alias, local, i, offset); |
| 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 |
no test coverage detected