1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[LAA] Split out a helper to print a collection of memchecks

This is effectively an NFC but we can no longer print the index of the
pointer group so instead I print its address.  This still lets us
cross-check the section that list the checks against the section that
list the groups (see how I modified the test).

E.g. before we printed this:

    Run-time memory checks:
    Check 0:
      Comparing group 0:
        %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %store_ind
        %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc
      Against group 1:
        %arrayidxA = getelementptr i16, i16* %a, i64 %ind
        %arrayidxA1 = getelementptr i16, i16* %a, i64 %add
    ...
    Grouped accesses:
      Group 0:
        (Low: %c High: (78 + %c))
          Member: {%c,+,4}<%for.body>
          Member: {(2 + %c),+,4}<%for.body>

Now we print this (changes are underlined):

    Run-time memory checks:
    Check 0:
      Comparing group (0x7f9c6040c320):
                       ~~~~~~~~~~~~~~
        %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc
        %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %store_ind
      Against group (0x7f9c6040c358):
                     ~~~~~~~~~~~~~~
        %arrayidxA1 = getelementptr i16, i16* %a, i64 %add
        %arrayidxA = getelementptr i16, i16* %a, i64 %ind
    ...
    Grouped accesses:
      Group 0x7f9c6040c320:
            ~~~~~~~~~~~~~~
        (Low: %c High: (78 + %c))
          Member: {(2 + %c),+,4}<%for.body>
          Member: {%c,+,4}<%for.body>

llvm-svn: 243354
This commit is contained in:
Adam Nemet 2015-07-27 23:54:41 +00:00
parent a1406d7c50
commit 7b14f72b61
3 changed files with 52 additions and 55 deletions

View File

@ -414,6 +414,10 @@ public:
void print(raw_ostream &OS, unsigned Depth = 0, void print(raw_ostream &OS, unsigned Depth = 0,
const SmallVectorImpl<int> *PtrPartition = nullptr) const; const SmallVectorImpl<int> *PtrPartition = nullptr) const;
/// Print \p Checks.
void printChecks(raw_ostream &OS, const SmallVectorImpl<PointerCheck> &Checks,
unsigned Depth = 0) const;
/// This flag indicates if we need to add the runtime check. /// This flag indicates if we need to add the runtime check.
bool Need; bool Need;

View File

