forked from OSchip/llvm-project
[DFAJumpThreading] make update order deterministic
We tracked down some non-determinism in compilation output to the DFAJumpThreading pass. These changes fixed our issue: * Make the DefMap type a MapVector to make its iteration order depend on insertion order. * Sort the values to be inserted into NewDefs by instruction order to make the insertion order deterministic. Since these values come from iterating over a ValueMap, which doesn't have deterministic iteration order, I couldn't fix this at its source. Reviewed By: alexey.zhikhar Differential Revision: https://reviews.llvm.org/D118590
This commit is contained in:
parent
22d3bbdf4e
commit
9d555b4a83
|
@ -357,7 +357,7 @@ typedef DenseMap<BasicBlock *, CloneList> DuplicateBlockMap;
|
||||||
|
|
||||||
// This map keeps track of all the new definitions for an instruction. This
|
// This map keeps track of all the new definitions for an instruction. This
|
||||||
// information is needed when restoring SSA form after cloning blocks.
|
// information is needed when restoring SSA form after cloning blocks.
|
||||||
typedef DenseMap<Instruction *, std::vector<Instruction *>> DefMap;
|
typedef MapVector<Instruction *, std::vector<Instruction *>> DefMap;
|
||||||
|
|
||||||
inline raw_ostream &operator<<(raw_ostream &OS, const PathType &Path) {
|
inline raw_ostream &operator<<(raw_ostream &OS, const PathType &Path) {
|
||||||
OS << "< ";
|
OS << "< ";
|
||||||
|
@ -1126,6 +1126,9 @@ private:
|
||||||
/// Add new value mappings to the DefMap to keep track of all new definitions
|
/// Add new value mappings to the DefMap to keep track of all new definitions
|
||||||
/// for a particular instruction. These will be used while updating SSA form.
|
/// for a particular instruction. These will be used while updating SSA form.
|
||||||
void updateDefMap(DefMap &NewDefs, ValueToValueMapTy &VMap) {
|
void updateDefMap(DefMap &NewDefs, ValueToValueMapTy &VMap) {
|
||||||
|
SmallVector<std::pair<Instruction *, Instruction *>> NewDefsVector;
|
||||||
|
NewDefsVector.reserve(VMap.size());
|
||||||
|
|
||||||
for (auto Entry : VMap) {
|
for (auto Entry : VMap) {
|
||||||
Instruction *Inst =
|
Instruction *Inst =
|
||||||
dyn_cast<Instruction>(const_cast<Value *>(Entry.first));
|
dyn_cast<Instruction>(const_cast<Value *>(Entry.first));
|
||||||
|
@ -1138,11 +1141,18 @@ private:
|
||||||
if (!Cloned)
|
if (!Cloned)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (NewDefs.find(Inst) == NewDefs.end())
|
NewDefsVector.push_back({Inst, Cloned});
|
||||||
NewDefs[Inst] = {Cloned};
|
|
||||||
else
|
|
||||||
NewDefs[Inst].push_back(Cloned);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort the defs to get deterministic insertion order into NewDefs.
|
||||||
|
sort(NewDefsVector, [](const auto &LHS, const auto &RHS) {
|
||||||
|
if (LHS.first == RHS.first)
|
||||||
|
return LHS.second->comesBefore(RHS.second);
|
||||||
|
return LHS.first->comesBefore(RHS.first);
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const auto &KV : NewDefsVector)
|
||||||
|
NewDefs[KV.first].push_back(KV.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the last branch of a particular cloned path to point to the correct
|
/// Update the last branch of a particular cloned path to point to the correct
|
||||||
|
|
Loading…
Reference in New Issue