Skip to content

Commit 7bf73bd

Browse files
committed
IPO: Add use-list-order verifier
Add a -verify-use-list-order pass, which shuffles use-list order, writes to bitcode, reads back, and verifies that the (shuffled) order matches. - The utility functions live in lib/IR/UseListOrder.cpp. - Moved (and renamed) the command-line option to enable writing use-lists, so that this pass can return early if the use-list orders aren't being serialized. It's not clear that this pass is the right direction long-term (perhaps a separate tool instead?), but short-term it's a great way to test the use-list order prototype. I've added an XFAIL-ed testcase that I'm hoping to get working pretty quickly. This is part of PR5680. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@213945 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent db4f73f commit 7bf73bd

File tree

11 files changed

+621
-7
lines changed

11 files changed

+621
-7
lines changed

include/llvm/IR/UseListOrder.h

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//===- llvm/IR/UseListOrder.h - LLVM Use List Order functions ---*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// This file has functions to modify the use-list order and to verify that it
11+
// doesn't change after serialization.
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#ifndef LLVM_IR_USELISTORDER_H
16+
#define LLVM_IR_USELISTORDER_H
17+
18+
namespace llvm {
19+
20+
class Module;
21+
22+
/// \brief Whether to preserve use-list ordering.
23+
bool shouldPreserveBitcodeUseListOrder();
24+
25+
/// \brief Shuffle all use-lists in a module.
26+
///
27+
/// Adds \c SeedOffset to the default seed for the random number generator.
28+
void shuffleUseLists(Module &M, unsigned SeedOffset = 0);
29+
30+
/// \brief Verify use-list order after serializing to bitcode.
31+
///
32+
/// \return \c true if there are no errors.
33+
bool verifyBitcodeUseListOrder(const Module &M);
34+
35+
/// \brief Verify use-list order after serializing to assembly.
36+
///
37+
/// \return \c true if there are no errors.
38+
bool verifyAssemblyUseListOrder(const Module &M);
39+
40+
} // end namespace llvm
41+
42+
#endif

include/llvm/InitializePasses.h

+1
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ void initializeUnifyFunctionExitNodesPass(PassRegistry&);
268268
void initializeUnreachableBlockElimPass(PassRegistry&);
269269
void initializeUnreachableMachineBlockElimPass(PassRegistry&);
270270
void initializeVerifierLegacyPassPass(PassRegistry&);
271+
void initializeVerifyUseListOrderPass(PassRegistry&);
271272
void initializeVirtRegMapPass(PassRegistry&);
272273
void initializeVirtRegRewriterPass(PassRegistry&);
273274
void initializeInstSimplifierPass(PassRegistry&);

include/llvm/LinkAllPasses.h

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ namespace {
161161
(void) llvm::createPartiallyInlineLibCallsPass();
162162
(void) llvm::createScalarizerPass();
163163
(void) llvm::createSeparateConstOffsetFromGEPPass();
164+
(void) llvm::createVerifyUseListOrderPass();
164165

165166
(void)new llvm::IntervalPartition();
166167
(void)new llvm::FindUsedTypes();

include/llvm/Transforms/IPO.h

+5
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ ModulePass *createInternalizePass(ArrayRef<const char *> ExportList);
118118
/// createInternalizePass - Same as above, but with an empty exportList.
119119
ModulePass *createInternalizePass();
120120

121+
/// \brief Verify that use-list order doesn't change after shuffling.
122+
///
123+
/// \note This is a transformation, since the use-list order changes.
124+
ModulePass *createVerifyUseListOrderPass();
125+
121126
//===----------------------------------------------------------------------===//
122127
/// createDeadArgEliminationPass - This pass removes arguments from functions
123128
/// which are not used by the body of the function.

lib/Bitcode/Writer/BitcodeWriter.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/IR/Instructions.h"
2323
#include "llvm/IR/Module.h"
2424
#include "llvm/IR/Operator.h"
25+
#include "llvm/IR/UseListOrder.h"
2526
#include "llvm/IR/ValueSymbolTable.h"
2627
#include "llvm/Support/CommandLine.h"
2728
#include "llvm/Support/ErrorHandling.h"
@@ -32,12 +33,6 @@
3233
#include <map>
3334
using namespace llvm;
3435

35-
static cl::opt<bool>
36-
EnablePreserveUseListOrdering("enable-bc-uselist-preserve",
37-
cl::desc("Turn on experimental support for "
38-
"use-list order preservation."),
39-
cl::init(false), cl::Hidden);
40-
4136
/// These are manifest constants used by the bitcode writer. They do not need to
4237
/// be kept in sync with the reader, but need to be consistent within this file.
4338
enum {
@@ -1975,7 +1970,7 @@ static void WriteModule(const Module *M, BitstreamWriter &Stream) {
19751970
WriteValueSymbolTable(M->getValueSymbolTable(), VE, Stream);
19761971

19771972
// Emit use-lists.
1978-
if (EnablePreserveUseListOrdering)
1973+
if (shouldPreserveBitcodeUseListOrder())
19791974
WriteModuleUseLists(M, VE, Stream);
19801975

19811976
// Emit function bodies.

lib/IR/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ add_llvm_library(LLVMCore
3939
Type.cpp
4040
TypeFinder.cpp
4141
Use.cpp
42+
UseListOrder.cpp
4243
User.cpp
4344
Value.cpp
4445
ValueSymbolTable.cpp

0 commit comments

Comments
 (0)