[PATCH] D37246: [PGO] Fixed non-determinism with DenseSet storing function importing info.

Ana Pazos via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 28 20:25:04 PDT 2017


apazos created this revision.

r296498 introduced a DenseSet to store function importing info.

Using this container causes a test failure in
test/Transform/SampleProfile/import.ll when in Reverse Iteration mode.

This patch orders IDs before iterating through this container.

What do you think, Daniel?

Not sure if sorting will cause slow down problem, either we do that or allow
this test to fail in Reverse Iteration mode.


https://reviews.llvm.org/D37246

Files:
  lib/IR/MDBuilder.cpp


Index: lib/IR/MDBuilder.cpp
===================================================================
--- lib/IR/MDBuilder.cpp
+++ lib/IR/MDBuilder.cpp
@@ -62,12 +62,19 @@
   SmallVector<Metadata *, 8> Ops;
   Ops.push_back(createString("function_entry_count"));
   Ops.push_back(createConstant(ConstantInt::get(Int64Ty, Count)));
-  if (Imports)
-    for (auto ID : *Imports)
+  if (Imports) {
+    SmallVector<GlobalValue::GUID, 2> OrderID(Imports->begin(), Imports->end());
+    std::stable_sort(OrderID.begin(), OrderID.end(),
+      [] (GlobalValue::GUID A, GlobalValue::GUID B) {
+        return A < B;});
+    for (auto ID : OrderID) {
       Ops.push_back(createConstant(ConstantInt::get(Int64Ty, ID)));
+    }
+  }
   return MDNode::get(Context, Ops);
 }
 
+
 MDNode *MDBuilder::createFunctionSectionPrefix(StringRef Prefix) {
   return MDNode::get(Context,
                      {createString("function_section_prefix"),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37246.113015.patch
Type: text/x-patch
Size: 925 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170829/c6c99f60/attachment.bin>


More information about the llvm-commits mailing list