@@ -1238,6 +1238,28 @@ std::ostream &operator<<(std::ostream &os, const FlatVariables &r) {
1238
1238
return os;
1239
1239
}
1240
1240
1241
+ bool log_diff_variable (LogLevel level, const FlatVariables &curr,
1242
+ const FlatVariables &prev, std::string &path,
1243
+ uint32_t slot) {
1244
+ const VarLayout &curr_l = curr.var_layout [slot];
1245
+ const VarLayout &prev_l = prev.var_layout [slot];
1246
+
1247
+ if (curr_l.vt != prev_l.vt ){
1248
+ jit_log (level, " %s: The variable type changed from %u to %u." ,
1249
+ path.c_str (), prev_l.vt , curr_l.vt );
1250
+ return false ;
1251
+ }
1252
+ if (curr_l.size_index != prev_l.size_index ){
1253
+ jit_log (level,
1254
+ " %s: The size equivalence class of the variable changed from "
1255
+ " %u to %u." ,
1256
+ path.c_str (), prev_l.size_index , curr_l.size_index );
1257
+ return false ;
1258
+ }
1259
+
1260
+ return true ;
1261
+ }
1262
+
1241
1263
/* *
1242
1264
* Log the difference of the layout nodes at ``index`` for the two FlatVariables.
1243
1265
*/
@@ -1248,6 +1270,28 @@ bool log_diff(LogLevel level, const FlatVariables &curr,
1248
1270
const Layout &prev_l = prev.layout [index ];
1249
1271
index ++;
1250
1272
1273
+ if (curr_l.flags != prev_l.flags ) {
1274
+ jit_log (level, " %s: The flags of this node changed from 0x%lx to 0x%lx" ,
1275
+ path.c_str (), prev_l.flags , curr_l.flags );
1276
+ return false ;
1277
+ }
1278
+
1279
+ if (curr_l.index != prev_l.index ) {
1280
+ jit_log (level,
1281
+ " %s: The index into the array of deduplicated variables "
1282
+ " changed from s%u to s%u. This can occur if two variables "
1283
+ " referred to the same JIT index, but do no longer." ,
1284
+ path.c_str (), prev_l.index , curr_l.index );
1285
+ return false ;
1286
+ }
1287
+
1288
+ if (curr_l.flags & (uint32_t ) LayoutFlag::JitIndex &&
1289
+ !(curr_l.flags & (uint32_t ) LayoutFlag::Literal)) {
1290
+ uint32_t slot = curr_l.index ;
1291
+ if (!log_diff_variable (level, curr, prev, path, slot))
1292
+ return false ;
1293
+ }
1294
+
1251
1295
if (((bool ) curr_l.type != (bool ) prev_l.type ) ||
1252
1296
!(curr_l.type .equal (prev_l.type ))) {
1253
1297
jit_log (level, " %s: The type of this node changed from %s to %s" ,
@@ -1347,6 +1391,13 @@ bool log_diff(LogLevel level, const FlatVariables &curr,
1347
1391
prev.layout .size (), curr.layout .size ());
1348
1392
return false ;
1349
1393
}
1394
+ if (curr.var_layout .size () != prev.var_layout .size ()){
1395
+ jit_log (level,
1396
+ " The number of opaque variables in the input changed from %u "
1397
+ " to %u." ,
1398
+ prev.layout .size (), curr.layout .size ());
1399
+ return false ;
1400
+ }
1350
1401
1351
1402
uint32_t index = 0 ;
1352
1403
std::string path;
@@ -1693,6 +1744,16 @@ nb::object FrozenFunction::operator()(nb::args args, nb::kwargs kwargs) {
1693
1744
// If new variables have been discovered that should be made
1694
1745
// opaque, we repeat traversal of the input to make them opaque.
1695
1746
// This reduces the number of variants that are saved by one.
1747
+ jit_log (LogLevel::Warn,
1748
+ " While traversing the frozen function input, new "
1749
+ " literal variables have been discovered which changed "
1750
+ " from one call to another. These will be made opaque, "
1751
+ " and the input will be traversed again. This will "
1752
+ " incur some overhead. To prevent this, make those "
1753
+ " variables opaque in beforehand. Below, a list of "
1754
+ " variables that changed will be shown." );
1755
+ if (prev_key)
1756
+ log_diff (LogLevel::Warn, *in_variables, *prev_key);
1696
1757
in_variables->release ();
1697
1758
in_variables = std::make_shared<FlatVariables>(
1698
1759
FlatVariables (in_heuristics));
0 commit comments