Skip to content

Commit

Permalink
[NFC] MIR-Canon: switching to a stable string sorting of instructions.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332191 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
plotfi committed May 13, 2018
1 parent 44156e3 commit d8ca4dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 8 additions & 2 deletions lib/CodeGen/MIRCanonicalizerPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ rescheduleLexographically(std::vector<MachineInstr *> instructions,
std::function<MachineBasicBlock::iterator()> getPos) {

bool Changed = false;
std::map<std::string, MachineInstr *> StringInstrMap;
using StringInstrPair = std::pair<std::string, MachineInstr *>;
std::vector<StringInstrPair> StringInstrMap;

for (auto *II : instructions) {
std::string S;
Expand All @@ -130,9 +131,14 @@ rescheduleLexographically(std::vector<MachineInstr *> instructions,

// Trim the assignment, or start from the begining in the case of a store.
const size_t i = S.find("=");
StringInstrMap.insert({(i == std::string::npos) ? S : S.substr(i), II});
StringInstrMap.push_back({(i == std::string::npos) ? S : S.substr(i), II});
}

std::sort(StringInstrMap.begin(), StringInstrMap.end(),
[](StringInstrPair &a, StringInstrPair &b) {
return (a.first < b.first);
});

for (auto &II : StringInstrMap) {

DEBUG({
Expand Down
7 changes: 4 additions & 3 deletions test/CodeGen/MIR/AArch64/mirCanonIdempotent.mir
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
# These Idempotent instructions are sorted alphabetically (based on after the '=')
# CHECK: %namedVReg4352:gpr64 = MOVi64imm 4617315517961601024
# CHECK: %namedVReg4353:gpr32 = MOVi32imm 408
# CHECK: %namedVReg4354:gpr64all = IMPLICIT_DEF
# CHECK: %namedVReg4355:fpr64 = FMOVDi 20
# CHECK: %namedVReg4356:fpr64 = FMOVDi 112
# CHECK: %namedVReg4354:gpr32 = MOVi32imm 408
# CHECK: %namedVReg4355:gpr64all = IMPLICIT_DEF
# CHECK: %namedVReg4356:fpr64 = FMOVDi 20
# CHECK: %namedVReg4357:fpr64 = FMOVDi 112
...
---
name: Proc8
Expand Down

0 comments on commit d8ca4dd

Please sign in to comment.