Index: llvm/trunk/include/llvm/InitializePasses.h =================================================================== --- llvm/trunk/include/llvm/InitializePasses.h +++ llvm/trunk/include/llvm/InitializePasses.h @@ -226,6 +226,7 @@ void initializeMemDerefPrinterPass(PassRegistry&); void initializeMemoryDependenceWrapperPassPass(PassRegistry&); void initializeMemorySSAWrapperPassPass(PassRegistry&); +void initializeMemorySSAPrinterLegacyPassPass(PassRegistry &); void initializeMemorySanitizerPass(PassRegistry&); void initializeMergeFunctionsPass(PassRegistry&); void initializeMergedLoadStoreMotionLegacyPassPass(PassRegistry &); Index: llvm/trunk/include/llvm/Transforms/Utils/MemorySSA.h =================================================================== --- llvm/trunk/include/llvm/Transforms/Utils/MemorySSA.h +++ llvm/trunk/include/llvm/Transforms/Utils/MemorySSA.h @@ -626,6 +626,17 @@ unsigned NextID; }; +// This pass does eager building and then printing of MemorySSA. It is used by +// the tests to be able to build, dump, and verify Memory SSA. +class MemorySSAPrinterLegacyPass : public FunctionPass { +public: + MemorySSAPrinterLegacyPass(); + + static char ID; + bool runOnFunction(Function &) override; + void getAnalysisUsage(AnalysisUsage &AU) const override; +}; + /// An analysis that produces \c MemorySSA for a function. /// class MemorySSAAnalysis : public AnalysisInfoMixin { Index: llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp =================================================================== --- llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp +++ llvm/trunk/lib/Transforms/Utils/MemorySSA.cpp @@ -54,6 +54,16 @@ INITIALIZE_PASS_END(MemorySSAWrapperPass, "memoryssa", "Memory SSA", false, true) +INITIALIZE_PASS_BEGIN(MemorySSAPrinterLegacyPass, "print-memoryssa", + "Memory SSA Printer", false, false) +INITIALIZE_PASS_DEPENDENCY(MemorySSAWrapperPass) +INITIALIZE_PASS_END(MemorySSAPrinterLegacyPass, "print-memoryssa", + "Memory SSA Printer", false, false) + +static cl::opt + VerifyMemorySSA("verify-memoryssa", cl::init(false), cl::Hidden, + cl::desc("Verify MemorySSA in legacy printer pass.")); + namespace llvm { /// \brief An assembly annotator class to print Memory SSA information in /// comments. @@ -894,6 +904,26 @@ dbgs() << "\n"; } +char MemorySSAPrinterLegacyPass::ID = 0; + +MemorySSAPrinterLegacyPass::MemorySSAPrinterLegacyPass() : FunctionPass(ID) { + initializeMemorySSAPrinterLegacyPassPass(*PassRegistry::getPassRegistry()); +} + +void MemorySSAPrinterLegacyPass::getAnalysisUsage(AnalysisUsage &AU) const { + AU.setPreservesAll(); + AU.addRequired(); + AU.addPreserved(); +} + +bool MemorySSAPrinterLegacyPass::runOnFunction(Function &F) { + auto &MSSA = getAnalysis().getMSSA(); + MSSA.print(dbgs()); + if (VerifyMemorySSA) + MSSA.verifyMemorySSA(); + return false; +} + char MemorySSAAnalysis::PassID; MemorySSA MemorySSAAnalysis::run(Function &F, AnalysisManager &AM) { Index: llvm/trunk/lib/Transforms/Utils/Utils.cpp =================================================================== --- llvm/trunk/lib/Transforms/Utils/Utils.cpp +++ llvm/trunk/lib/Transforms/Utils/Utils.cpp @@ -34,6 +34,7 @@ initializeInstSimplifierPass(Registry); initializeMetaRenamerPass(Registry); initializeMemorySSAWrapperPassPass(Registry); + initializeMemorySSAPrinterLegacyPassPass(Registry); } /// LLVMInitializeTransformUtils - C binding for initializeTransformUtilsPasses. Index: llvm/trunk/test/Transforms/Util/MemorySSA/atomic-clobber.ll =================================================================== --- llvm/trunk/test/Transforms/Util/MemorySSA/atomic-clobber.ll +++ llvm/trunk/test/Transforms/Util/MemorySSA/atomic-clobber.ll @@ -1,4 +1,4 @@ -; RUN: opt -basicaa -memoryssa -analyze < %s 2>&1 | FileCheck %s +; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='print,verify' -disable-output < %s 2>&1 | FileCheck %s ; ; Ensures that atomic loads count as MemoryDefs Index: llvm/trunk/test/Transforms/Util/MemorySSA/cyclicphi.ll =================================================================== --- llvm/trunk/test/Transforms/Util/MemorySSA/cyclicphi.ll +++ llvm/trunk/test/Transforms/Util/MemorySSA/cyclicphi.ll @@ -1,4 +1,4 @@ -; RUN: opt -basicaa -memoryssa -analyze < %s 2>&1 | FileCheck %s +; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='print,verify' -disable-output < %s 2>&1 | FileCheck %s %struct.hoge = type { i32, %struct.widget } Index: llvm/trunk/test/Transforms/Util/MemorySSA/function-clobber.ll =================================================================== --- llvm/trunk/test/Transforms/Util/MemorySSA/function-clobber.ll +++ llvm/trunk/test/Transforms/Util/MemorySSA/function-clobber.ll @@ -1,4 +1,4 @@ -; RUN: opt -basicaa -memoryssa -analyze < %s 2>&1 | FileCheck %s +; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='print,verify' -disable-output < %s 2>&1 | FileCheck %s ; ; Ensuring that external functions without attributes are MemoryDefs Index: llvm/trunk/test/Transforms/Util/MemorySSA/function-mem-attrs.ll =================================================================== --- llvm/trunk/test/Transforms/Util/MemorySSA/function-mem-attrs.ll +++ llvm/trunk/test/Transforms/Util/MemorySSA/function-mem-attrs.ll @@ -1,4 +1,4 @@ -; RUN: opt -basicaa -memoryssa -analyze < %s 2>&1 | FileCheck %s +; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='print,verify' -disable-output < %s 2>&1 | FileCheck %s ; ; Test that various function attributes give us sane results. Index: llvm/trunk/test/Transforms/Util/MemorySSA/livein.ll =================================================================== --- llvm/trunk/test/Transforms/Util/MemorySSA/livein.ll +++ llvm/trunk/test/Transforms/Util/MemorySSA/livein.ll @@ -1,4 +1,4 @@ -; RUN: opt -basicaa -memoryssa -analyze < %s 2>&1 | FileCheck %s +; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='print,verify' -disable-output < %s 2>&1 | FileCheck %s define void @F(i8*) { br i1 true, label %left, label %right Index: llvm/trunk/test/Transforms/Util/MemorySSA/load-invariant.ll =================================================================== --- llvm/trunk/test/Transforms/Util/MemorySSA/load-invariant.ll +++ llvm/trunk/test/Transforms/Util/MemorySSA/load-invariant.ll @@ -1,5 +1,5 @@ ; XFAIL: * -; RUN: opt -basicaa -memoryssa -analyze < %s 2>&1 | FileCheck %s +; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='print' -verify-memoryssa -disable-output < %s 2>&1 | FileCheck %s ; ; Invariant loads should be considered live on entry, because, once the Index: llvm/trunk/test/Transforms/Util/MemorySSA/many-dom-backedge.ll =================================================================== --- llvm/trunk/test/Transforms/Util/MemorySSA/many-dom-backedge.ll +++ llvm/trunk/test/Transforms/Util/MemorySSA/many-dom-backedge.ll @@ -1,4 +1,4 @@ -; RUN: opt -basicaa -memoryssa -analyze < %s 2>&1 | FileCheck %s +; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='print,verify' -disable-output < %s 2>&1 | FileCheck %s ; ; many-dom.ll, with an added back-edge back into the switch. Index: llvm/trunk/test/Transforms/Util/MemorySSA/many-doms.ll =================================================================== --- llvm/trunk/test/Transforms/Util/MemorySSA/many-doms.ll +++ llvm/trunk/test/Transforms/Util/MemorySSA/many-doms.ll @@ -1,4 +1,4 @@ -; RUN: opt -basicaa -memoryssa -analyze < %s 2>&1 | FileCheck %s +; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='print,verify' -disable-output < %s 2>&1 | FileCheck %s ; ; Testing many dominators, specifically from a switch statement in C. Index: llvm/trunk/test/Transforms/Util/MemorySSA/multi-edges.ll =================================================================== --- llvm/trunk/test/Transforms/Util/MemorySSA/multi-edges.ll +++ llvm/trunk/test/Transforms/Util/MemorySSA/multi-edges.ll @@ -1,4 +1,4 @@ -; RUN: opt -basicaa -memoryssa -analyze < %s 2>&1 | FileCheck %s +; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='print,verify' -disable-output < %s 2>&1 | FileCheck %s ; ; Makes sure we have a sane model if both successors of some block is the same Index: llvm/trunk/test/Transforms/Util/MemorySSA/multiple-backedges-hal.ll =================================================================== --- llvm/trunk/test/Transforms/Util/MemorySSA/multiple-backedges-hal.ll +++ llvm/trunk/test/Transforms/Util/MemorySSA/multiple-backedges-hal.ll @@ -1,4 +1,4 @@ -; RUN: opt -basicaa -memoryssa -analyze < %s 2>&1 | FileCheck %s +; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='print,verify' -disable-output < %s 2>&1 | FileCheck %s ; hfinkel's case Index: llvm/trunk/test/Transforms/Util/MemorySSA/multiple-locations.ll =================================================================== --- llvm/trunk/test/Transforms/Util/MemorySSA/multiple-locations.ll +++ llvm/trunk/test/Transforms/Util/MemorySSA/multiple-locations.ll @@ -1,4 +1,4 @@ -; RUN: opt -basicaa -memoryssa -analyze < %s 2>&1 | FileCheck %s +; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='print,verify' -disable-output < %s 2>&1 | FileCheck %s ; ; Checks that basicAA is doing some amount of disambiguation for us Index: llvm/trunk/test/Transforms/Util/MemorySSA/no-disconnected.ll =================================================================== --- llvm/trunk/test/Transforms/Util/MemorySSA/no-disconnected.ll +++ llvm/trunk/test/Transforms/Util/MemorySSA/no-disconnected.ll @@ -1,4 +1,4 @@ -; RUN: opt -basicaa -memoryssa -analyze < %s 2>&1 | FileCheck %s +; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='print,verify' -disable-output < %s 2>&1 | FileCheck %s ; ; This test ensures we don't end up with multiple reaching defs for a single Index: llvm/trunk/test/Transforms/Util/MemorySSA/optimize-use.ll =================================================================== --- llvm/trunk/test/Transforms/Util/MemorySSA/optimize-use.ll +++ llvm/trunk/test/Transforms/Util/MemorySSA/optimize-use.ll @@ -1,4 +1,4 @@ -; RUN: opt -basicaa -memoryssa -analyze < %s 2>&1 | FileCheck %s +; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='print,verify' -disable-output < %s 2>&1 | FileCheck %s ; Function Attrs: ssp uwtable Index: llvm/trunk/test/Transforms/Util/MemorySSA/phi-translation.ll =================================================================== --- llvm/trunk/test/Transforms/Util/MemorySSA/phi-translation.ll +++ llvm/trunk/test/Transforms/Util/MemorySSA/phi-translation.ll @@ -1,4 +1,4 @@ -; RUN: opt -basicaa -memoryssa -analyze < %s 2>&1 | FileCheck %s +; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='print,verify' -disable-output < %s 2>&1 | FileCheck %s ; %ptr can't alias %local, so we should be able to optimize the use of %local to Index: llvm/trunk/test/Transforms/Util/MemorySSA/volatile-clobber.ll =================================================================== --- llvm/trunk/test/Transforms/Util/MemorySSA/volatile-clobber.ll +++ llvm/trunk/test/Transforms/Util/MemorySSA/volatile-clobber.ll @@ -1,4 +1,4 @@ -; RUN: opt -basicaa -memoryssa -analyze < %s 2>&1 | FileCheck %s +; RUN: opt -basicaa -print-memoryssa -verify-memoryssa -analyze < %s 2>&1 | FileCheck %s ; RUN: opt -aa-pipeline=basic-aa -passes='print,verify' -disable-output < %s 2>&1 | FileCheck %s ; ; Ensures that volatile stores/loads count as MemoryDefs