Skip to content

Commit 3e11177

Browse files
committed
[TSAR, Analysis] Fix CallsToPtrArgumentsMemorySources, passes queue.
1 parent 83e9643 commit 3e11177

File tree

13 files changed

+132
-15
lines changed

13 files changed

+132
-15
lines changed

lib/Analysis/Memory/RestrictionArgumentsPass.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <llvm/Analysis/CallGraphSCCPass.h>
1414
#include <llvm/ADT/SCCIterator.h>
1515
#include <llvm/InitializePasses.h>
16+
#include <llvm/IR/GetElementPtrTypeIterator.h>
17+
#include <llvm/IR/Operator.h>
1618

1719
using namespace tsar;
1820
using namespace llvm;
@@ -136,20 +138,15 @@ DenseMap<CallInst*, FunctionCallWithMemorySources> fillCallsToPtrArgumentsMemory
136138
auto& memorySources = WorkPair.mMemorySources;
137139
workList.pop_back();
138140
for (auto* U : I->users()) {
139-
if (auto* GepU = dyn_cast<GetElementPtrInst>(U)) {
141+
if (auto* GepU = dyn_cast<GEPOperator>(U)) {
140142
workList.push_back(ValueWithMemorySources(GepU, memorySources));
141-
}
142-
if (auto* CastI = dyn_cast<CastInst>(U)) {
143+
} else if (auto* CastI = dyn_cast<CastInst>(U)) {
143144
workList.push_back(ValueWithMemorySources(CastI, memorySources));
144-
}
145-
if (auto* SelectI = dyn_cast<SelectInst>(U)) {
145+
} else if (auto* SelectI = dyn_cast<SelectInst>(U)) {
146146
workList.push_back(ValueWithMemorySources(SelectI, memorySources));
147-
}
148-
// for the new malloc behaviour
149-
if (auto* LoadI = dyn_cast<LoadInst>(U)) {
147+
} else if (auto* LoadI = dyn_cast<LoadInst>(U)) {
150148
workList.push_back(ValueWithMemorySources(LoadI, memorySources));
151-
}
152-
if (auto* CallI = dyn_cast<CallInst>(U)) {
149+
} else if (auto* CallI = dyn_cast<CallInst>(U)) {
153150
if (TargetFunctionsCalls.count(CallI)) {
154151
LLVM_DEBUG(
155152
dbgs() << "\tFound CallInst in TargetCalls: ";

lib/Core/Query.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ void addAfterSROAAnalysis(const GlobalOptions &GO, const DataLayout &DL,
143143
Passes.add(createGlobalLiveMemoryPass());
144144
Passes.add(createFunctionMemoryAttrsAnalysis());
145145
Passes.add(createDIDependencyAnalysisPass());
146+
Passes.add(createRestrictionArgumentsPass());
146147
}
147148

148149
void addAfterLoopRotateAnalysis(legacy::PassManager &Passes) {
@@ -270,7 +271,6 @@ void DefaultQueryManager::run(llvm::Module *M, TransformationContext *Ctx) {
270271
// avoid dangling handles. So, we add pool before environment in the manager.
271272
Passes.add(createDIMemoryTraitPoolStorage());
272273
Passes.add(createDIMemoryEnvironmentStorage());
273-
Passes.add(createRestrictionArgumentsPass());
274274
#ifdef APC_FOUND
275275
Passes.add(createAPCContextStorage());
276276
addIfNecessary(createAPCLoopInfoBasePass(), mPrintPasses,
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#include <stdlib.h>
22

3-
int b[10][20];
3+
int b[10];
44

55
int foo(int *a, int* b) {
66
return a[0] + b[0];
77
}
88

99
int main(int argc, char const *argv[]) {
1010
int *a = malloc(sizeof(int) * 5);
11-
return foo(a, b[0]);
11+
return foo(a[2], b);
1212
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include <stdlib.h>
2+
3+
int b[10];
4+
5+
int foo(int *a, int* b) {
6+
return a[0] + b[0];
7+
}
8+
9+
int main(int argc, char const *argv[]) {
10+
int (*a)[10] = malloc(sizeof(int) * 10 * 20);
11+
return foo(a[2], b);
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <stdlib.h>
2+
3+
int b[10][20];
4+
5+
int foo(int *a, int* b) {
6+
return a[0] + b[0];
7+
}
8+
9+
int main(int argc, char const *argv[]) {
10+
int *a1 = malloc(sizeof(int) * 5);
11+
int (*a2)[10] = malloc(sizeof(int) * 10 * 20);
12+
return foo(a1, b) + foo(a2[2], b);
13+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <stdlib.h>
2+
3+
int (*b)[10];
4+
5+
int foo(int *a, int* b) {
6+
return a[0] + bar(a, b);
7+
}
8+
9+
int bar(int *a, int* b) {
10+
return a[5] + 5 + b[7];
11+
}
12+
13+
int main(int argc, char const *argv[]) {
14+
int (*a)[10] = malloc(sizeof(int) * 10 * 20);
15+
b = malloc(sizeof(int) * 10 * 20);
16+
return foo(a[2], b[3]);
17+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <stdlib.h>
2+
3+
int (*b)[10];
4+
int *a1;
5+
int (*a2)[10];
6+
7+
int foo(int *a, int* b) {
8+
return a[0] + bar(a, b);
9+
}
10+
11+
int bar(int *a, int* b) {
12+
return a[5] + 5 + b[7];
13+
}
14+
15+
int main(int argc, char const *argv[]) {
16+
a1 = malloc(sizeof(int) * 5);
17+
a2 = malloc(sizeof(int) * 10 * 20);
18+
b = malloc(sizeof(int) * 10 * 20);
19+
return foo(a1, b[3]) + foo(a2[2], b[3]);
20+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <stdlib.h>
2+
3+
int f2(char *a, char* b) {
4+
return a[0] + b[0] + 2;
5+
}
6+
7+
int foo(char *a, char* b, char* c) {
8+
return f2(a, c) + f2(b, c);
9+
}
10+
11+
char *bar() {
12+
return "BARRRR";
13+
}
14+
15+
char *yaf() {
16+
return "YAFFFF";
17+
}
18+
19+
int main(int argc, char const *argv[]) {
20+
char *a = bar();
21+
22+
char *b = bar();
23+
24+
char *c = yaf();
25+
//Not restrict calls:
26+
int r1 = foo(a, b, c);
27+
28+
return r1;
29+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <stdlib.h>
2+
3+
int f2(int *a, int* b) {
4+
return a[0] + b[0] + 2;
5+
}
6+
7+
int* f3(int *a, int* b) {
8+
return a + 1;
9+
}
10+
11+
int f1(int *a, int* b) {
12+
return f2(f3(a, b), a);
13+
}
14+
15+
int main(int argc, char const *argv[]) {
16+
int *a = malloc(sizeof(int) * 5);
17+
int b[10];
18+
a[0] = 5;
19+
a[1] = 6;
20+
a[2] = 7;
21+
b[0] = 10;
22+
b[1] = 20;
23+
b[2] = 30;
24+
25+
return f1(a, b);
26+
}

0 commit comments

Comments
 (0)