Skip to content

Commit 1b1f3c2

Browse files
committed
[X86][CodeGen] Remove duplicated code for the table checks, NFCI
1 parent 18fd6df commit 1b1f3c2

File tree

1 file changed

+16
-50
lines changed

1 file changed

+16
-50
lines changed

llvm/lib/Target/X86/X86InstrFoldTables.cpp

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -382,59 +382,25 @@ static const X86MemoryFoldTableEntry BroadcastSizeFoldTable3[] = {
382382
static const X86MemoryFoldTableEntry *
383383
lookupFoldTableImpl(ArrayRef<X86MemoryFoldTableEntry> Table, unsigned RegOp) {
384384
#ifndef NDEBUG
385+
#define CHECK_SORTED_UNIQUE(TABLE) \
386+
assert(llvm::is_sorted(TABLE) && #TABLE " is not sorted"); \
387+
assert(std::adjacent_find(std::begin(Table), std::end(Table)) == \
388+
std::end(Table) && \
389+
#TABLE " is not unique");
390+
385391
// Make sure the tables are sorted.
386392
static std::atomic<bool> FoldTablesChecked(false);
387393
if (!FoldTablesChecked.load(std::memory_order_relaxed)) {
388-
assert(llvm::is_sorted(MemoryFoldTable2Addr) &&
389-
std::adjacent_find(std::begin(MemoryFoldTable2Addr),
390-
std::end(MemoryFoldTable2Addr)) ==
391-
std::end(MemoryFoldTable2Addr) &&
392-
"MemoryFoldTable2Addr is not sorted and unique!");
393-
assert(llvm::is_sorted(MemoryFoldTable0) &&
394-
std::adjacent_find(std::begin(MemoryFoldTable0),
395-
std::end(MemoryFoldTable0)) ==
396-
std::end(MemoryFoldTable0) &&
397-
"MemoryFoldTable0 is not sorted and unique!");
398-
assert(llvm::is_sorted(MemoryFoldTable1) &&
399-
std::adjacent_find(std::begin(MemoryFoldTable1),
400-
std::end(MemoryFoldTable1)) ==
401-
std::end(MemoryFoldTable1) &&
402-
"MemoryFoldTable1 is not sorted and unique!");
403-
assert(llvm::is_sorted(MemoryFoldTable2) &&
404-
std::adjacent_find(std::begin(MemoryFoldTable2),
405-
std::end(MemoryFoldTable2)) ==
406-
std::end(MemoryFoldTable2) &&
407-
"MemoryFoldTable2 is not sorted and unique!");
408-
assert(llvm::is_sorted(MemoryFoldTable3) &&
409-
std::adjacent_find(std::begin(MemoryFoldTable3),
410-
std::end(MemoryFoldTable3)) ==
411-
std::end(MemoryFoldTable3) &&
412-
"MemoryFoldTable3 is not sorted and unique!");
413-
assert(llvm::is_sorted(MemoryFoldTable4) &&
414-
std::adjacent_find(std::begin(MemoryFoldTable4),
415-
std::end(MemoryFoldTable4)) ==
416-
std::end(MemoryFoldTable4) &&
417-
"MemoryFoldTable4 is not sorted and unique!");
418-
assert(llvm::is_sorted(BroadcastFoldTable2) &&
419-
std::adjacent_find(std::begin(BroadcastFoldTable2),
420-
std::end(BroadcastFoldTable2)) ==
421-
std::end(BroadcastFoldTable2) &&
422-
"BroadcastFoldTable2 is not sorted and unique!");
423-
assert(llvm::is_sorted(BroadcastFoldTable3) &&
424-
std::adjacent_find(std::begin(BroadcastFoldTable3),
425-
std::end(BroadcastFoldTable3)) ==
426-
std::end(BroadcastFoldTable3) &&
427-
"BroadcastFoldTable3 is not sorted and unique!");
428-
assert(llvm::is_sorted(BroadcastSizeFoldTable2) &&
429-
std::adjacent_find(std::begin(BroadcastSizeFoldTable2),
430-
std::end(BroadcastSizeFoldTable2)) ==
431-
std::end(BroadcastSizeFoldTable2) &&
432-
"BroadcastSizeFoldTable2 is not sorted and unique!");
433-
assert(llvm::is_sorted(BroadcastSizeFoldTable3) &&
434-
std::adjacent_find(std::begin(BroadcastSizeFoldTable3),
435-
std::end(BroadcastSizeFoldTable3)) ==
436-
std::end(BroadcastSizeFoldTable3) &&
437-
"BroadcastSizeFoldTable3 is not sorted and unique!");
394+
CHECK_SORTED_UNIQUE(MemoryFoldTable2Addr)
395+
CHECK_SORTED_UNIQUE(MemoryFoldTable0)
396+
CHECK_SORTED_UNIQUE(MemoryFoldTable1)
397+
CHECK_SORTED_UNIQUE(MemoryFoldTable2)
398+
CHECK_SORTED_UNIQUE(MemoryFoldTable3)
399+
CHECK_SORTED_UNIQUE(MemoryFoldTable4)
400+
CHECK_SORTED_UNIQUE(BroadcastFoldTable2)
401+
CHECK_SORTED_UNIQUE(BroadcastFoldTable3)
402+
CHECK_SORTED_UNIQUE(BroadcastSizeFoldTable2)
403+
CHECK_SORTED_UNIQUE(BroadcastSizeFoldTable3)
438404
FoldTablesChecked.store(true, std::memory_order_relaxed);
439405
}
440406
#endif

0 commit comments

Comments
 (0)