mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-25 13:24:46 +00:00
[PM] Add module and function printing passes for the new pass manager.
This implements the legacy passes in terms of the new ones. It adds basic testing using explicit runs of the passes. Next up will be wiring the basic output mechanism of opt up when the new pass manager is engaged unless bitcode writing is requested. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199049 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -19,12 +19,16 @@
|
|||||||
#ifndef LLVM_IR_PRINTMODULEPASS_H
|
#ifndef LLVM_IR_PRINTMODULEPASS_H
|
||||||
#define LLVM_IR_PRINTMODULEPASS_H
|
#define LLVM_IR_PRINTMODULEPASS_H
|
||||||
|
|
||||||
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
class FunctionPass;
|
|
||||||
class ModulePass;
|
|
||||||
class BasicBlockPass;
|
class BasicBlockPass;
|
||||||
|
class Function;
|
||||||
|
class FunctionPass;
|
||||||
|
class Module;
|
||||||
|
class ModulePass;
|
||||||
|
class PreservedAnalyses;
|
||||||
class raw_ostream;
|
class raw_ostream;
|
||||||
|
|
||||||
/// \brief Create and return a pass that writes the module to the specified
|
/// \brief Create and return a pass that writes the module to the specified
|
||||||
@@ -42,6 +46,40 @@ FunctionPass *createPrintFunctionPass(raw_ostream &OS,
|
|||||||
BasicBlockPass *createPrintBasicBlockPass(raw_ostream &OS,
|
BasicBlockPass *createPrintBasicBlockPass(raw_ostream &OS,
|
||||||
const std::string &Banner = "");
|
const std::string &Banner = "");
|
||||||
|
|
||||||
|
/// \brief Pass for printing a Module as LLVM's text IR assembly.
|
||||||
|
///
|
||||||
|
/// Note: This pass is for use with the new pass manager. Use the create...Pass
|
||||||
|
/// functions above to create passes for use with the legacy pass manager.
|
||||||
|
class PrintModulePass {
|
||||||
|
raw_ostream &OS;
|
||||||
|
std::string Banner;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PrintModulePass();
|
||||||
|
PrintModulePass(raw_ostream &OS, const std::string &Banner = "");
|
||||||
|
|
||||||
|
PreservedAnalyses run(Module *M);
|
||||||
|
|
||||||
|
static StringRef name() { return "PrintModulePass"; }
|
||||||
|
};
|
||||||
|
|
||||||
|
/// \brief Pass for printing a Function as LLVM's text IR assembly.
|
||||||
|
///
|
||||||
|
/// Note: This pass is for use with the new pass manager. Use the create...Pass
|
||||||
|
/// functions above to create passes for use with the legacy pass manager.
|
||||||
|
class PrintFunctionPass {
|
||||||
|
raw_ostream &OS;
|
||||||
|
std::string Banner;
|
||||||
|
|
||||||
|
public:
|
||||||
|
PrintFunctionPass();
|
||||||
|
PrintFunctionPass(raw_ostream &OS, const std::string &Banner = "");
|
||||||
|
|
||||||
|
PreservedAnalyses run(Function *F);
|
||||||
|
|
||||||
|
static StringRef name() { return "PrintFunctionPass"; }
|
||||||
|
};
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -212,8 +212,8 @@ void initializePostDominatorTreePass(PassRegistry&);
|
|||||||
void initializePostRASchedulerPass(PassRegistry&);
|
void initializePostRASchedulerPass(PassRegistry&);
|
||||||
void initializePostMachineSchedulerPass(PassRegistry&);
|
void initializePostMachineSchedulerPass(PassRegistry&);
|
||||||
void initializePreVerifierPass(PassRegistry&);
|
void initializePreVerifierPass(PassRegistry&);
|
||||||
void initializePrintFunctionPassPass(PassRegistry&);
|
void initializePrintFunctionPassWrapperPass(PassRegistry&);
|
||||||
void initializePrintModulePassPass(PassRegistry&);
|
void initializePrintModulePassWrapperPass(PassRegistry&);
|
||||||
void initializePrintBasicBlockPassPass(PassRegistry&);
|
void initializePrintBasicBlockPassPass(PassRegistry&);
|
||||||
void initializeProcessImplicitDefsPass(PassRegistry&);
|
void initializeProcessImplicitDefsPass(PassRegistry&);
|
||||||
void initializePromotePassPass(PassRegistry&);
|
void initializePromotePassPass(PassRegistry&);
|
||||||
|
@@ -41,8 +41,8 @@ using namespace llvm;
|
|||||||
|
|
||||||
void llvm::initializeCore(PassRegistry &Registry) {
|
void llvm::initializeCore(PassRegistry &Registry) {
|
||||||
initializeDominatorTreePass(Registry);
|
initializeDominatorTreePass(Registry);
|
||||||
initializePrintModulePassPass(Registry);
|
initializePrintModulePassWrapperPass(Registry);
|
||||||
initializePrintFunctionPassPass(Registry);
|
initializePrintFunctionPassWrapperPass(Registry);
|
||||||
initializePrintBasicBlockPassPass(Registry);
|
initializePrintBasicBlockPassPass(Registry);
|
||||||
initializeVerifierPass(Registry);
|
initializeVerifierPass(Registry);
|
||||||
initializePreVerifierPass(Registry);
|
initializePreVerifierPass(Registry);
|
||||||
|
@@ -14,25 +14,43 @@
|
|||||||
#include "llvm/IR/IRPrintingPasses.h"
|
#include "llvm/IR/IRPrintingPasses.h"
|
||||||
#include "llvm/IR/Function.h"
|
#include "llvm/IR/Function.h"
|
||||||
#include "llvm/IR/Module.h"
|
#include "llvm/IR/Module.h"
|
||||||
|
#include "llvm/IR/PassManager.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
PrintModulePass::PrintModulePass() : OS(dbgs()) {}
|
||||||
|
PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner)
|
||||||
|
: OS(OS), Banner(Banner) {}
|
||||||
|
|
||||||
|
PreservedAnalyses PrintModulePass::run(Module *M) {
|
||||||
|
OS << Banner << *M;
|
||||||
|
return PreservedAnalyses::all();
|
||||||
|
}
|
||||||
|
|
||||||
|
PrintFunctionPass::PrintFunctionPass() : OS(dbgs()) {}
|
||||||
|
PrintFunctionPass::PrintFunctionPass(raw_ostream &OS, const std::string &Banner)
|
||||||
|
: OS(OS), Banner(Banner) {}
|
||||||
|
|
||||||
|
PreservedAnalyses PrintFunctionPass::run(Function *F) {
|
||||||
|
OS << Banner << static_cast<Value &>(*F);
|
||||||
|
return PreservedAnalyses::all();
|
||||||
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
class PrintModulePass : public ModulePass {
|
class PrintModulePassWrapper : public ModulePass {
|
||||||
raw_ostream &Out;
|
PrintModulePass P;
|
||||||
std::string Banner;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID;
|
static char ID;
|
||||||
PrintModulePass() : ModulePass(ID), Out(dbgs()) {}
|
PrintModulePassWrapper() : ModulePass(ID) {}
|
||||||
PrintModulePass(raw_ostream &Out, const std::string &Banner)
|
PrintModulePassWrapper(raw_ostream &OS, const std::string &Banner)
|
||||||
: ModulePass(ID), Out(Out), Banner(Banner) {}
|
: ModulePass(ID), P(OS, Banner) {}
|
||||||
|
|
||||||
bool runOnModule(Module &M) {
|
bool runOnModule(Module &M) {
|
||||||
Out << Banner << M;
|
P.run(&M);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,19 +59,18 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class PrintFunctionPass : public FunctionPass {
|
class PrintFunctionPassWrapper : public FunctionPass {
|
||||||
raw_ostream &Out;
|
PrintFunctionPass P;
|
||||||
std::string Banner;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID;
|
static char ID;
|
||||||
PrintFunctionPass() : FunctionPass(ID), Out(dbgs()) {}
|
PrintFunctionPassWrapper() : FunctionPass(ID) {}
|
||||||
PrintFunctionPass(raw_ostream &Out, const std::string &Banner)
|
PrintFunctionPassWrapper(raw_ostream &OS, const std::string &Banner)
|
||||||
: FunctionPass(ID), Out(Out), Banner(Banner) {}
|
: FunctionPass(ID), P(OS, Banner) {}
|
||||||
|
|
||||||
// This pass just prints a banner followed by the function as it's processed.
|
// This pass just prints a banner followed by the function as it's processed.
|
||||||
bool runOnFunction(Function &F) {
|
bool runOnFunction(Function &F) {
|
||||||
Out << Banner << static_cast<Value &>(F);
|
P.run(&F);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,24 +101,24 @@ public:
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char PrintModulePass::ID = 0;
|
char PrintModulePassWrapper::ID = 0;
|
||||||
INITIALIZE_PASS(PrintModulePass, "print-module", "Print module to stderr",
|
INITIALIZE_PASS(PrintModulePassWrapper, "print-module",
|
||||||
false, false)
|
"Print module to stderr", false, false)
|
||||||
char PrintFunctionPass::ID = 0;
|
char PrintFunctionPassWrapper::ID = 0;
|
||||||
INITIALIZE_PASS(PrintFunctionPass, "print-function", "Print function to stderr",
|
INITIALIZE_PASS(PrintFunctionPassWrapper, "print-function",
|
||||||
false, false)
|
"Print function to stderr", false, false)
|
||||||
char PrintBasicBlockPass::ID = 0;
|
char PrintBasicBlockPass::ID = 0;
|
||||||
INITIALIZE_PASS(PrintBasicBlockPass, "print-bb", "Print BB to stderr", false,
|
INITIALIZE_PASS(PrintBasicBlockPass, "print-bb", "Print BB to stderr", false,
|
||||||
false)
|
false)
|
||||||
|
|
||||||
ModulePass *llvm::createPrintModulePass(llvm::raw_ostream &OS,
|
ModulePass *llvm::createPrintModulePass(llvm::raw_ostream &OS,
|
||||||
const std::string &Banner) {
|
const std::string &Banner) {
|
||||||
return new PrintModulePass(OS, Banner);
|
return new PrintModulePassWrapper(OS, Banner);
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionPass *llvm::createPrintFunctionPass(llvm::raw_ostream &OS,
|
FunctionPass *llvm::createPrintFunctionPass(llvm::raw_ostream &OS,
|
||||||
const std::string &Banner) {
|
const std::string &Banner) {
|
||||||
return new PrintFunctionPass(OS, Banner);
|
return new PrintFunctionPassWrapper(OS, Banner);
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicBlockPass *llvm::createPrintBasicBlockPass(llvm::raw_ostream &OS,
|
BasicBlockPass *llvm::createPrintBasicBlockPass(llvm::raw_ostream &OS,
|
||||||
|
28
test/Other/new-pass-manager.ll
Normal file
28
test/Other/new-pass-manager.ll
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
; This test is essentially doing very basic things with the opt tool and the
|
||||||
|
; new pass manager pipeline. It will be used to flesh out the feature
|
||||||
|
; completeness of the opt tool when the new pass manager is engaged. The tests
|
||||||
|
; may not be useful once it becomes the default or may get spread out into other
|
||||||
|
; files, but for now this is just going to step the new process through its
|
||||||
|
; paces.
|
||||||
|
|
||||||
|
; RUN: opt -disable-output -debug-pass-manager -passes=print %s 2>&1 \
|
||||||
|
; RUN: | FileCheck %s --check-prefix=CHECK-MODULE-PRINT
|
||||||
|
; CHECK-MODULE-PRINT: Starting module pass manager
|
||||||
|
; CHECK-MODULE-PRINT: Running module pass: PrintModulePass
|
||||||
|
; CHECK-MODULE-PRINT: ModuleID
|
||||||
|
; CHECK-MODULE-PRINT: define void @foo()
|
||||||
|
; CHECK-MODULE-PRINT: Finished module pass manager
|
||||||
|
|
||||||
|
; RUN: opt -disable-output -debug-pass-manager -passes='function(print)' %s 2>&1 \
|
||||||
|
; RUN: | FileCheck %s --check-prefix=CHECK-FUNCTION-PRINT
|
||||||
|
; CHECK-FUNCTION-PRINT: Starting module pass manager
|
||||||
|
; CHECK-FUNCTION-PRINT: Starting function pass manager
|
||||||
|
; CHECK-FUNCTION-PRINT: Running function pass: PrintFunctionPass
|
||||||
|
; CHECK-FUNCTION-PRINT-NOT: ModuleID
|
||||||
|
; CHECK-FUNCTION-PRINT: define void @foo()
|
||||||
|
; CHECK-FUNCTION-PRINT: Finished function pass manager
|
||||||
|
; CHECK-FUNCTION-PRINT: Finished module pass manager
|
||||||
|
|
||||||
|
define void @foo() {
|
||||||
|
ret void
|
||||||
|
}
|
@@ -15,7 +15,9 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "Passes.h"
|
#include "Passes.h"
|
||||||
|
#include "llvm/IR/IRPrintingPasses.h"
|
||||||
#include "llvm/IR/PassManager.h"
|
#include "llvm/IR/PassManager.h"
|
||||||
|
#include "llvm/Support/Debug.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@@ -39,12 +41,14 @@ struct NoOpFunctionPass {
|
|||||||
// under different macros.
|
// under different macros.
|
||||||
static bool isModulePassName(StringRef Name) {
|
static bool isModulePassName(StringRef Name) {
|
||||||
if (Name == "no-op-module") return true;
|
if (Name == "no-op-module") return true;
|
||||||
|
if (Name == "print") return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isFunctionPassName(StringRef Name) {
|
static bool isFunctionPassName(StringRef Name) {
|
||||||
if (Name == "no-op-function") return true;
|
if (Name == "no-op-function") return true;
|
||||||
|
if (Name == "print") return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -54,6 +58,10 @@ static bool parseModulePassName(ModulePassManager &MPM, StringRef Name) {
|
|||||||
MPM.addPass(NoOpModulePass());
|
MPM.addPass(NoOpModulePass());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (Name == "print") {
|
||||||
|
MPM.addPass(PrintModulePass(dbgs()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,6 +70,10 @@ static bool parseFunctionPassName(FunctionPassManager &FPM, StringRef Name) {
|
|||||||
FPM.addPass(NoOpFunctionPass());
|
FPM.addPass(NoOpFunctionPass());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (Name == "print") {
|
||||||
|
FPM.addPass(PrintFunctionPass(dbgs()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user