llvm.org GIT mirror llvm / 110748b
[dfsan] Introduce further optimization to reduce the number of union queries. Specifically, do not compute a union if it is statically known that one shadow set subsumes the other. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213100 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 5 years ago
2 changed file(s) with 51 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
6262 #include "llvm/Support/SpecialCaseList.h"
6363 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
6464 #include "llvm/Transforms/Utils/Local.h"
65 #include
6566 #include
67 #include
68 #include
6669
6770 using namespace llvm;
6871
283286 };
284287 DenseMap, CachedCombinedShadow>
285288 CachedCombinedShadows;
289 DenseMap> ShadowElements;
286290
287291 DFSanFunction(DataFlowSanitizer &DFS, Function *F, bool IsNativeABI)
288292 : DFS(DFS), F(F), IA(DFS.getInstrumentedABI()),
891895 if (V1 == V2)
892896 return V1;
893897
898 auto V1Elems = ShadowElements.find(V1);
899 auto V2Elems = ShadowElements.find(V2);
900 if (V1Elems != ShadowElements.end() && V2Elems != ShadowElements.end()) {
901 if (std::includes(V1Elems->second.begin(), V1Elems->second.end(),
902 V2Elems->second.begin(), V2Elems->second.end())) {
903 return V1;
904 } else if (std::includes(V2Elems->second.begin(), V2Elems->second.end(),
905 V1Elems->second.begin(), V1Elems->second.end())) {
906 return V2;
907 }
908 } else if (V1Elems != ShadowElements.end()) {
909 if (V1Elems->second.count(V2))
910 return V1;
911 } else if (V2Elems != ShadowElements.end()) {
912 if (V2Elems->second.count(V1))
913 return V2;
914 }
915
894916 auto Key = std::make_pair(V1, V2);
895917 if (V1 > V2)
896918 std::swap(Key.first, Key.second);
916938
917939 CCS.Block = Tail;
918940 CCS.Shadow = Phi;
941
942 std::set UnionElems;
943 if (V1Elems != ShadowElements.end()) {
944 UnionElems = V1Elems->second;
945 } else {
946 UnionElems.insert(V1);
947 }
948 if (V2Elems != ShadowElements.end()) {
949 UnionElems.insert(V2Elems->second.begin(), V2Elems->second.end());
950 } else {
951 UnionElems.insert(V2);
952 }
953 ShadowElements[Phi] = std::move(UnionElems);
954
919955 return Phi;
920956 }
921957
77
88 ; CHECK-LABEL: @"dfs$f"
99 define void @f(i32 %x, i32 %y) {
10 ; CHECK: __dfsan_union
10 ; CHECK: call{{.*}}__dfsan_union
1111 %xay = add i32 %x, %y
1212 store i32 %xay, i32* @a
13 ; CHECK-NOT: __dfsan_union
13 ; CHECK-NOT: call{{.*}}__dfsan_union
1414 %xmy = mul i32 %x, %y
1515 store i32 %xmy, i32* @b
1616 ret void
2424 br i1 %p, label %l1, label %l2
2525
2626 l1:
27 ; CHECK: __dfsan_union
27 ; CHECK: call{{.*}}__dfsan_union
2828 %xay = add i32 %x, %y
2929 store i32 %xay, i32* @a
3030 br label %l3
3131
3232 l2:
33 ; CHECK: __dfsan_union
33 ; CHECK: call{{.*}}__dfsan_union
3434 %xmy = mul i32 %x, %y
3535 store i32 %xmy, i32* @b
3636 br label %l3
3838 l3:
3939 ret void
4040 }
41
42 ; In this case, we know that the label for %xayax subsumes the label for %xay.
43
44 ; CHECK-LABEL: @"dfs$h"
45 define i32 @h(i32 %x, i32 %y) {
46 ; CHECK: call{{.*}}__dfsan_union
47 %xay = add i32 %x, %y
48 ; CHECK-NOT: call{{.*}}__dfsan_union
49 %xayax = add i32 %xay, %x
50 ret i32 %xayax
51 }