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
This commit is contained in:
Duncan P. N. Exon Smith
2014-07-25 14:49:26 +00:00
parent db4f73f6d9
commit 7bf73bd378
11 changed files with 621 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ add_llvm_library(LLVMipo
PruneEH.cpp
StripDeadPrototypes.cpp
StripSymbols.cpp
VerifyUseListOrder.cpp
)
add_dependencies(LLVMipo intrinsics_gen)

View File

@@ -44,6 +44,7 @@ void llvm::initializeIPO(PassRegistry &Registry) {
initializeStripDebugDeclarePass(Registry);
initializeStripDeadDebugInfoPass(Registry);
initializeStripNonDebugSymbolsPass(Registry);
initializeVerifyUseListOrderPass(Registry);
initializeBarrierNoopPass(Registry);
}

View File

@@ -0,0 +1,61 @@
//===- VerifyUseListOrder.cpp - Use List Order Verifier ---------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Pass to verify use-list order doesn't change after serialization.
//
// Despite it being a verifier, this pass *does* transform the module, since it
// shuffles the use-list of every value.
//
//===----------------------------------------------------------------------===//
#include "llvm/Transforms/IPO.h"
#include "llvm/IR/UseListOrder.h"
#include "llvm/Pass.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
using namespace llvm;
#define DEBUG_TYPE "use-list-order"
namespace {
class VerifyUseListOrder : public ModulePass {
public:
static char ID;
VerifyUseListOrder();
bool runOnModule(Module &M) override;
};
} // end anonymous namespace
char VerifyUseListOrder::ID = 0;
INITIALIZE_PASS(VerifyUseListOrder, "verify-use-list-order",
"Verify Use List Order", false, false)
VerifyUseListOrder::VerifyUseListOrder() : ModulePass(ID) {
initializeVerifyUseListOrderPass(*PassRegistry::getPassRegistry());
}
bool VerifyUseListOrder::runOnModule(Module &M) {
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 false;
}
shuffleUseLists(M);
if (!verifyBitcodeUseListOrder(M))
report_fatal_error("bitcode use-list order changed");
return true;
}
ModulePass *llvm::createVerifyUseListOrderPass() {
return new VerifyUseListOrder;
}