From 6f5cc82686d6f25abc3e373b241bc2cb47d87268 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sun, 23 Aug 2009 09:47:37 +0000 Subject: [PATCH] Fix non-determinism in DAGISel emitter. - This manifested as non-determinism in the .inc output in rare cases (when two distinct patterns ended up being equivalent, which is rather rare). That meant the pattern matching was non-deterministic, which could eventually mean the code generator selected different instructions based on the arch. - It's probably worth making the DAGISel ensure a total ordering (or force the user to), but the simple fix here is to totally order the Record* maps based on a unique ID. - PR4672, PR4711. Yay: -- ddunbar@giles:~$ cat ~/llvm.obj.64/lib/Target/*/*.inc | shasum d1099ff34b21459a5a3e7021c225c080e6017ece - ddunbar@giles:~$ cat ~/llvm.obj.ppc/lib/Target/*/*.inc | shasum d1099ff34b21459a5a3e7021c225c080e6017ece - -- git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79846 91177308-0d34-0410-b5e6-96231b3b80d8 --- utils/TableGen/CodeGenDAGPatterns.cpp | 3 +++ utils/TableGen/CodeGenDAGPatterns.h | 16 ++++++++++------ utils/TableGen/Record.cpp | 2 ++ utils/TableGen/Record.h | 9 ++++++++- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/utils/TableGen/CodeGenDAGPatterns.cpp b/utils/TableGen/CodeGenDAGPatterns.cpp index 2f12a6c4cbe..f0a8c4d74ff 100644 --- a/utils/TableGen/CodeGenDAGPatterns.cpp +++ b/utils/TableGen/CodeGenDAGPatterns.cpp @@ -100,6 +100,9 @@ bool isExtVectorInVTs(const std::vector &EVTs) { } // end namespace EEVT. } // end namespace llvm. +bool RecordPtrCmp::operator()(const Record *LHS, const Record *RHS) const { + return LHS->getID() < RHS->getID(); +} /// Dependent variable map for CodeGenDAGPattern variant generation typedef std::map DepVarMap; diff --git a/utils/TableGen/CodeGenDAGPatterns.h b/utils/TableGen/CodeGenDAGPatterns.h index 56dcfcff910..f7198d8ae5b 100644 --- a/utils/TableGen/CodeGenDAGPatterns.h +++ b/utils/TableGen/CodeGenDAGPatterns.h @@ -462,6 +462,10 @@ struct PatternToMatch { std::string getPredicateCheck() const; }; +// Deterministic comparison of Record*. +struct RecordPtrCmp { + bool operator()(const Record *LHS, const Record *RHS) const; +}; class CodeGenDAGPatterns { RecordKeeper &Records; @@ -469,12 +473,12 @@ class CodeGenDAGPatterns { std::vector Intrinsics; std::vector TgtIntrinsics; - std::map SDNodes; - std::map > SDNodeXForms; - std::map ComplexPatterns; - std::map PatternFragments; - std::map DefaultOperands; - std::map Instructions; + std::map SDNodes; + std::map, RecordPtrCmp> SDNodeXForms; + std::map ComplexPatterns; + std::map PatternFragments; + std::map DefaultOperands; + std::map Instructions; // Specific SDNode definitions: Record *intrinsic_void_sdnode; diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index 8f31624644f..d594c9aa09a 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -1319,6 +1319,8 @@ void RecordVal::print(raw_ostream &OS, bool PrintSem) const { if (PrintSem) OS << ";\n"; } +unsigned Record::LastID = 0; + void Record::setName(const std::string &Name) { if (Records.getDef(getName()) == this) { Records.removeDef(getName()); diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index 40c8239b9a3..9415109dbb3 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -1220,6 +1220,10 @@ inline raw_ostream &operator<<(raw_ostream &OS, const RecordVal &RV) { } class Record { + static unsigned LastID; + + // Unique record ID. + unsigned ID; std::string Name; SMLoc Loc; std::vector TemplateArgs; @@ -1227,9 +1231,12 @@ class Record { std::vector SuperClasses; public: - explicit Record(const std::string &N, SMLoc loc) : Name(N), Loc(loc) {} + explicit Record(const std::string &N, SMLoc loc) : + ID(LastID++), Name(N), Loc(loc) {} ~Record() {} + unsigned getID() const { return ID; } + const std::string &getName() const { return Name; } void setName(const std::string &Name); // Also updates RecordKeeper.