Rename llvm-uselistorder => verify-uselistorder
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 30 Jul 2014 17:11:27 +0000 (17:11 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Wed, 30 Jul 2014 17:11:27 +0000 (17:11 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@214318 91177308-0d34-0410-b5e6-96231b3b80d8

51 files changed:
test/Bitcode/2006-12-11-Cast-ConstExpr.ll
test/Bitcode/2009-06-11-FirstClassAggregateConstant.ll
test/Bitcode/aggregateInstructions.3.2.ll
test/Bitcode/arm32_neon_vcnt_upgrade.ll
test/Bitcode/atomic.ll
test/Bitcode/attributes-3.3.ll
test/Bitcode/attributes.ll
test/Bitcode/binaryFloatInstructions.3.2.ll
test/Bitcode/binaryIntInstructions.3.2.ll
test/Bitcode/bitwiseInstructions.3.2.ll
test/Bitcode/calling-conventions.3.2.ll
test/Bitcode/case-ranges-3.3.ll
test/Bitcode/cmpxchg-upgrade.ll
test/Bitcode/conversionInstructions.3.2.ll
test/Bitcode/drop-debug-info.ll
test/Bitcode/extractelement.ll
test/Bitcode/flags.ll
test/Bitcode/function-encoding-rel-operands.ll
test/Bitcode/global-variables.3.2.ll
test/Bitcode/inalloca.ll
test/Bitcode/linkage-types-3.2.ll
test/Bitcode/local-linkage-default-visibility.3.4.ll
test/Bitcode/memInstructions.3.2.ll
test/Bitcode/metadata.ll
test/Bitcode/old-aliases.ll
test/Bitcode/ptest-new.ll
test/Bitcode/ptest-old.ll
test/Bitcode/select.ll
test/Bitcode/shuffle.ll
test/Bitcode/tailcall.ll
test/Bitcode/terminatorInstructions.3.2.ll
test/Bitcode/upgrade-global-ctors.ll
test/Bitcode/upgrade-loop-metadata.ll
test/Bitcode/upgrade-tbaa.ll
test/Bitcode/use-list-order.ll
test/Bitcode/vectorInstructions.3.2.ll
test/Bitcode/visibility-styles.3.2.ll
test/Bitcode/weak-cmpxchg-upgrade.ll
test/CMakeLists.txt
test/lit.cfg
tools/CMakeLists.txt
tools/LLVMBuild.txt
tools/Makefile
tools/llvm-uselistorder/CMakeLists.txt [deleted file]
tools/llvm-uselistorder/LLVMBuild.txt [deleted file]
tools/llvm-uselistorder/Makefile [deleted file]
tools/llvm-uselistorder/llvm-uselistorder.cpp [deleted file]
tools/verify-uselistorder/CMakeLists.txt [new file with mode: 0644]
tools/verify-uselistorder/LLVMBuild.txt [new file with mode: 0644]
tools/verify-uselistorder/Makefile [new file with mode: 0644]
tools/verify-uselistorder/verify-uselistorder.cpp [new file with mode: 0644]

index e1e2d7dc5447b905de5560f3c64bd26b8ae00773..461a92a84a1ab6f91060afae6e6795e5dc633419 100644 (file)
@@ -1,7 +1,7 @@
 ; This test ensures that we get a bitcast constant expression in and out,
 ; not a sitofp constant expression. 
 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 ; CHECK: bitcast (
 
 @G = external global i32
index a321ce213113c4e5cdad20b191bbdfbc9c4192e4..16f7e9ab9ae5c4e7a485bf3f59e8cf8458fe05a7 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-as < %s | llvm-dis -disable-output
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 ; PR4373
 
 @foo = weak global { i32 } zeroinitializer              
index 4d35be08bd12e62cb646a52bfd1faeb007190559..2853823f1c9b7ad80d9139b7c06235b92ad678f5 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-dis < %s.bc| FileCheck %s
-; RUN: llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; aggregateOperations.3.2.ll.bc was generated by passing this file to llvm-as-3.2.
 ; The test checks that LLVM does not misread instructions with aggregate operands
index fba518fe7f7f002a17f816c2592abb285de05dcd..c1eba948b6bd45714b725febad2fc6bdf87b6762 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 ; Tests vclz and vcnt
 
 define <4 x i16> @vclz16(<4 x i16>* %A) nounwind {
index 448219a59cb4c3928a68601d2aaa8c7966afcbbe..bccb868653cbbff500fb6459d98c655758968e7a 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-as %s -o - | llvm-dis | FileCheck %s
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 
 define void @test_cmpxchg(i32* %addr, i32 %desired, i32 %new) {
   cmpxchg i32* %addr, i32 %desired, i32 %new seq_cst seq_cst
index 7b44938a3e828bba995761b061fed7e9f02cbe9a..359d7ce38758ddf8aa87d7edf17c54009dc4d802 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN:  llvm-dis < %s.bc| FileCheck %s
-; RUN:  llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN:  verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; attributes-3.3.ll.bc was generated by passing this file to llvm-as-3.3.
 ; The test checks that LLVM does not silently misread attributes of
index 0fe66f5ad82cf95b53ed42a5351b9c83b77f651f..8286e396adf26655d8425da4d1f341575bde5389 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 ; PR12696
 
 define void @f1(i8 zeroext)
index a0010e03834df605e222be2c3425cbf9bcd23760..4df571094350a96e55cc1a9baedf8a08731ddb97 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-dis < %s.bc| FileCheck %s
-; RUN: llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; BinaryFloatOperation.3.2.ll.bc was generated by passing this file to llvm-as-3.2.
 ; The test checks that LLVM does not misread binary float instructions from
index bcf3d5882e05dfe1d256d34d62ea5a278541ae78..4559b4f4526acfa126182cd8136704ebfeda15cb 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-dis < %s.bc| FileCheck %s
-; RUN: llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; BinaryIntOperation.3.2.ll.bc was generated by passing this file to llvm-as-3.2.
 ; The test checks that LLVM does not misread binary integer instructions from
index 780f0447a52c6cbc6b95514b041eb9fee279df21..f6d46577d97ee2ce7fdc08400c8d656c1c2c5351 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-dis < %s.bc| FileCheck %s
-; RUN: llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; bitwiseOperations.3.2.ll.bc was generated by passing this file to llvm-as-3.2.
 ; The test checks that LLVM does not misread bitwise instructions from
index 6a497dc8d5a862a957736d20b4c60f7f05cbd532..e1f1634949979243dc25ce5ebd87ff451d3f4128 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN:  llvm-dis < %s.bc| FileCheck %s
-; RUN:  llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN:  verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; calling-conventions.3.2.ll.bc was generated by passing this file to llvm-as-3.2.
 ; The test checks that LLVM does not silently misread calling conventions of
index 1198f2bb2cb8bed65687b58d042171b451628dff..eaab6ec58237176d2d70365d3f5ecdc955985779 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN:  llvm-dis < %s.bc| FileCheck %s
-; RUN:  llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN:  verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; case-ranges.ll.bc was generated by passing this file to llvm-as from the 3.3
 ; release of LLVM. This tests that the bitcode for switches from that release
index 94f0eef455e6e5f7cef283f06050f43557c61a50..2a69ec5db5b97597d760f8b8801b7f9228cbdefa 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-dis < %s.bc | FileCheck %s
-; RUN: llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; cmpxchg-upgrade.ll.bc was produced by running a version of llvm-as from just
 ; before the IR change on this file.
index 9f8204821d4d64adf26857e4f9c82d38533b5d90..550d44349e75d7a83ed58b02becb7875d4cfe437 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-dis < %s.bc| FileCheck %s
-; RUN: llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; conversionOperations.3.2.ll.bc was generated by passing this file to llvm-as-3.2.
 ; The test checks that LLVM does not misread conversion instructions from
index b3073e0d6c8b709d2b292aaac2d48783979e74da..ee860115a8300c216ea9274978b7cc1e5b7cc30e 100644 (file)
@@ -1,6 +1,6 @@
 ; RUN: llvm-as < %s -o %t.bc 2>&1 >/dev/null | FileCheck -check-prefix=WARN %s
 ; RUN: llvm-dis < %t.bc | FileCheck %s
-; RUN: llvm-uselistorder < %t.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %t.bc -preserve-bc-use-list-order -num-shuffles=5
 
 define i32 @main() {
 entry:
index 29f5b029200cad4165e5b7e4eae38b74ca19ff53..ba806a4e3f252f541be01eead7dd6cd21348e42a 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: opt < %s -constprop | llvm-dis -disable-output
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 ; PR3465
 
 define double @test() {
index 3760a44bd6fd446c6b436c58196b9af65a450956..a996a8a8f8df743f3ee5b1b69ff5fc59e9c34121 100644 (file)
@@ -1,7 +1,7 @@
 ; RUN: llvm-as < %s | llvm-dis > %t0
 ; RUN: opt -S < %s > %t1
 ; RUN: diff %t0 %t1
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 ; PR6140
 
 ; Make sure the flags are serialized/deserialized properly for both
index cc2f6aef5e5b7c5e8431fae1aa851d9ee0a268d1..14aa01fc1d9448d989919f434fe7e7b13bc45438 100644 (file)
@@ -1,7 +1,7 @@
 ; Basic sanity test to check that instruction operands are encoded with
 ; relative IDs.
 ; RUN: llvm-as < %s | llvm-bcanalyzer -dump | FileCheck %s
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 
 ; CHECK: FUNCTION_BLOCK
 ; CHECK: INST_BINOP {{.*}}op0=1 op1=1
index 4a856f199e58b99be6405d0341e1b2fc724b739d..cbba464a2983ac81135ff5102ab6e52de25da7c1 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN:  llvm-dis < %s.bc| FileCheck %s
-; RUN:  llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN:  verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; global-variables.3.2.ll.bc was generated by passing this file to llvm-as-3.2.
 ; The test checks that LLVM does not silently misread global variables attributes of
index 445b4a282bff09992dd1075f09a278b018cbaa41..386a476b4551c503a3e4eaadfd4418c21ada519e 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 
 ; inalloca should roundtrip.
 
index 01b195f6c51a7c483d3d677bdb3ee1895d4af2f9..06e81b949f172aa02d42548910396792e6945aaf 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN:  llvm-dis < %s.bc| FileCheck %s
-; RUN:  llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN:  verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; linkage-types-3.2.ll.bc was generated by passing this file to llvm-as-3.2
 ; The test checks that LLVM does not silently misread linkage types of
index c1a9fbefe69a7420f25895e01f3a44c9b89f59e8..f72fd1578e83c1789a97caf93604bfdcbd0c609c 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-dis < %s.bc | FileCheck %s
-; RUN: llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; local-linkage-default-visibility.3.4.ll.bc was generated by passing this file
 ; to llvm-as-3.4.  The test checks that LLVM upgrades visibility of symbols
index a8073225a69c7a9392e5de538bf6bb089da58eb8..67d24f41a10711261649087bdb9c35be420548a8 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-dis < %s.bc| FileCheck %s
-; RUN: llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; memOperations.3.2.ll.bc was generated by passing this file to llvm-as-3.2.
 ; The test checks that LLVM does not misread memory related instructions of
index a3550bcaceca9671f415777735ac9a1c70dcad0c..1ceb606dd18bf3519186984a0e29c66624b673ba 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-as < %s | llvm-dis -disable-output
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 
 !llvm.foo = !{!0}
 !0 = metadata !{i32 42}
index 13b6d3efa2330a628e1186a99dc8c82384642698..b32bc1b18cd16a57e7a1ac00957a7424075b9dd1 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-dis < %s.bc | FileCheck %s
-; RUN: llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; old-aliases.bc consist of this file assembled with an old llvm-as (3.5 trunk)
 ; from when aliases contained a ConstantExpr.
index c0ded8b622c09e589758ebf1b922740e73cd34c9..ff2848141896b5403047771a8ff73773bc84e7ed 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 
 define i32 @foo(<2 x i64> %bar) nounwind {
 entry:
index c6c160539c2174c590e220425adf43db5c9f21e4..5f252aabf7376633ed856dead13dc01385988f4f 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 
 define i32 @foo(<4 x float> %bar) nounwind {
 entry:
index 3da538578706a837ef56614d83999116c9f9dfa3..a33926c28295358855367f95d10b25eb363cae7a 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 
 define <2 x i32> @main() {
   ret <2 x i32> select (<2 x i1> <i1 false, i1 undef>, <2 x i32> zeroinitializer, <2 x i32> <i32 0, i32 undef>)
index 65bde6765c26cf3004b76ca33386a525dd1edb3b..5b0e9e70e44042328837f4f94b3ec26cd5601f87 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-as < %s | llvm-dis -disable-output
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 
 ; <rdar://problem/8622574>
 ; tests the bitcodereader can handle the case where the reader will initially
index ea47df62011a81f2ae240c356060f447efa323bd..5eed7a3957422cfdbfa5e2a166ecc6980b1fe16d 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 
 ; Check that musttail and tail roundtrip.
 
index d9e51a5996e895064eb0f4d3e34c358456df183e..a2285a13871a2c5c2e0d70e2598ddc018f9dd03e 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-dis < %s.bc| FileCheck %s
-; RUN: llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; TerminatorOperations.3.2.ll.bc was generated by passing this file to llvm-as-3.2.
 ; The test checks that LLVM does not misread terminator instructions from
index f75b28b7db1ef29d5e12b8d6365f32ed634b0442..b01c7520c95a269cf3ef436a2bb043d9b5000b4a 100644 (file)
@@ -1,4 +1,4 @@
 ; RUN:  llvm-dis < %s.bc| FileCheck %s
-; RUN:  llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN:  verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; CHECK: @llvm.global_ctors = appending global [0 x { i32, void ()*, i8* }] zeroinitializer
index 5c18bd930cc21a73a18b502f2f0ec9825509063c..3c1db98273a39286ca5f8b8d670ce982fbcb8e77 100644 (file)
@@ -1,7 +1,7 @@
 ; Test to make sure loop vectorizer metadata is automatically upgraded.
 ;
 ; RUN: llvm-dis < %s.bc | FileCheck %s
-; RUN: llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 define void @_Z28loop_with_vectorize_metadatav() {
 entry:
index 0d88fa6ce3a730fc7ee357fa2c8ae0f84e231085..8dd3b695a67f2599bbcc5baf0175509bb4ec1e61 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-as < %s | llvm-dis | FileCheck %s
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 
 ; Function Attrs: nounwind
 define void @_Z4testPiPf(i32* nocapture %pI, float* nocapture %pF) #0 {
index 33cc13edb05ab7675a81a4e779199c125feffea1..bb71a8586b73efec2d04df3a101c29f1bb73e94e 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llvm-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s -preserve-bc-use-list-order -num-shuffles=5
 
 @a = global [4 x i1] [i1 0, i1 1, i1 0, i1 1]
 @b = alias i1* getelementptr ([4 x i1]* @a, i64 0, i64 2)
index 5b983ac0f02ed2d41b587ebdb86513c676dda700..4daae4187226765f0514a72d50b3b0cc4fdedcb8 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-dis < %s.bc| FileCheck %s
-; RUN: llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; vectorOperations.3.2.ll.bc was generated by passing this file to llvm-as-3.2.
 ; The test checks that LLVM does not misread vector operations of
index cccc9509e67a8fd233bfbe3b030a3a78910d86c6..aecbc6562cd731d07048ebe13652b2e057dddaea 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN:  llvm-dis < %s.bc| FileCheck %s
-; RUN:  llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN:  verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; visibility-styles.3.2.ll.bc was generated by passing this file to llvm-as-3.2.
 ; The test checks that LLVM does not silently misread visibility styles of
index fd543c4a96856979d0ad507cc0d614d5656c943e..a09efc70992d460ecbafae85eb439c82d00dc930 100644 (file)
@@ -1,5 +1,5 @@
 ; RUN: llvm-dis < %s.bc | FileCheck %s
-; RUN: llvm-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
+; RUN: verify-uselistorder < %s.bc -preserve-bc-use-list-order -num-shuffles=5
 
 ; cmpxchg-upgrade.ll.bc was produced by running a version of llvm-as from just
 ; before the IR change on this file.
index 59a17b1950680d1481bcd622076fa84b6fa08593..2b3a618a3aede2a9dff4792cbec1d77918175aa6 100644 (file)
@@ -44,7 +44,6 @@ set(LLVM_TEST_DEPENDS
           llvm-rtdyld
           llvm-symbolizer
           llvm-tblgen
-          llvm-uselistorder
           llvm-vtabledump
           macho-dump
           opt
@@ -53,6 +52,7 @@ set(LLVM_TEST_DEPENDS
           not
           yaml2obj
           obj2yaml
+          verify-uselistorder
         )
 
 # If Intel JIT events are supported, depend on a tool that tests the listener.
index 6f2632cba5dd2b6837587b7b8267a200892ef560..b5a982c02d5b234c9764bac540534753d6e40d87 100644 (file)
@@ -228,7 +228,6 @@ for pattern in [r"\bbugpoint\b(?!-)",
                 r"\bllvm-rtdyld\b",
                 r"\bllvm-size\b",
                 r"\bllvm-tblgen\b",
-                r"\bllvm-uselistorder\b",
                 r"\bllvm-vtabledump\b",
                 r"\bllvm-c-test\b",
                 r"\bmacho-dump\b",
@@ -236,6 +235,7 @@ for pattern in [r"\bbugpoint\b(?!-)",
                 r"\bFileCheck\b",
                 r"\bobj2yaml\b",
                 r"\byaml2obj\b",
+                r"\bverify-uselistorder\b",
                 # Handle these specially as they are strings searched
                 # for during testing.
                 r"\| \bcount\b",
index ef8095b688e1cf17654a08160b93b8e4a1bd3807..940f656b5980a756fb93eda1e12cc0a9b5ee8c02 100644 (file)
@@ -43,7 +43,7 @@ add_llvm_tool_subdirectory(llvm-bcanalyzer)
 add_llvm_tool_subdirectory(llvm-stress)
 add_llvm_tool_subdirectory(llvm-mcmarkup)
 
-add_llvm_tool_subdirectory(llvm-uselistorder)
+add_llvm_tool_subdirectory(verify-uselistorder)
 
 add_llvm_tool_subdirectory(llvm-symbolizer)
 
index 92c7d2b409469d4a47be9353bdda3ddce0feab85..13a08b2d4499581281e8cb6e8ee430cf27f4f0e9 100644 (file)
@@ -16,7 +16,7 @@
 ;===------------------------------------------------------------------------===;
 
 [common]
-subdirectories = bugpoint llc lli llvm-ar llvm-as llvm-bcanalyzer llvm-cov llvm-diff llvm-dis llvm-dwarfdump llvm-extract llvm-jitlistener llvm-link llvm-lto llvm-mc llvm-nm llvm-objdump llvm-profdata llvm-rtdyld llvm-size macho-dump opt llvm-mcmarkup llvm-uselistorder
+subdirectories = bugpoint llc lli llvm-ar llvm-as llvm-bcanalyzer llvm-cov llvm-diff llvm-dis llvm-dwarfdump llvm-extract llvm-jitlistener llvm-link llvm-lto llvm-mc llvm-nm llvm-objdump llvm-profdata llvm-rtdyld llvm-size macho-dump opt llvm-mcmarkup verify-uselistorder
 
 [component_0]
 type = Group
index ed7773d61fad3dae605c320161757599a7c2f305..9ba4608ecade34d729622b4f1487632c7802098d 100644 (file)
@@ -32,7 +32,7 @@ PARALLEL_DIRS := opt llvm-as llvm-dis llc llvm-ar llvm-nm llvm-link \
                  macho-dump llvm-objdump llvm-readobj llvm-rtdyld \
                  llvm-dwarfdump llvm-cov llvm-size llvm-stress llvm-mcmarkup \
                  llvm-profdata llvm-symbolizer obj2yaml yaml2obj llvm-c-test \
-                 llvm-vtabledump llvm-uselistorder
+                 llvm-vtabledump verify-uselistorder
 
 # If Intel JIT Events support is configured, build an extra tool to test it.
 ifeq ($(USE_INTEL_JITEVENTS), 1)
diff --git a/tools/llvm-uselistorder/CMakeLists.txt b/tools/llvm-uselistorder/CMakeLists.txt
deleted file mode 100644 (file)
index c08f8c3..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-set(LLVM_LINK_COMPONENTS
-  AsmParser
-  BitReader
-  BitWriter
-  Core
-  IRReader
-  Support
-  )
-
-add_llvm_tool(llvm-uselistorder
-  llvm-uselistorder.cpp
-  )
diff --git a/tools/llvm-uselistorder/LLVMBuild.txt b/tools/llvm-uselistorder/LLVMBuild.txt
deleted file mode 100644 (file)
index b9d6f10..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-;===- ./tools/llvm-uselistorder/LLVMBuild.txt ------------------*- Conf -*--===;
-;
-;                     The LLVM Compiler Infrastructure
-;
-; This file is distributed under the University of Illinois Open Source
-; License. See LICENSE.TXT for details.
-;
-;===------------------------------------------------------------------------===;
-;
-; This is an LLVMBuild description file for the components in this subdirectory.
-;
-; For more information on the LLVMBuild system, please see:
-;
-;   http://llvm.org/docs/LLVMBuild.html
-;
-;===------------------------------------------------------------------------===;
-
-[component_0]
-type = Tool
-name = llvm-uselistorder
-parent = Tools
-required_libraries = IRReader BitWriter Support
diff --git a/tools/llvm-uselistorder/Makefile b/tools/llvm-uselistorder/Makefile
deleted file mode 100644 (file)
index 5a3727e..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-##===- tools/llvm-uselistorder/Makefile --------------------*- Makefile -*-===##
-#
-#                     The LLVM Compiler Infrastructure
-#
-# This file is distributed under the University of Illinois Open Source
-# License. See LICENSE.TXT for details.
-#
-##===----------------------------------------------------------------------===##
-
-LEVEL := ../..
-TOOLNAME := llvm-uselistorder
-LINK_COMPONENTS := AsmParser BitReader BitWriter Core IRReader Support
-
-# This tool has no plugins, optimize startup time.
-TOOL_NO_EXPORTS := 1
-
-include $(LEVEL)/Makefile.common
diff --git a/tools/llvm-uselistorder/llvm-uselistorder.cpp b/tools/llvm-uselistorder/llvm-uselistorder.cpp
deleted file mode 100644 (file)
index 0f817d2..0000000
+++ /dev/null
@@ -1,394 +0,0 @@
-//===- llvm-uselistorder.cpp - The LLVM Modular Optimizer -----------------===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// Verify that use-list order can be serialized correctly.  After reading the
-// provided IR, this tool shuffles the use-lists and then writes and reads to a
-// separate Module whose use-list orders are compared to the original.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/ADT/DenseMap.h"
-#include "llvm/AsmParser/Parser.h"
-#include "llvm/Bitcode/ReaderWriter.h"
-#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/Module.h"
-#include "llvm/IR/UseListOrder.h"
-#include "llvm/IRReader/IRReader.h"
-#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/FileUtilities.h"
-#include "llvm/Support/ManagedStatic.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/PrettyStackTrace.h"
-#include "llvm/Support/Signals.h"
-#include "llvm/Support/SourceMgr.h"
-#include "llvm/Support/SystemUtils.h"
-
-using namespace llvm;
-
-#define DEBUG_TYPE "use-list-order"
-
-static cl::opt<std::string> InputFilename(cl::Positional,
-                                          cl::desc("<input bitcode file>"),
-                                          cl::init("-"),
-                                          cl::value_desc("filename"));
-
-static cl::opt<bool> SaveTemps("save-temps", cl::desc("Save temp files"),
-                               cl::init(false));
-
-static cl::opt<unsigned>
-    NumShuffles("num-shuffles",
-                cl::desc("Number of times to shuffle and verify use-lists"),
-                cl::init(1));
-
-namespace {
-
-struct TempFile {
-  std::string Filename;
-  FileRemover Remover;
-  bool init(const std::string &Ext);
-  bool writeBitcode(const Module &M) const;
-  bool writeAssembly(const Module &M) const;
-  std::unique_ptr<Module> readBitcode(LLVMContext &Context) const;
-  std::unique_ptr<Module> readAssembly(LLVMContext &Context) const;
-};
-
-struct ValueMapping {
-  DenseMap<const Value *, unsigned> IDs;
-  std::vector<const Value *> Values;
-
-  /// \brief Construct a value mapping for module.
-  ///
-  /// Creates mapping from every value in \c M to an ID.  This mapping includes
-  /// un-referencable values.
-  ///
-  /// Every \a Value that gets serialized in some way should be represented
-  /// here.  The order needs to be deterministic, but it's unnecessary to match
-  /// the value-ids in the bitcode writer.
-  ///
-  /// All constants that are referenced by other values are included in the
-  /// mapping, but others -- which wouldn't be serialized -- are not.
-  ValueMapping(const Module &M);
-
-  /// \brief Map a value.
-  ///
-  /// Maps a value.  If it's a constant, maps all of its operands first.
-  void map(const Value *V);
-  unsigned lookup(const Value *V) const { return IDs.lookup(V); }
-};
-
-} // end namespace
-
-bool TempFile::init(const std::string &Ext) {
-  SmallVector<char, 64> Vector;
-  DEBUG(dbgs() << " - create-temp-file\n");
-  if (auto EC = sys::fs::createTemporaryFile("use-list-order", Ext, Vector)) {
-    (void)EC;
-    DEBUG(dbgs() << "error: " << EC.message() << "\n");
-    return true;
-  }
-  assert(!Vector.empty());
-
-  Filename.assign(Vector.data(), Vector.data() + Vector.size());
-  Remover.setFile(Filename, !SaveTemps);
-  DEBUG(dbgs() << " - filename = " << Filename << "\n");
-  return false;
-}
-
-bool TempFile::writeBitcode(const Module &M) const {
-  DEBUG(dbgs() << " - write bitcode\n");
-  std::string ErrorInfo;
-  raw_fd_ostream OS(Filename.c_str(), ErrorInfo, sys::fs::F_None);
-  if (!ErrorInfo.empty()) {
-    DEBUG(dbgs() << "error: " << ErrorInfo << "\n");
-    return true;
-  }
-
-  WriteBitcodeToFile(&M, OS);
-  return false;
-}
-
-bool TempFile::writeAssembly(const Module &M) const {
-  DEBUG(dbgs() << " - write assembly\n");
-  std::string ErrorInfo;
-  raw_fd_ostream OS(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
-  if (!ErrorInfo.empty()) {
-    DEBUG(dbgs() << "error: " << ErrorInfo << "\n");
-    return true;
-  }
-
-  OS << M;
-  return false;
-}
-
-std::unique_ptr<Module> TempFile::readBitcode(LLVMContext &Context) const {
-  DEBUG(dbgs() << " - read bitcode\n");
-  ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOr =
-      MemoryBuffer::getFile(Filename);
-  if (!BufferOr) {
-    DEBUG(dbgs() << "error: " << BufferOr.getError().message() << "\n");
-    return nullptr;
-  }
-
-  std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOr.get());
-  ErrorOr<Module *> ModuleOr = parseBitcodeFile(Buffer.get(), Context);
-  if (!ModuleOr) {
-    DEBUG(dbgs() << "error: " << ModuleOr.getError().message() << "\n");
-    return nullptr;
-  }
-  return std::unique_ptr<Module>(ModuleOr.get());
-}
-
-std::unique_ptr<Module> TempFile::readAssembly(LLVMContext &Context) const {
-  DEBUG(dbgs() << " - read assembly\n");
-  SMDiagnostic Err;
-  std::unique_ptr<Module> M(ParseAssemblyFile(Filename, Err, Context));
-  if (!M.get())
-    DEBUG(dbgs() << "error: "; Err.print("verify-use-list-order", dbgs()));
-  return M;
-}
-
-ValueMapping::ValueMapping(const Module &M) {
-  // Every value should be mapped, including things like void instructions and
-  // basic blocks that are kept out of the ValueEnumerator.
-  //
-  // The current mapping order makes it easier to debug the tables.  It happens
-  // to be similar to the ID mapping when writing ValueEnumerator, but they
-  // aren't (and needn't be) in sync.
-
-  // Globals.
-  for (const GlobalVariable &G : M.globals())
-    map(&G);
-  for (const GlobalAlias &A : M.aliases())
-    map(&A);
-  for (const Function &F : M)
-    map(&F);
-
-  // Constants used by globals.
-  for (const GlobalVariable &G : M.globals())
-    if (G.hasInitializer())
-      map(G.getInitializer());
-  for (const GlobalAlias &A : M.aliases())
-    map(A.getAliasee());
-  for (const Function &F : M)
-    if (F.hasPrefixData())
-      map(F.getPrefixData());
-
-  // Function bodies.
-  for (const Function &F : M) {
-    for (const Argument &A : F.args())
-      map(&A);
-    for (const BasicBlock &BB : F)
-      map(&BB);
-    for (const BasicBlock &BB : F)
-      for (const Instruction &I : BB)
-        map(&I);
-
-    // Constants used by instructions.
-    for (const BasicBlock &BB : F)
-      for (const Instruction &I : BB)
-        for (const Value *Op : I.operands())
-          if ((isa<Constant>(Op) && !isa<GlobalValue>(*Op)) ||
-              isa<InlineAsm>(Op))
-            map(Op);
-  }
-}
-
-void ValueMapping::map(const Value *V) {
-  if (IDs.lookup(V))
-    return;
-
-  if (auto *C = dyn_cast<Constant>(V))
-    if (!isa<GlobalValue>(C))
-      for (const Value *Op : C->operands())
-        map(Op);
-
-  Values.push_back(V);
-  IDs[V] = Values.size();
-}
-
-#ifndef NDEBUG
-static void dumpMapping(const ValueMapping &VM) {
-  dbgs() << "value-mapping (size = " << VM.Values.size() << "):\n";
-  for (unsigned I = 0, E = VM.Values.size(); I != E; ++I) {
-    dbgs() << " - id = " << I << ", value = ";
-    VM.Values[I]->dump();
-  }
-}
-
-static void debugValue(const ValueMapping &M, unsigned I, StringRef Desc) {
-  const Value *V = M.Values[I];
-  dbgs() << " - " << Desc << " value = ";
-  V->dump();
-  for (const Use &U : V->uses()) {
-    dbgs() << "   => use: op = " << U.getOperandNo()
-           << ", user-id = " << M.IDs.lookup(U.getUser()) << ", user = ";
-    U.getUser()->dump();
-  }
-}
-
-static void debugUserMismatch(const ValueMapping &L, const ValueMapping &R,
-                              unsigned I) {
-  dbgs() << " - fail: user mismatch: ID = " << I << "\n";
-  debugValue(L, I, "LHS");
-  debugValue(R, I, "RHS");
-
-  dbgs() << "\nlhs-";
-  dumpMapping(L);
-  dbgs() << "\nrhs-";
-  dumpMapping(R);
-}
-
-static void debugSizeMismatch(const ValueMapping &L, const ValueMapping &R) {
-  dbgs() << " - fail: map size: " << L.Values.size()
-         << " != " << R.Values.size() << "\n";
-  dbgs() << "\nlhs-";
-  dumpMapping(L);
-  dbgs() << "\nrhs-";
-  dumpMapping(R);
-}
-#endif
-
-static bool matches(const ValueMapping &LM, const ValueMapping &RM) {
-  DEBUG(dbgs() << "compare value maps\n");
-  if (LM.Values.size() != RM.Values.size()) {
-    DEBUG(debugSizeMismatch(LM, RM));
-    return false;
-  }
-
-  // This mapping doesn't include dangling constant users, since those don't
-  // get serialized.  However, checking if users are constant and calling
-  // isConstantUsed() on every one is very expensive.  Instead, just check if
-  // the user is mapped.
-  auto skipUnmappedUsers =
-      [&](Value::const_use_iterator &U, Value::const_use_iterator E,
-          const ValueMapping &M) {
-    while (U != E && !M.lookup(U->getUser()))
-      ++U;
-  };
-
-  // Iterate through all values, and check that both mappings have the same
-  // users.
-  for (unsigned I = 0, E = LM.Values.size(); I != E; ++I) {
-    const Value *L = LM.Values[I];
-    const Value *R = RM.Values[I];
-    auto LU = L->use_begin(), LE = L->use_end();
-    auto RU = R->use_begin(), RE = R->use_end();
-    skipUnmappedUsers(LU, LE, LM);
-    skipUnmappedUsers(RU, RE, RM);
-
-    while (LU != LE) {
-      if (RU == RE) {
-        DEBUG(debugUserMismatch(LM, RM, I));
-        return false;
-      }
-      if (LM.lookup(LU->getUser()) != RM.lookup(RU->getUser())) {
-        DEBUG(debugUserMismatch(LM, RM, I));
-        return false;
-      }
-      if (LU->getOperandNo() != RU->getOperandNo()) {
-        DEBUG(debugUserMismatch(LM, RM, I));
-        return false;
-      }
-      skipUnmappedUsers(++LU, LE, LM);
-      skipUnmappedUsers(++RU, RE, RM);
-    }
-    if (RU != RE) {
-      DEBUG(debugUserMismatch(LM, RM, I));
-      return false;
-    }
-  }
-
-  return true;
-}
-
-static bool verifyBitcodeUseListOrder(const Module &M) {
-  DEBUG(dbgs() << "*** verify-use-list-order: bitcode ***\n");
-  TempFile F;
-  if (F.init("bc"))
-    return false;
-
-  if (F.writeBitcode(M))
-    return false;
-
-  LLVMContext Context;
-  std::unique_ptr<Module> OtherM = F.readBitcode(Context);
-  if (!OtherM)
-    return false;
-
-  return matches(ValueMapping(M), ValueMapping(*OtherM));
-}
-
-static bool verifyAssemblyUseListOrder(const Module &M) {
-  DEBUG(dbgs() << "*** verify-use-list-order: assembly ***\n");
-  TempFile F;
-  if (F.init("ll"))
-    return false;
-
-  if (F.writeAssembly(M))
-    return false;
-
-  LLVMContext Context;
-  std::unique_ptr<Module> OtherM = F.readAssembly(Context);
-  if (!OtherM)
-    return false;
-
-  return matches(ValueMapping(M), ValueMapping(*OtherM));
-}
-
-int main(int argc, char **argv) {
-  sys::PrintStackTraceOnErrorSignal();
-  llvm::PrettyStackTraceProgram X(argc, argv);
-
-  // Enable debug stream buffering.
-  EnableDebugBuffering = true;
-
-  llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
-  LLVMContext &Context = getGlobalContext();
-
-  cl::ParseCommandLineOptions(argc, argv,
-                              "llvm tool to verify use-list order\n");
-
-  SMDiagnostic Err;
-
-  // Load the input module...
-  std::unique_ptr<Module> M;
-  M.reset(ParseIRFile(InputFilename, Err, Context));
-
-  if (!M.get()) {
-    Err.print(argv[0], errs());
-    return 1;
-  }
-
-  DEBUG(dbgs() << "*** verify-use-list-order ***\n");
-  if (!shouldPreserveBitcodeUseListOrder()) {
-    // Can't verify if order isn't preserved.
-    DEBUG(dbgs() << "warning: cannot verify bitcode; "
-                    "try -preserve-bc-use-list-order\n");
-    return 0;
-  }
-
-  for (unsigned I = 0, E = NumShuffles; I != E; ++I) {
-    DEBUG(dbgs() << "*** iteration: " << I << " ***\n");
-
-    // Shuffle with a different seed each time so that use-lists that aren't
-    // modified the first time are likely to be modified the next time.
-    shuffleUseLists(*M, I);
-    if (!verifyBitcodeUseListOrder(*M))
-      report_fatal_error("bitcode use-list order changed");
-
-    if (shouldPreserveAssemblyUseListOrder())
-      if (!verifyAssemblyUseListOrder(*M))
-        report_fatal_error("assembly use-list order changed");
-  }
-
-  return 0;
-}
diff --git a/tools/verify-uselistorder/CMakeLists.txt b/tools/verify-uselistorder/CMakeLists.txt
new file mode 100644 (file)
index 0000000..260a95a
--- /dev/null
@@ -0,0 +1,12 @@
+set(LLVM_LINK_COMPONENTS
+  AsmParser
+  BitReader
+  BitWriter
+  Core
+  IRReader
+  Support
+  )
+
+add_llvm_tool(verify-uselistorder
+  verify-uselistorder.cpp
+  )
diff --git a/tools/verify-uselistorder/LLVMBuild.txt b/tools/verify-uselistorder/LLVMBuild.txt
new file mode 100644 (file)
index 0000000..23957c1
--- /dev/null
@@ -0,0 +1,22 @@
+;===- ./tools/verify-uselistorder/LLVMBuild.txt ----------------*- Conf -*--===;
+;
+;                     The LLVM Compiler Infrastructure
+;
+; This file is distributed under the University of Illinois Open Source
+; License. See LICENSE.TXT for details.
+;
+;===------------------------------------------------------------------------===;
+;
+; This is an LLVMBuild description file for the components in this subdirectory.
+;
+; For more information on the LLVMBuild system, please see:
+;
+;   http://llvm.org/docs/LLVMBuild.html
+;
+;===------------------------------------------------------------------------===;
+
+[component_0]
+type = Tool
+name = verify-uselistorder
+parent = Tools
+required_libraries = IRReader BitWriter Support
diff --git a/tools/verify-uselistorder/Makefile b/tools/verify-uselistorder/Makefile
new file mode 100644 (file)
index 0000000..90d2aa8
--- /dev/null
@@ -0,0 +1,17 @@
+##===- tools/verify-uselistorder/Makefile ------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL := ../..
+TOOLNAME := verify-uselistorder
+LINK_COMPONENTS := AsmParser BitReader BitWriter Core IRReader Support
+
+# This tool has no plugins, optimize startup time.
+TOOL_NO_EXPORTS := 1
+
+include $(LEVEL)/Makefile.common
diff --git a/tools/verify-uselistorder/verify-uselistorder.cpp b/tools/verify-uselistorder/verify-uselistorder.cpp
new file mode 100644 (file)
index 0000000..37d7f5f
--- /dev/null
@@ -0,0 +1,394 @@
+//===- verify-uselistorder.cpp - The LLVM Modular Optimizer ---------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Verify that use-list order can be serialized correctly.  After reading the
+// provided IR, this tool shuffles the use-lists and then writes and reads to a
+// separate Module whose use-list orders are compared to the original.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/AsmParser/Parser.h"
+#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
+#include "llvm/IR/UseListOrder.h"
+#include "llvm/IRReader/IRReader.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Signals.h"
+#include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/SystemUtils.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "use-list-order"
+
+static cl::opt<std::string> InputFilename(cl::Positional,
+                                          cl::desc("<input bitcode file>"),
+                                          cl::init("-"),
+                                          cl::value_desc("filename"));
+
+static cl::opt<bool> SaveTemps("save-temps", cl::desc("Save temp files"),
+                               cl::init(false));
+
+static cl::opt<unsigned>
+    NumShuffles("num-shuffles",
+                cl::desc("Number of times to shuffle and verify use-lists"),
+                cl::init(1));
+
+namespace {
+
+struct TempFile {
+  std::string Filename;
+  FileRemover Remover;
+  bool init(const std::string &Ext);
+  bool writeBitcode(const Module &M) const;
+  bool writeAssembly(const Module &M) const;
+  std::unique_ptr<Module> readBitcode(LLVMContext &Context) const;
+  std::unique_ptr<Module> readAssembly(LLVMContext &Context) const;
+};
+
+struct ValueMapping {
+  DenseMap<const Value *, unsigned> IDs;
+  std::vector<const Value *> Values;
+
+  /// \brief Construct a value mapping for module.
+  ///
+  /// Creates mapping from every value in \c M to an ID.  This mapping includes
+  /// un-referencable values.
+  ///
+  /// Every \a Value that gets serialized in some way should be represented
+  /// here.  The order needs to be deterministic, but it's unnecessary to match
+  /// the value-ids in the bitcode writer.
+  ///
+  /// All constants that are referenced by other values are included in the
+  /// mapping, but others -- which wouldn't be serialized -- are not.
+  ValueMapping(const Module &M);
+
+  /// \brief Map a value.
+  ///
+  /// Maps a value.  If it's a constant, maps all of its operands first.
+  void map(const Value *V);
+  unsigned lookup(const Value *V) const { return IDs.lookup(V); }
+};
+
+} // end namespace
+
+bool TempFile::init(const std::string &Ext) {
+  SmallVector<char, 64> Vector;
+  DEBUG(dbgs() << " - create-temp-file\n");
+  if (auto EC = sys::fs::createTemporaryFile("use-list-order", Ext, Vector)) {
+    (void)EC;
+    DEBUG(dbgs() << "error: " << EC.message() << "\n");
+    return true;
+  }
+  assert(!Vector.empty());
+
+  Filename.assign(Vector.data(), Vector.data() + Vector.size());
+  Remover.setFile(Filename, !SaveTemps);
+  DEBUG(dbgs() << " - filename = " << Filename << "\n");
+  return false;
+}
+
+bool TempFile::writeBitcode(const Module &M) const {
+  DEBUG(dbgs() << " - write bitcode\n");
+  std::string ErrorInfo;
+  raw_fd_ostream OS(Filename.c_str(), ErrorInfo, sys::fs::F_None);
+  if (!ErrorInfo.empty()) {
+    DEBUG(dbgs() << "error: " << ErrorInfo << "\n");
+    return true;
+  }
+
+  WriteBitcodeToFile(&M, OS);
+  return false;
+}
+
+bool TempFile::writeAssembly(const Module &M) const {
+  DEBUG(dbgs() << " - write assembly\n");
+  std::string ErrorInfo;
+  raw_fd_ostream OS(Filename.c_str(), ErrorInfo, sys::fs::F_Text);
+  if (!ErrorInfo.empty()) {
+    DEBUG(dbgs() << "error: " << ErrorInfo << "\n");
+    return true;
+  }
+
+  OS << M;
+  return false;
+}
+
+std::unique_ptr<Module> TempFile::readBitcode(LLVMContext &Context) const {
+  DEBUG(dbgs() << " - read bitcode\n");
+  ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOr =
+      MemoryBuffer::getFile(Filename);
+  if (!BufferOr) {
+    DEBUG(dbgs() << "error: " << BufferOr.getError().message() << "\n");
+    return nullptr;
+  }
+
+  std::unique_ptr<MemoryBuffer> Buffer = std::move(BufferOr.get());
+  ErrorOr<Module *> ModuleOr = parseBitcodeFile(Buffer.get(), Context);
+  if (!ModuleOr) {
+    DEBUG(dbgs() << "error: " << ModuleOr.getError().message() << "\n");
+    return nullptr;
+  }
+  return std::unique_ptr<Module>(ModuleOr.get());
+}
+
+std::unique_ptr<Module> TempFile::readAssembly(LLVMContext &Context) const {
+  DEBUG(dbgs() << " - read assembly\n");
+  SMDiagnostic Err;
+  std::unique_ptr<Module> M(ParseAssemblyFile(Filename, Err, Context));
+  if (!M.get())
+    DEBUG(dbgs() << "error: "; Err.print("verify-use-list-order", dbgs()));
+  return M;
+}
+
+ValueMapping::ValueMapping(const Module &M) {
+  // Every value should be mapped, including things like void instructions and
+  // basic blocks that are kept out of the ValueEnumerator.
+  //
+  // The current mapping order makes it easier to debug the tables.  It happens
+  // to be similar to the ID mapping when writing ValueEnumerator, but they
+  // aren't (and needn't be) in sync.
+
+  // Globals.
+  for (const GlobalVariable &G : M.globals())
+    map(&G);
+  for (const GlobalAlias &A : M.aliases())
+    map(&A);
+  for (const Function &F : M)
+    map(&F);
+
+  // Constants used by globals.
+  for (const GlobalVariable &G : M.globals())
+    if (G.hasInitializer())
+      map(G.getInitializer());
+  for (const GlobalAlias &A : M.aliases())
+    map(A.getAliasee());
+  for (const Function &F : M)
+    if (F.hasPrefixData())
+      map(F.getPrefixData());
+
+  // Function bodies.
+  for (const Function &F : M) {
+    for (const Argument &A : F.args())
+      map(&A);
+    for (const BasicBlock &BB : F)
+      map(&BB);
+    for (const BasicBlock &BB : F)
+      for (const Instruction &I : BB)
+        map(&I);
+
+    // Constants used by instructions.
+    for (const BasicBlock &BB : F)
+      for (const Instruction &I : BB)
+        for (const Value *Op : I.operands())
+          if ((isa<Constant>(Op) && !isa<GlobalValue>(*Op)) ||
+              isa<InlineAsm>(Op))
+            map(Op);
+  }
+}
+
+void ValueMapping::map(const Value *V) {
+  if (IDs.lookup(V))
+    return;
+
+  if (auto *C = dyn_cast<Constant>(V))
+    if (!isa<GlobalValue>(C))
+      for (const Value *Op : C->operands())
+        map(Op);
+
+  Values.push_back(V);
+  IDs[V] = Values.size();
+}
+
+#ifndef NDEBUG
+static void dumpMapping(const ValueMapping &VM) {
+  dbgs() << "value-mapping (size = " << VM.Values.size() << "):\n";
+  for (unsigned I = 0, E = VM.Values.size(); I != E; ++I) {
+    dbgs() << " - id = " << I << ", value = ";
+    VM.Values[I]->dump();
+  }
+}
+
+static void debugValue(const ValueMapping &M, unsigned I, StringRef Desc) {
+  const Value *V = M.Values[I];
+  dbgs() << " - " << Desc << " value = ";
+  V->dump();
+  for (const Use &U : V->uses()) {
+    dbgs() << "   => use: op = " << U.getOperandNo()
+           << ", user-id = " << M.IDs.lookup(U.getUser()) << ", user = ";
+    U.getUser()->dump();
+  }
+}
+
+static void debugUserMismatch(const ValueMapping &L, const ValueMapping &R,
+                              unsigned I) {
+  dbgs() << " - fail: user mismatch: ID = " << I << "\n";
+  debugValue(L, I, "LHS");
+  debugValue(R, I, "RHS");
+
+  dbgs() << "\nlhs-";
+  dumpMapping(L);
+  dbgs() << "\nrhs-";
+  dumpMapping(R);
+}
+
+static void debugSizeMismatch(const ValueMapping &L, const ValueMapping &R) {
+  dbgs() << " - fail: map size: " << L.Values.size()
+         << " != " << R.Values.size() << "\n";
+  dbgs() << "\nlhs-";
+  dumpMapping(L);
+  dbgs() << "\nrhs-";
+  dumpMapping(R);
+}
+#endif
+
+static bool matches(const ValueMapping &LM, const ValueMapping &RM) {
+  DEBUG(dbgs() << "compare value maps\n");
+  if (LM.Values.size() != RM.Values.size()) {
+    DEBUG(debugSizeMismatch(LM, RM));
+    return false;
+  }
+
+  // This mapping doesn't include dangling constant users, since those don't
+  // get serialized.  However, checking if users are constant and calling
+  // isConstantUsed() on every one is very expensive.  Instead, just check if
+  // the user is mapped.
+  auto skipUnmappedUsers =
+      [&](Value::const_use_iterator &U, Value::const_use_iterator E,
+          const ValueMapping &M) {
+    while (U != E && !M.lookup(U->getUser()))
+      ++U;
+  };
+
+  // Iterate through all values, and check that both mappings have the same
+  // users.
+  for (unsigned I = 0, E = LM.Values.size(); I != E; ++I) {
+    const Value *L = LM.Values[I];
+    const Value *R = RM.Values[I];
+    auto LU = L->use_begin(), LE = L->use_end();
+    auto RU = R->use_begin(), RE = R->use_end();
+    skipUnmappedUsers(LU, LE, LM);
+    skipUnmappedUsers(RU, RE, RM);
+
+    while (LU != LE) {
+      if (RU == RE) {
+        DEBUG(debugUserMismatch(LM, RM, I));
+        return false;
+      }
+      if (LM.lookup(LU->getUser()) != RM.lookup(RU->getUser())) {
+        DEBUG(debugUserMismatch(LM, RM, I));
+        return false;
+      }
+      if (LU->getOperandNo() != RU->getOperandNo()) {
+        DEBUG(debugUserMismatch(LM, RM, I));
+        return false;
+      }
+      skipUnmappedUsers(++LU, LE, LM);
+      skipUnmappedUsers(++RU, RE, RM);
+    }
+    if (RU != RE) {
+      DEBUG(debugUserMismatch(LM, RM, I));
+      return false;
+    }
+  }
+
+  return true;
+}
+
+static bool verifyBitcodeUseListOrder(const Module &M) {
+  DEBUG(dbgs() << "*** verify-use-list-order: bitcode ***\n");
+  TempFile F;
+  if (F.init("bc"))
+    return false;
+
+  if (F.writeBitcode(M))
+    return false;
+
+  LLVMContext Context;
+  std::unique_ptr<Module> OtherM = F.readBitcode(Context);
+  if (!OtherM)
+    return false;
+
+  return matches(ValueMapping(M), ValueMapping(*OtherM));
+}
+
+static bool verifyAssemblyUseListOrder(const Module &M) {
+  DEBUG(dbgs() << "*** verify-use-list-order: assembly ***\n");
+  TempFile F;
+  if (F.init("ll"))
+    return false;
+
+  if (F.writeAssembly(M))
+    return false;
+
+  LLVMContext Context;
+  std::unique_ptr<Module> OtherM = F.readAssembly(Context);
+  if (!OtherM)
+    return false;
+
+  return matches(ValueMapping(M), ValueMapping(*OtherM));
+}
+
+int main(int argc, char **argv) {
+  sys::PrintStackTraceOnErrorSignal();
+  llvm::PrettyStackTraceProgram X(argc, argv);
+
+  // Enable debug stream buffering.
+  EnableDebugBuffering = true;
+
+  llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
+  LLVMContext &Context = getGlobalContext();
+
+  cl::ParseCommandLineOptions(argc, argv,
+                              "llvm tool to verify use-list order\n");
+
+  SMDiagnostic Err;
+
+  // Load the input module...
+  std::unique_ptr<Module> M;
+  M.reset(ParseIRFile(InputFilename, Err, Context));
+
+  if (!M.get()) {
+    Err.print(argv[0], errs());
+    return 1;
+  }
+
+  DEBUG(dbgs() << "*** verify-use-list-order ***\n");
+  if (!shouldPreserveBitcodeUseListOrder()) {
+    // Can't verify if order isn't preserved.
+    DEBUG(dbgs() << "warning: cannot verify bitcode; "
+                    "try -preserve-bc-use-list-order\n");
+    return 0;
+  }
+
+  for (unsigned I = 0, E = NumShuffles; I != E; ++I) {
+    DEBUG(dbgs() << "*** iteration: " << I << " ***\n");
+
+    // Shuffle with a different seed each time so that use-lists that aren't
+    // modified the first time are likely to be modified the next time.
+    shuffleUseLists(*M, I);
+    if (!verifyBitcodeUseListOrder(*M))
+      report_fatal_error("bitcode use-list order changed");
+
+    if (shouldPreserveAssemblyUseListOrder())
+      if (!verifyAssemblyUseListOrder(*M))
+        report_fatal_error("assembly use-list order changed");
+  }
+
+  return 0;
+}