46
46
#include " ActivityAnalysis.h"
47
47
#include " Utils.h"
48
48
49
+ #if LLVM_VERSION_MAJOR >= 9
50
+ #include " llvm/Demangle/Demangle.h"
51
+ #endif
52
+
49
53
#include " FunctionUtils.h"
50
54
#include " LibraryFuncs.h"
51
55
#include " TypeAnalysis/TBAA.h"
@@ -79,24 +83,22 @@ cl::opt<bool>
79
83
#include < unordered_map>
80
84
81
85
const char *KnownInactiveFunctionsStartingWith[] = {
82
- " _ZN4core3fmt" ,
83
- " _ZN3std2io5stdio6_print" ,
84
86
" f90io" ,
85
87
" $ss5print" ,
88
+ #if LLVM_VERSION_MAJOR <= 8
89
+ " _ZN4core3fmt" ,
90
+ " _ZN3std2io5stdio6_print" ,
86
91
" _ZNSt7__cxx1112basic_string" ,
87
92
" _ZNSt7__cxx1118basic_string" ,
88
93
" _ZNKSt7__cxx1112basic_string" ,
89
94
" _ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_string" ,
90
- // filebuf
91
95
" _ZNSt12__basic_file" ,
92
96
" _ZNSt15basic_streambufIcSt11char_traits" ,
93
97
" _ZNSt13basic_filebufIcSt11char_traits" ,
94
98
" _ZNSt14basic_ofstreamIcSt11char_traits" ,
95
- // ifstream
96
99
" _ZNSi4readEPcl" ,
97
100
" _ZNKSt14basic_ifstreamIcSt11char_traits" ,
98
101
" _ZNSt14basic_ifstreamIcSt11char_traits" ,
99
- // ostream generic <<
100
102
" _ZNSo5writeEPKcl" ,
101
103
" _ZNSt19basic_ostringstreamIcSt11char_traits" ,
102
104
" _ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istream" ,
@@ -109,42 +111,31 @@ const char *KnownInactiveFunctionsStartingWith[] = {
109
111
" _ZSt16__ostream_insert" ,
110
112
" _ZStlsIwSt11char_traitsIwEERSt13basic_ostream" ,
111
113
" _ZNSo9_M_insert" ,
112
- // ostream wchar
113
114
" _ZNSt13basic_ostream" ,
114
- // ostream put
115
115
" _ZNSo3put" ,
116
- // std::istream: widen_init, get, getline, >>, sync, ignore
117
116
" _ZNKSt5ctypeIcE13_M_widen_init" ,
118
117
" _ZNSi3get" ,
119
118
" _ZNSi7getline" ,
120
119
" _ZNSirsER" ,
121
120
" _ZNSt7__cxx1115basic_stringbuf" ,
122
121
" _ZNSi6ignore" ,
123
- // std::ios_base
124
122
" _ZNSt8ios_base" ,
125
123
" _ZNKSt9basic_ios" ,
126
124
" _ZNSt9basic_ios" ,
127
125
" _ZStorSt13_Ios_OpenmodeS_" ,
128
- // std::local
129
126
" _ZNSt6locale" ,
130
127
" _ZNKSt6locale4name" ,
131
- // init
132
128
" _ZStL8__ioinit"
133
129
" _ZNSt9basic_ios" ,
134
- // std::cout
135
130
" _ZSt4cout" ,
136
- // std::cin
137
131
" _ZSt3cin" ,
138
132
" _ZNSi10_M_extract" ,
139
- // generic <<
140
133
" _ZNSolsE" ,
141
- // std::flush
142
134
" _ZSt5flush" ,
143
135
" _ZNSo5flush" ,
144
- // std::endl
145
136
" _ZSt4endl" ,
146
- // std::allocator
147
137
" _ZNSaIcE" ,
138
+ #endif
148
139
};
149
140
150
141
const char *KnownInactiveFunctionsContains[] = {
@@ -202,6 +193,7 @@ const std::set<std::string> KnownInactiveFunctions = {
202
193
" snprintf" ,
203
194
" sprintf" ,
204
195
" printf" ,
196
+ " fprintf" ,
205
197
" putchar" ,
206
198
" fprintf" ,
207
199
" vprintf" ,
@@ -266,6 +258,32 @@ const std::set<std::string> KnownInactiveFunctions = {
266
258
" logbl" ,
267
259
};
268
260
261
+ const char *DemangledKnownInactiveFunctionsStartingWith[] = {
262
+ " fprintf" ,
263
+ " std::allocator" ,
264
+ " std::string" ,
265
+ " std::cerr" ,
266
+ " std::basic_ios" ,
267
+ " std::basic_istream" ,
268
+ " std::basic_ostream" ,
269
+ " std::basic_ifstream" ,
270
+ " std::basic_ofstream" ,
271
+ " std::basic_filebuf" ,
272
+ " std::basic_streambuf" ,
273
+ " std::istream" ,
274
+ " std::ostream" ,
275
+ " std::ios_base" ,
276
+ " std::locale" ,
277
+ " std::ctype<char>" ,
278
+ " std::__cxx11::basic_string" ,
279
+ " std::__cxx11::basic_ostringstream" ,
280
+ " std::__cxx11::basic_istringstream" ,
281
+ " std::__cxx11::basic_stringbuf" ,
282
+ " std::__basic_file" ,
283
+ " std::__ioinit" ,
284
+ " std::__basic_file" ,
285
+ };
286
+
269
287
// / Is the use of value val as an argument of call CI known to be inactive
270
288
// / This tool can only be used when in DOWN mode
271
289
bool ActivityAnalyzer::isFunctionArgumentConstant (CallInst *CI, Value *val) {
@@ -292,11 +310,28 @@ bool ActivityAnalyzer::isFunctionArgumentConstant(CallInst *CI, Value *val) {
292
310
if (Name == " posix_memalign" )
293
311
return true ;
294
312
313
+ #if LLVM_VERSION_MAJOR >= 9
314
+ std::string demangledName = llvm::demangle (Name.str ());
315
+ auto dName = StringRef (demangledName);
316
+ for (auto FuncName : DemangledKnownInactiveFunctionsStartingWith) {
317
+ if (dName.startswith (FuncName)) {
318
+ return true ;
319
+ }
320
+ }
321
+ if (demangledName == Name.str ()) {
322
+ // Either demangeling failed
323
+ // or they are equal but matching failed
324
+ // if (!Name.startswith("llvm."))
325
+ // llvm::errs() << "matching failed: " << Name.str() << " "
326
+ // << demangledName << "\n";
327
+ }
328
+ #endif
295
329
for (auto FuncName : KnownInactiveFunctionsStartingWith) {
296
330
if (Name.startswith (FuncName)) {
297
331
return true ;
298
332
}
299
333
}
334
+
300
335
for (auto FuncName : KnownInactiveFunctionsContains) {
301
336
if (Name.contains (FuncName)) {
302
337
return true ;
@@ -305,6 +340,7 @@ bool ActivityAnalyzer::isFunctionArgumentConstant(CallInst *CI, Value *val) {
305
340
if (KnownInactiveFunctions.count (Name.str ())) {
306
341
return true ;
307
342
}
343
+
308
344
if (MPIInactiveCommAllocators.find (Name.str ()) !=
309
345
MPIInactiveCommAllocators.end ()) {
310
346
return true ;
@@ -1253,13 +1289,25 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) {
1253
1289
return true ;
1254
1290
}
1255
1291
1292
+ #if LLVM_VERSION_MAJOR >= 9
1293
+ auto dName = demangle (called->getName ().str ());
1294
+ for (auto FuncName : DemangledKnownInactiveFunctionsStartingWith) {
1295
+ if (StringRef (dName).startswith (FuncName)) {
1296
+ InsertConstantValue (TR, Val);
1297
+ insertConstantsFrom (TR, *UpHypothesis);
1298
+ return true ;
1299
+ }
1300
+ }
1301
+ #endif
1302
+
1256
1303
for (auto FuncName : KnownInactiveFunctionsStartingWith) {
1257
1304
if (called->getName ().startswith (FuncName)) {
1258
1305
InsertConstantValue (TR, Val);
1259
1306
insertConstantsFrom (TR, *UpHypothesis);
1260
1307
return true ;
1261
1308
}
1262
1309
}
1310
+
1263
1311
for (auto FuncName : KnownInactiveFunctionsContains) {
1264
1312
if (called->getName ().contains (FuncName)) {
1265
1313
InsertConstantValue (TR, Val);
@@ -1438,6 +1486,14 @@ bool ActivityAnalyzer::isConstantValue(TypeResults const &TR, Value *Val) {
1438
1486
F->getName () == " __fd_sincos_1" ) {
1439
1487
return false ;
1440
1488
}
1489
+ #if LLVM_VERSION_MAJOR >= 9
1490
+ auto dName = demangle (F->getName ().str ());
1491
+ for (auto FuncName : DemangledKnownInactiveFunctionsStartingWith) {
1492
+ if (StringRef (dName).startswith (FuncName)) {
1493
+ return false ;
1494
+ }
1495
+ }
1496
+ #endif
1441
1497
for (auto FuncName : KnownInactiveFunctionsStartingWith) {
1442
1498
if (F->getName ().startswith (FuncName)) {
1443
1499
return false ;
@@ -2008,11 +2064,21 @@ bool ActivityAnalyzer::isInstructionInactiveFromOrigin(TypeResults const &TR,
2008
2064
return true ;
2009
2065
}
2010
2066
2067
+ #if LLVM_VERSION_MAJOR >= 9
2068
+ auto dName = demangle (called->getName ().str ());
2069
+ for (auto FuncName : DemangledKnownInactiveFunctionsStartingWith) {
2070
+ if (StringRef (dName).startswith (FuncName)) {
2071
+ return true ;
2072
+ }
2073
+ }
2074
+ #endif
2075
+
2011
2076
for (auto FuncName : KnownInactiveFunctionsStartingWith) {
2012
2077
if (called->getName ().startswith (FuncName)) {
2013
2078
return true ;
2014
2079
}
2015
2080
}
2081
+
2016
2082
for (auto FuncName : KnownInactiveFunctionsContains) {
2017
2083
if (called->getName ().contains (FuncName)) {
2018
2084
return true ;
0 commit comments