@@ -79,19 +79,53 @@ cl::opt<bool>
79
79
#include < unordered_map>
80
80
81
81
const char *KnownInactiveFunctionsStartingWith[] = {
82
- " _ZN4core3fmt" , " _ZN3std2io5stdio6_print" , " f90io" , " $ss5print" ,
82
+ " _ZN4core3fmt" ,
83
+ " _ZN3std2io5stdio6_print" ,
84
+ " f90io" ,
85
+ " $ss5print" ,
83
86
" _ZNSt7__cxx1112basic_string" ,
87
+ " _ZNSt7__cxx1118basic_string" ,
84
88
// ostream generic <<
85
- " _ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_" ,
86
- " _ZSt16__ostream_insert" , " _ZNSo9_M_insert" ,
89
+ " _ZStlsISt11char_traitsIcEERSt13basic_ostream" ,
90
+ " _ZSt16__ostream_insert" ,
91
+ " _ZStlsIwSt11char_traitsIwEERSt13basic_ostream" ,
92
+ " _ZNSo9_M_insert" ,
93
+ // ostream wchar
94
+ " _ZNSt13basic_ostream" ,
87
95
// ostream put
88
96
" _ZNSo3put" ,
97
+ // std::istream: widen_init, get, getline, >>, sync, ignore
98
+ " _ZNKSt5ctypeIcE13_M_widen_init" ,
99
+ " _ZNSi3get" ,
100
+ " _ZNSi7getline" ,
101
+ " _ZNSirsER" ,
102
+ " _ZNSt7__cxx1115basic_stringbuf" ,
103
+ " _ZNSi6ignore" ,
104
+ // std::ios_base
105
+ " _ZNSt8ios_base" ,
106
+ " _ZNSt9basic_ios" ,
107
+ " _ZStorSt13_Ios_OpenmodeS_" ,
108
+ // std::local
109
+ " _ZNSt6locale" ,
110
+ " _ZNKSt6locale4name" ,
111
+ // init
112
+ " _ZStL8__ioinit"
113
+ " _ZNSt9basic_ios" ,
89
114
// std::cout
90
115
" _ZSt4cout" ,
116
+ // std::cin
117
+ " _ZSt3cin" ,
118
+ " _ZNSi10_M_extract" ,
91
119
// generic <<
92
120
" _ZNSolsE" ,
121
+ // std::flush
122
+ " _ZSt5flush" ,
123
+ " _ZNSo5flush" ,
93
124
// std::endl
94
- " _ZNSo5flushEv" , " _ZSt4endl" };
125
+ " _ZSt4endl" ,
126
+ // std::allocator
127
+ " _ZNSaIcE" ,
128
+ };
95
129
96
130
const char *KnownInactiveFunctionsContains[] = {
97
131
" __enzyme_float" , " __enzyme_double" , " __enzyme_integer" ,
@@ -104,6 +138,22 @@ const std::set<std::string> InactiveGlobals = {
104
138
" stderr" ,
105
139
" stdout" ,
106
140
" stdin" ,
141
+ " _ZSt3cin" ,
142
+ " _ZSt4cout" ,
143
+ " _ZSt5wcout" ,
144
+ " _ZSt4cerr" ,
145
+ " _ZTVNSt7__cxx1115basic_stringbufIcSt11char_traitsIcESaIcEEE" ,
146
+ " _ZTVSt15basic_streambufIcSt11char_traitsIcEE" ,
147
+ " _ZTVSt9basic_iosIcSt11char_traitsIcEE" ,
148
+ // istream
149
+ " _ZTVNSt7__cxx1119basic_istringstreamIcSt11char_traitsIcESaIcEEE" ,
150
+ " _ZTTNSt7__cxx1119basic_istringstreamIcSt11char_traitsIcESaIcEEE" ,
151
+ // ostream
152
+ " _ZTVNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEE" ,
153
+ " _ZTTNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEE" ,
154
+ // stringstream
155
+ " _ZTVNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE" ,
156
+ " _ZTTNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE" ,
107
157
};
108
158
109
159
const std::map<std::string, size_t > MPIInactiveCommAllocators = {
@@ -861,7 +911,8 @@ bool ActivityAnalyzer::isConstantValue(TypeResults &TR, Value *Val) {
861
911
862
912
// If this global is unchanging and the internal constant data
863
913
// is inactive, the global is inactive
864
- if (GI->isConstant () && isConstantValue (TR, GI->getInitializer ())) {
914
+ if (GI->isConstant () && GI->hasInitializer () &&
915
+ isConstantValue (TR, GI->getInitializer ())) {
865
916
InsertConstantValue (TR, Val);
866
917
if (EnzymePrintActivity)
867
918
llvm::errs () << " VALUE const global " << *Val
@@ -1136,10 +1187,12 @@ bool ActivityAnalyzer::isConstantValue(TypeResults &TR, Value *Val) {
1136
1187
1137
1188
// If requesting empty unknown functions to be considered inactive,
1138
1189
// abide by those rules
1139
- if (! isCertainPrintMallocOrFree (called) && called->empty () &&
1190
+ if (EnzymeEmptyFnInactive && called->empty () &&
1140
1191
!hasMetadata (called, " enzyme_gradient" ) &&
1141
1192
!hasMetadata (called, " enzyme_derivative" ) &&
1142
- !isa<IntrinsicInst>(op) && EnzymeEmptyFnInactive) {
1193
+ !isAllocationFunction (*called, TLI) &&
1194
+ !isDeallocationFunction (*called, TLI) &&
1195
+ !isa<IntrinsicInst>(op)) {
1143
1196
InsertConstantValue (TR, Val);
1144
1197
insertConstantsFrom (TR, *UpHypothesis);
1145
1198
return true ;
@@ -1816,10 +1869,11 @@ bool ActivityAnalyzer::isInstructionInactiveFromOrigin(TypeResults &TR,
1816
1869
1817
1870
// If requesting empty unknown functions to be considered inactive, abide
1818
1871
// by those rules
1819
- if (! isCertainPrintMallocOrFree (called) && called->empty () &&
1872
+ if (EnzymeEmptyFnInactive && called->empty () &&
1820
1873
!hasMetadata (called, " enzyme_gradient" ) &&
1821
1874
!hasMetadata (called, " enzyme_derivative" ) &&
1822
- !isa<IntrinsicInst>(op) && EnzymeEmptyFnInactive) {
1875
+ !isAllocationFunction (*called, TLI) &&
1876
+ !isDeallocationFunction (*called, TLI) && !isa<IntrinsicInst>(op)) {
1823
1877
if (EnzymePrintActivity)
1824
1878
llvm::errs () << " constant(" << (int )directions << " ) up-emptyconst "
1825
1879
<< *inst << " \n " ;
0 commit comments