Bug 793319 - Backport patches to make the output order deterministic. r=rail.
authorRafael Ávila de Espíndola <respindola@mozilla.org>
Mon, 01 Oct 2012 10:40:55 -0400
changeset 108868 42d8a883e361bb9f98638b77ce28164b307a361a
parent 108867 e8f9e7a76efa480f8dd929cf7040fcb611f7b4a5
child 108869 8c035b44ef281990b89576bf1ef90425103c4489
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersrail
bugs793319
milestone18.0a1
Bug 793319 - Backport patches to make the output order deterministic. r=rail.
build/unix/build-clang/build-clang.py
build/unix/build-clang/clang-deterministic.patch
build/unix/build-clang/llvm-deterministic.patch
--- a/build/unix/build-clang/build-clang.py
+++ b/build/unix/build-clang/build-clang.py
@@ -125,16 +125,18 @@ if not os.path.exists(source_dir):
            llvm_source_dir, llvm_revision)
     svn_co("http://llvm.org/svn/llvm-project/cfe/trunk",
            clang_source_dir, llvm_revision)
     svn_co("http://llvm.org/svn/llvm-project/compiler-rt/trunk",
            compiler_rt_source_dir, llvm_revision)
     os.symlink("../../clang", llvm_source_dir + "/tools/clang")
     os.symlink("../../compiler-rt", llvm_source_dir + "/projects/compiler-rt")
     patch("llvm-debug-frame.patch", 1, llvm_source_dir)
+    patch("llvm-deterministic.patch", 1, llvm_source_dir)
+    patch("clang-deterministic.patch", 1, clang_source_dir)
     if not isDarwin:
         patch("old-ld-hack.patch", 1, llvm_source_dir)
         patch("compiler-rt-gnu89-inline.patch", 0, compiler_rt_source_dir)
         patch("no-sse-on-linux.patch", 1, clang_source_dir)
 
 if os.path.exists(build_dir):
     shutil.rmtree(build_dir)
 os.makedirs(build_dir)
new file mode 100644
--- /dev/null
+++ b/build/unix/build-clang/clang-deterministic.patch
@@ -0,0 +1,45 @@
+diff --git a/include/clang/AST/CXXInheritance.h b/include/clang/AST/CXXInheritance.h
+index ee6eba7..87bdbe0 100644
+--- a/include/clang/AST/CXXInheritance.h
++++ b/include/clang/AST/CXXInheritance.h
+@@ -19,7 +19,7 @@
+ #include "clang/AST/DeclCXX.h"
+ #include "clang/AST/Type.h"
+ #include "clang/AST/TypeOrdering.h"
+-#include "llvm/ADT/DenseMap.h"
++#include "llvm/ADT/MapVector.h"
+ #include "llvm/ADT/SmallSet.h"
+ #include "llvm/ADT/SmallVector.h"
+ #include <list>
+@@ -271,15 +271,14 @@ struct UniqueVirtualMethod {
+ /// pair is the virtual method that overrides it (including the
+ /// subobject in which that virtual function occurs).
+ class OverridingMethods {
+-  llvm::DenseMap<unsigned, SmallVector<UniqueVirtualMethod, 4> > 
+-    Overrides;
++  typedef SmallVector<UniqueVirtualMethod, 4> ValuesT;
++  typedef llvm::MapVector<unsigned, ValuesT> MapType;
++  MapType Overrides;
+ 
+ public:
+   // Iterate over the set of subobjects that have overriding methods.
+-  typedef llvm::DenseMap<unsigned, SmallVector<UniqueVirtualMethod, 4> >
+-            ::iterator iterator;
+-  typedef llvm::DenseMap<unsigned, SmallVector<UniqueVirtualMethod, 4> >
+-            ::const_iterator const_iterator;
++  typedef MapType::iterator iterator;
++  typedef MapType::const_iterator const_iterator;
+   iterator begin() { return Overrides.begin(); }
+   const_iterator begin() const { return Overrides.begin(); }
+   iterator end() { return Overrides.end(); }
+@@ -357,8 +356,8 @@ public:
+ /// 0 represents the virtua base class subobject of that type, while
+ /// subobject numbers greater than 0 refer to non-virtual base class
+ /// subobjects of that type.
+-class CXXFinalOverriderMap 
+-  : public llvm::DenseMap<const CXXMethodDecl *, OverridingMethods> { };
++class CXXFinalOverriderMap
++  : public llvm::MapVector<const CXXMethodDecl *, OverridingMethods> { };
+ 
+ /// \brief A set of all the primary bases for a class.
+ class CXXIndirectPrimaryBaseSet
new file mode 100644
--- /dev/null
+++ b/build/unix/build-clang/llvm-deterministic.patch
@@ -0,0 +1,86 @@
+diff --git a/include/llvm/ADT/MapVector.h b/include/llvm/ADT/MapVector.h
+new file mode 100644
+index 0000000..bad207b
+--- /dev/null
++++ b/include/llvm/ADT/MapVector.h
+@@ -0,0 +1,80 @@
++//===- llvm/ADT/MapVector.h - Map with deterministic value order *- C++ -*-===//
++//
++//                     The LLVM Compiler Infrastructure
++//
++// This file is distributed under the University of Illinois Open Source
++// License. See LICENSE.TXT for details.
++//
++//===----------------------------------------------------------------------===//
++//
++// This file implements a map that provides insertion order iteration. The
++// interface is purposefully minimal. The key is assumed to be cheap to copy
++// and 2 copies are kept, one for indexing in a DenseMap, one for iteration in
++// a std::vector.
++//
++//===----------------------------------------------------------------------===//
++
++#ifndef LLVM_ADT_MAPVECTOR_H
++#define LLVM_ADT_MAPVECTOR_H
++
++#include "llvm/ADT/ArrayRef.h"
++#include "llvm/ADT/DenseMap.h"
++#include <vector>
++
++namespace llvm {
++
++/// This class implements a map that also provides access to all stored values
++/// in a deterministic order. The values are kept in a std::vector and the
++/// mapping is done with DenseMap from Keys to indexes in that vector.
++template<typename KeyT, typename ValueT>
++class MapVector {
++  typedef llvm::DenseMap<KeyT, unsigned> MapType;
++  typedef std::vector<std::pair<KeyT, ValueT> > VectorType;
++  typedef typename VectorType::size_type SizeType;
++
++  MapType Map;
++  VectorType Vector;
++
++public:
++  typedef typename VectorType::iterator iterator;
++  typedef typename VectorType::const_iterator const_iterator;
++
++  SizeType size() const {
++    return Vector.size();
++  }
++
++  iterator begin() {
++    return Vector.begin();
++  }
++
++  const_iterator begin() const {
++    return Vector.begin();
++  }
++
++  iterator end() {
++    return Vector.end();
++  }
++
++  const_iterator end() const {
++    return Vector.end();
++  }
++
++  bool empty() const {
++    return Vector.empty();
++  }
++
++  ValueT &operator[](const KeyT &Key) {
++    std::pair<KeyT, unsigned> Pair = std::make_pair(Key, 0);
++    std::pair<typename MapType::iterator, bool> Result = Map.insert(Pair);
++    unsigned &I = Result.first->second;
++    if (Result.second) {
++      Vector.push_back(std::make_pair(Key, ValueT()));
++      I = Vector.size() - 1;
++    }
++    return Vector[I].second;
++  }
++};
++
++}
++
++#endif