-
Notifications
You must be signed in to change notification settings - Fork 10.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[utils/TableGen/X86CompressEVEXTablesEmitter.cpp] Make sure the tablegen output for the checkPredicate
function is deterministic
#84533
[utils/TableGen/X86CompressEVEXTablesEmitter.cpp] Make sure the tablegen output for the checkPredicate
function is deterministic
#84533
Conversation
@llvm/pr-subscribers-backend-x86 Author: Argyrios Kyrtzidis (akyrtzi) ChangesThe output for the Make a change to sort the entries before iterating over them. Full diff: https://github.com/llvm/llvm-project/pull/84533.diff 1 Files Affected:
diff --git a/llvm/utils/TableGen/X86CompressEVEXTablesEmitter.cpp b/llvm/utils/TableGen/X86CompressEVEXTablesEmitter.cpp
index b96d16b9797cf3..326a9dfbcfefaa 100644
--- a/llvm/utils/TableGen/X86CompressEVEXTablesEmitter.cpp
+++ b/llvm/utils/TableGen/X86CompressEVEXTablesEmitter.cpp
@@ -82,15 +82,27 @@ void X86CompressEVEXTablesEmitter::printTable(const std::vector<Entry> &Table,
void X86CompressEVEXTablesEmitter::printCheckPredicate(
const PredicateInstMap &PredicateInsts, raw_ostream &OS) {
+ // Create a sorted list of the map entries so that the tablegen output is
+ // deterministic.
+ typedef std::pair<StringRef, const std::vector<const CodeGenInstruction *> *>
+ PredicateInstsTy;
+ std::vector<PredicateInstsTy> SortedPredicateInsts;
+ for (const auto &[Key, Val] : PredicateInsts) {
+ SortedPredicateInsts.push_back({Key->getValueAsString("CondString"), &Val});
+ }
+ llvm::sort(SortedPredicateInsts,
+ [](const PredicateInstsTy &LHS, const PredicateInstsTy &RHS) {
+ return LHS.first < RHS.first;
+ });
OS << "static bool checkPredicate(unsigned Opc, const X86Subtarget "
"*Subtarget) {\n"
<< " switch (Opc) {\n"
<< " default: return true;\n";
- for (const auto &[Key, Val] : PredicateInsts) {
- for (const auto &Inst : Val)
+ for (const auto &[Key, Val] : SortedPredicateInsts) {
+ for (const auto &Inst : *Val)
OS << " case X86::" << Inst->TheDef->getName() << ":\n";
- OS << " return " << Key->getValueAsString("CondString") << ";\n";
+ OS << " return " << Key << ";\n";
}
OS << " }\n";
|
Not understand. I believe |
It's non-deterministic because the keys are pointer values, so ordering for them is not stable between runs. |
I see. Could we change the type of
where the |
…gen output for the `checkPredicate` function is deterministic The output for the `checkPredicate` function was depending on a `std::map` iteration that was non-deterministic from run to run, because the keys were pointer values. Make a change so that the keys are `StringRef`s so the ordering is stable.
803bd40
to
20c3748
Compare
I like this idea, see updated commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Friendly remind: Need to update the description. |
Updated 👍 |
The output for the
checkPredicate
function was depending on astd::map
iteration that was non-deterministic from run to run, because the keys were pointer values.Make a change so that the keys are
StringRef
s so the ordering is stable.