6
6
#include " backends/p4tools/common/control_plane/symbolic_variables.h"
7
7
#include " backends/p4tools/common/lib/variables.h"
8
8
#include " backends/p4tools/modules/flay/core/control_plane/substitute_variable.h"
9
+ #include " backends/p4tools/modules/flay/core/lib/simplify_expression.h"
9
10
#include " backends/p4tools/modules/flay/core/lib/z3_cache.h"
10
11
#include " ir/irutils.h"
11
12
#include " lib/timer.h"
@@ -290,6 +291,25 @@ Z3ControlPlaneAssignmentSet WildCardMatchEntry::computeZ3ControlPlaneAssignments
290
291
TableConfiguration
291
292
**************************************************************************************************/
292
293
294
+ const IR::Expression *buildKeyMatches (const KeyMap &keyMap) {
295
+ if (keyMap.empty ()) {
296
+ return IR::BoolLiteral::get (false );
297
+ }
298
+ const IR::Expression *hitCondition = nullptr ;
299
+ for (const auto *key : keyMap) {
300
+ const auto *matchExpr = key->computeControlPlaneConstraint ();
301
+ if (hitCondition == nullptr ) {
302
+ hitCondition = matchExpr;
303
+ } else {
304
+ hitCondition = new IR::LAnd (hitCondition, matchExpr);
305
+ }
306
+ }
307
+ // The table can only "hit" when it is actually configured by the control-plane.
308
+ // Pay attention to how we use "toString" for the path name here.
309
+ // We need to match these choices correctly. TODO: Make this very explicit.
310
+ return hitCondition;
311
+ }
312
+
293
313
bool TableConfiguration::CompareTableMatch::operator ()(const TableMatchEntry &left,
294
314
const TableMatchEntry &right) {
295
315
return left.priority () > right.priority ();
@@ -306,10 +326,10 @@ bool TableConfiguration::operator<(const ControlPlaneItem &other) const {
306
326
: typeid (*this ).hash_code () < typeid (other).hash_code ();
307
327
}
308
328
309
- void TableConfiguration::setTableKeyMatch (const IR::Expression *tableKeyMatch ) {
310
- _tableKeyMatch = tableKeyMatch ;
329
+ void TableConfiguration::setTableKeyMatch (const KeyMap &tableKeyMap ) {
330
+ _tableKeyMatch = SimplifyExpression::simplify ( buildKeyMatches (tableKeyMap)) ;
311
331
// When we set the table key match, we also need to recompute the match of all table entries.
312
- auto z3TableKeyMatch = Z3Cache::set (tableKeyMatch );
332
+ auto z3TableKeyMatch = Z3Cache::set (_tableKeyMatch );
313
333
for (const auto &tableMatchEntry : _tableEntries) {
314
334
tableMatchEntry.get ().setZ3Condition (z3TableKeyMatch);
315
335
}
@@ -341,21 +361,21 @@ ControlPlaneAssignmentSet TableConfiguration::computeControlPlaneAssignments() c
341
361
return defaultAssignments;
342
362
}
343
363
344
- // If we have more than kMaxEntriesPerTable entries we give up.
345
- // Set the entries symbolic and assume they can be executed freely.
346
- if (_tableEntries.size () > kMaxEntriesPerTable ) {
347
- for (const auto &[symbol, assignment] : defaultAssignments) {
348
- const auto *symbolicVar =
349
- ToolsVariables::getSymbolicVariable (symbol.get ().type , symbol.get ().label + " *" );
350
- auto it = defaultAssignments.find (symbol);
351
- if (it == defaultAssignments.end ()) {
352
- defaultAssignments.emplace (symbol, *symbolicVar);
353
- } else {
354
- it->second = *symbolicVar;
355
- }
356
- }
357
- return defaultAssignments;
358
- }
364
+ // // If we have more than kMaxEntriesPerTable entries we give up.
365
+ // // Set the entries symbolic and assume they can be executed freely.
366
+ // if (_tableEntries.size() > kMaxEntriesPerTable) {
367
+ // for (const auto &[symbol, assignment] : defaultAssignments) {
368
+ // const auto *symbolicVar =
369
+ // ToolsVariables::getSymbolicVariable(symbol.get().type, symbol.get().label + "*");
370
+ // auto it = defaultAssignments.find(symbol);
371
+ // if (it == defaultAssignments.end()) {
372
+ // defaultAssignments.emplace(symbol, *symbolicVar);
373
+ // } else {
374
+ // it->second = *symbolicVar;
375
+ // }
376
+ // }
377
+ // return defaultAssignments;
378
+ // }
359
379
360
380
for (const auto &tableEntry : _tableEntries) {
361
381
const auto &actionAssignments = tableEntry.get ().actionAssignment ();
@@ -384,10 +404,10 @@ Z3ControlPlaneAssignmentSet TableConfiguration::computeZ3ControlPlaneAssignments
384
404
385
405
// If we have more than kMaxEntriesPerTable entries we give up.
386
406
// Set the entries symbolic and assume they can be executed freely.
387
- if (_tableEntries.size () > kMaxEntriesPerTable ) {
388
- defaultAssignments.setAllSymbolic ();
389
- return defaultAssignments;
390
- }
407
+ // if (_tableEntries.size() > kMaxEntriesPerTable) {
408
+ // defaultAssignments.setAllSymbolic();
409
+ // return defaultAssignments;
410
+ // }
391
411
392
412
Util::ScopedTimer timer (" computeZ3ControlPlaneAssignments" );
393
413
auto z3TableKeyMatchOpt = Z3Cache::get (_tableKeyMatch);
0 commit comments