|
14 | 14 | #include "BinaryFunction.h" |
15 | 15 | #include "DataReader.h" |
16 | 16 | #include "Passes/MCF.h" |
| 17 | +#include "llvm/ADT/edit_distance.h" |
17 | 18 | #include "llvm/ADT/StringRef.h" |
18 | 19 | #include "llvm/DebugInfo/DWARF/DWARFContext.h" |
19 | 20 | #include "llvm/MC/MCAsmInfo.h" |
@@ -2510,32 +2511,8 @@ bool BinaryFunction::hasLayoutChanged() const { |
2510 | 2511 | } |
2511 | 2512 |
|
2512 | 2513 | uint64_t BinaryFunction::getEditDistance() const { |
2513 | | - const auto LayoutSize = BasicBlocksPreviousLayout.size(); |
2514 | | - if (LayoutSize < 2) { |
2515 | | - return 0; |
2516 | | - } |
2517 | | - |
2518 | | - std::vector<std::vector<uint64_t>> ChangeMatrix( |
2519 | | - LayoutSize + 1, std::vector<uint64_t>(LayoutSize + 1)); |
2520 | | - |
2521 | | - for (uint64_t I = 0; I <= LayoutSize; ++I) { |
2522 | | - ChangeMatrix[I][0] = I; |
2523 | | - ChangeMatrix[0][I] = I; |
2524 | | - } |
2525 | | - |
2526 | | - for (uint64_t I = 1; I <= LayoutSize; ++I) { |
2527 | | - for (uint64_t J = 1; J <= LayoutSize; ++J) { |
2528 | | - if (BasicBlocksPreviousLayout[I] != BasicBlocksLayout[J]) { |
2529 | | - ChangeMatrix[I][J] = |
2530 | | - std::min(std::min(ChangeMatrix[I - 1][J], ChangeMatrix[I][J - 1]), |
2531 | | - ChangeMatrix[I - 1][J - 1]) + 1; |
2532 | | - } else { |
2533 | | - ChangeMatrix[I][J] = ChangeMatrix[I - 1][J - 1]; |
2534 | | - } |
2535 | | - } |
2536 | | - } |
2537 | | - |
2538 | | - return ChangeMatrix[LayoutSize][LayoutSize]; |
| 2514 | + return ComputeEditDistance<BinaryBasicBlock *>(BasicBlocksPreviousLayout, |
| 2515 | + BasicBlocksLayout); |
2539 | 2516 | } |
2540 | 2517 |
|
2541 | 2518 | void BinaryFunction::emitBody(MCStreamer &Streamer, bool EmitColdPart) { |
|
0 commit comments