@ -344,48 +344,41 @@ bool RuntimePointerChecking::needsChecking(
return true; return true;
} }
void RuntimePointerChecking::printChecks(
raw_ostream &OS, const SmallVectorImpl<PointerCheck> &Checks,
unsigned Depth) const {
unsigned N = 0;
for (const auto &Check : Checks) {
const auto &First = Check.first->Members, &Second = Check.second->Members;
OS.indent(Depth) << "Check " << N++ << ":\n";
OS.indent(Depth + 2) << "Comparing group (" << Check.first << "):\n";
for (unsigned K = 0; K < First.size(); ++K)
OS.indent(Depth + 2) << *Pointers[First[K]].PointerValue << "\n";
OS.indent(Depth + 2) << "Against group (" << Check.second << "):\n";
for (unsigned K = 0; K < Second.size(); ++K)
OS.indent(Depth + 2) << *Pointers[Second[K]].PointerValue << "\n";
}
}
void RuntimePointerChecking::print( void RuntimePointerChecking::print(
raw_ostream &OS, unsigned Depth, raw_ostream &OS, unsigned Depth,
const SmallVectorImpl<int> *PtrPartition) const { const SmallVectorImpl<int> *PtrPartition) const {
OS.indent(Depth) << "Run-time memory checks:\n"; OS.indent(Depth) << "Run-time memory checks:\n";
printChecks(OS, generateChecks(PtrPartition), Depth);
unsigned N = 0;
for (unsigned I = 0; I < CheckingGroups.size(); ++I)
for (unsigned J = I + 1; J < CheckingGroups.size(); ++J)
if (needsChecking(CheckingGroups[I], CheckingGroups[J], PtrPartition)) {
OS.indent(Depth) << "Check " << N++ << ":\n";
OS.indent(Depth + 2) << "Comparing group " << I << ":\n";
for (unsigned K = 0; K < CheckingGroups[I].Members.size(); ++K) {
OS.indent(Depth + 2)
<< *Pointers[CheckingGroups[I].Members[K]].PointerValue << "\n";
if (PtrPartition)
OS << " (Partition: "
<< (*PtrPartition)[CheckingGroups[I].Members[K]] << ")"
<< "\n";
}
OS.indent(Depth + 2) << "Against group " << J << ":\n";
for (unsigned K = 0; K < CheckingGroups[J].Members.size(); ++K) {
OS.indent(Depth + 2)
<< *Pointers[CheckingGroups[J].Members[K]].PointerValue << "\n";
if (PtrPartition)
OS << " (Partition: "
<< (*PtrPartition)[CheckingGroups[J].Members[K]] << ")"
<< "\n";
}
}
OS.indent(Depth) << "Grouped accesses:\n"; OS.indent(Depth) << "Grouped accesses:\n";
for (unsigned I = 0; I < CheckingGroups.size(); ++I) { for (unsigned I = 0; I < CheckingGroups.size(); ++I) {
OS.indent(Depth + 2) << "Group " << I << ":\n"; const auto &CG = CheckingGroups[I];
OS.indent(Depth + 4) << "(Low: " << *CheckingGroups[I].Low
<< " High: " << *CheckingGroups[I].High << ")\n"; OS.indent(Depth + 2) << "Group " << &CG << ":\n";
for (unsigned J = 0; J < CheckingGroups[I].Members.size(); ++J) { OS.indent(Depth + 4) << "(Low: " << *CG.Low << " High: " << *CG.High
OS.indent(Depth + 6) << "Member: " << ")\n";
<< *Pointers[CheckingGroups[I].Members[J]].Expr for (unsigned J = 0; J < CG.Members.size(); ++J) {
OS.indent(Depth + 6) << "Member: " << *Pointers[CG.Members[J]].Expr
<< "\n"; << "\n";
} }
} }

View File

@ -81,28 +81,28 @@ for.end: ; preds = %for.body
; CHECK: Run-time memory checks: ; CHECK: Run-time memory checks:
; CHECK-NEXT: Check 0: ; CHECK-NEXT: Check 0:
; CHECK-NEXT: Comparing group 0: ; CHECK-NEXT: Comparing group ([[ZERO:.+]]):
; CHECK-NEXT: %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc ; CHECK-NEXT: %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc
; CHECK-NEXT: %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %store_ind ; CHECK-NEXT: %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %store_ind
; CHECK-NEXT: Against group 1: ; CHECK-NEXT: Against group ([[ONE:.+]]):
; CHECK-NEXT: %arrayidxA1 = getelementptr inbounds i16, i16* %a, i64 %add ; CHECK-NEXT: %arrayidxA1 = getelementptr inbounds i16, i16* %a, i64 %add
; CHECK-NEXT: %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %ind ; CHECK-NEXT: %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %ind
; CHECK-NEXT: Check 1: ; CHECK-NEXT: Check 1:
; CHECK-NEXT: Comparing group 0: ; CHECK-NEXT: Comparing group ({{.*}}[[ZERO]]):
; CHECK-NEXT: %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc ; CHECK-NEXT: %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc
; CHECK-NEXT: %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %store_ind ; CHECK-NEXT: %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %store_ind
; CHECK-NEXT: Against group 2: ; CHECK-NEXT: Against group ([[TWO:.+]]):
; CHECK-NEXT: %arrayidxB = getelementptr inbounds i16, i16* %b, i64 %ind ; CHECK-NEXT: %arrayidxB = getelementptr inbounds i16, i16* %b, i64 %ind
; CHECK-NEXT: Grouped accesses: ; CHECK-NEXT: Grouped accesses:
; CHECK-NEXT: Group 0: ; CHECK-NEXT: Group {{.*}}[[ZERO]]:
; CHECK-NEXT: (Low: %c High: (78 + %c)) ; CHECK-NEXT: (Low: %c High: (78 + %c))
; CHECK-NEXT: Member: {(2 + %c),+,4} ; CHECK-NEXT: Member: {(2 + %c),+,4}
; CHECK-NEXT: Member: {%c,+,4} ; CHECK-NEXT: Member: {%c,+,4}
; CHECK-NEXT: Group 1: ; CHECK-NEXT: Group {{.*}}[[ONE]]:
; CHECK-NEXT: (Low: %a High: (40 + %a)) ; CHECK-NEXT: (Low: %a High: (40 + %a))
; CHECK-NEXT: Member: {(2 + %a),+,2} ; CHECK-NEXT: Member: {(2 + %a),+,2}
; CHECK-NEXT: Member: {%a,+,2} ; CHECK-NEXT: Member: {%a,+,2}
; CHECK-NEXT: Group 2: ; CHECK-NEXT: Group {{.*}}[[TWO]]:
; CHECK-NEXT: (Low: %b High: (38 + %b)) ; CHECK-NEXT: (Low: %b High: (38 + %b))
; CHECK-NEXT: Member: {%b,+,2} ; CHECK-NEXT: Member: {%b,+,2}
@ -153,28 +153,28 @@ for.end: ; preds = %for.body
; CHECK: function 'testh': ; CHECK: function 'testh':
; CHECK: Run-time memory checks: ; CHECK: Run-time memory checks:
; CHECK-NEXT: Check 0: ; CHECK-NEXT: Check 0:
; CHECK-NEXT: Comparing group 0: ; CHECK-NEXT: Comparing group ([[ZERO:.+]]):
; CHECK-NEXT: %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc ; CHECK-NEXT: %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc
; CHECK-NEXT: %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %store_ind ; CHECK-NEXT: %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %store_ind
; CHECK-NEXT: Against group 1: ; CHECK-NEXT: Against group ([[ONE:.+]]):
; CHECK-NEXT: %arrayidxA1 = getelementptr i16, i16* %a, i64 %add ; CHECK-NEXT: %arrayidxA1 = getelementptr i16, i16* %a, i64 %add
; CHECK-NEXT: %arrayidxA = getelementptr i16, i16* %a, i64 %ind ; CHECK-NEXT: %arrayidxA = getelementptr i16, i16* %a, i64 %ind
; CHECK-NEXT: Check 1: ; CHECK-NEXT: Check 1:
; CHECK-NEXT: Comparing group 0: ; CHECK-NEXT: Comparing group ({{.*}}[[ZERO]]):
; CHECK-NEXT: %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc ; CHECK-NEXT: %arrayidxC1 = getelementptr inbounds i16, i16* %c, i64 %store_ind_inc
; CHECK-NEXT: %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %store_ind ; CHECK-NEXT: %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %store_ind
; CHECK-NEXT: Against group 2: ; CHECK-NEXT: Against group ([[TWO:.+]]):
; CHECK-NEXT: %arrayidxB = getelementptr i16, i16* %b, i64 %ind ; CHECK-NEXT: %arrayidxB = getelementptr i16, i16* %b, i64 %ind
; CHECK-NEXT: Grouped accesses: ; CHECK-NEXT: Grouped accesses:
; CHECK-NEXT: Group 0: ; CHECK-NEXT: Group {{.*}}[[ZERO]]:
; CHECK-NEXT: (Low: %c High: (78 + %c)) ; CHECK-NEXT: (Low: %c High: (78 + %c))
; CHECK-NEXT: Member: {(2 + %c),+,4} ; CHECK-NEXT: Member: {(2 + %c),+,4}
; CHECK-NEXT: Member: {%c,+,4} ; CHECK-NEXT: Member: {%c,+,4}
; CHECK-NEXT: Group 1: ; CHECK-NEXT: Group {{.*}}[[ONE]]:
; CHECK-NEXT: (Low: %a High: (40 + %a)) ; CHECK-NEXT: (Low: %a High: (40 + %a))
; CHECK-NEXT: Member: {(2 + %a),+,2} ; CHECK-NEXT: Member: {(2 + %a),+,2}
; CHECK-NEXT: Member: {%a,+,2} ; CHECK-NEXT: Member: {%a,+,2}
; CHECK-NEXT: Group 2: ; CHECK-NEXT: Group {{.*}}[[TWO]]:
; CHECK-NEXT: (Low: %b High: (38 + %b)) ; CHECK-NEXT: (Low: %b High: (38 + %b))
; CHECK-NEXT: Member: {%b,+,2} ; CHECK-NEXT: Member: {%b,+,2}
@ -230,23 +230,23 @@ for.end: ; preds = %for.body
; CHECK: function 'testi': ; CHECK: function 'testi':
; CHECK: Run-time memory checks: ; CHECK: Run-time memory checks:
; CHECK-NEXT: Check 0: ; CHECK-NEXT: Check 0:
; CHECK-NEXT: Comparing group 0: ; CHECK-NEXT: Comparing group ([[ZERO:.+]]):
; CHECK-NEXT: %storeidx = getelementptr inbounds i16, i16* %a, i64 %store_ind ; CHECK-NEXT: %storeidx = getelementptr inbounds i16, i16* %a, i64 %store_ind
; CHECK-NEXT: Against group 1: ; CHECK-NEXT: Against group ([[ONE:.+]]):
; CHECK-NEXT: %arrayidxA1 = getelementptr i16, i16* %a, i64 %ind ; CHECK-NEXT: %arrayidxA1 = getelementptr i16, i16* %a, i64 %ind
; CHECK-NEXT: Check 1: ; CHECK-NEXT: Check 1:
; CHECK-NEXT: Comparing group 0: ; CHECK-NEXT: Comparing group ({{.*}}[[ZERO]]):
; CHECK-NEXT: %storeidx = getelementptr inbounds i16, i16* %a, i64 %store_ind ; CHECK-NEXT: %storeidx = getelementptr inbounds i16, i16* %a, i64 %store_ind
; CHECK-NEXT: Against group 2: ; CHECK-NEXT: Against group ([[TWO:.+]]):
; CHECK-NEXT: %arrayidxA2 = getelementptr i16, i16* %a, i64 %ind2 ; CHECK-NEXT: %arrayidxA2 = getelementptr i16, i16* %a, i64 %ind2
; CHECK-NEXT: Grouped accesses: ; CHECK-NEXT: Grouped accesses:
; CHECK-NEXT: Group 0: ; CHECK-NEXT: Group {{.*}}[[ZERO]]:
; CHECK-NEXT: (Low: ((2 * %offset) + %a) High: (9998 + (2 * %offset) + %a)) ; CHECK-NEXT: (Low: ((2 * %offset) + %a) High: (9998 + (2 * %offset) + %a))
; CHECK-NEXT: Member: {((2 * %offset) + %a),+,2}<nsw><%for.body> ; CHECK-NEXT: Member: {((2 * %offset) + %a),+,2}<nsw><%for.body>
; CHECK-NEXT: Group 1: ; CHECK-NEXT: Group {{.*}}[[ONE]]:
; CHECK-NEXT: (Low: %a High: (9998 + %a)) ; CHECK-NEXT: (Low: %a High: (9998 + %a))
; CHECK-NEXT: Member: {%a,+,2}<%for.body> ; CHECK-NEXT: Member: {%a,+,2}<%for.body>
; CHECK-NEXT: Group 2: ; CHECK-NEXT: Group {{.*}}[[TWO]]:
; CHECK-NEXT: (Low: (20000 + %a) High: (29998 + %a)) ; CHECK-NEXT: (Low: (20000 + %a) High: (29998 + %a))
; CHECK-NEXT: Member: {(20000 + %a),+,2}<%for.body> ; CHECK-NEXT: Member: {(20000 + %a),+,2}<%for.body>