LLVM: lib/IR/IRPrintingPasses.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

24

25using namespace llvm;

26

27namespace {

28

29class PrintModulePassWrapper : public ModulePass {

30 raw_ostream &OS;

31 std::string Banner;

32 bool ShouldPreserveUseListOrder;

33

34public:

35 static char ID;

36 PrintModulePassWrapper() : ModulePass(ID), OS(dbgs()) {}

37 PrintModulePassWrapper(raw_ostream &OS, const std::string &Banner,

38 bool ShouldPreserveUseListOrder)

39 : ModulePass(ID), OS(OS), Banner(Banner),

40 ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {}

41

42 bool runOnModule(Module &M) override {

43

44

45 M.removeDebugIntrinsicDeclarations();

46

48 if (!Banner.empty())

49 OS << Banner << "\n";

50 M.print(OS, nullptr, ShouldPreserveUseListOrder);

51 } else {

52 bool BannerPrinted = false;

53 for (const auto &F : M.functions()) {

55 if (!BannerPrinted && !Banner.empty()) {

56 OS << Banner << "\n";

57 BannerPrinted = true;

58 }

59 F.print(OS);

60 }

61 }

62 }

63

64 return false;

65 }

66

67 void getAnalysisUsage(AnalysisUsage &AU) const override {

69 }

70

71 StringRef getPassName() const override { return "Print Module IR"; }

72};

73

74class PrintFunctionPassWrapper : public FunctionPass {

75 raw_ostream &OS;

76 std::string Banner;

77

78public:

79 static char ID;

80 PrintFunctionPassWrapper() : FunctionPass(ID), OS(dbgs()) {}

81 PrintFunctionPassWrapper(raw_ostream &OS, const std::string &Banner)

82 : FunctionPass(ID), OS(OS), Banner(Banner) {}

83

84

88 OS << Banner << " (function: " << F.getName() << ")\n"

89 << *F.getParent();

90 else

91 OS << Banner << '\n' << static_cast<Value &>(F);

92 }

93

94 return false;

95 }

96

97 void getAnalysisUsage(AnalysisUsage &AU) const override {

99 }

100

101 StringRef getPassName() const override { return "Print Function IR"; }

102};

103

104}

105

106char PrintModulePassWrapper::ID = 0;

108 "Print module to stderr", false, true)

109char PrintFunctionPassWrapper::ID = 0;

111 "Print function to stderr", false, true)

112

115 bool ShouldPreserveUseListOrder) {

116 return new PrintModulePassWrapper(OS, Banner, ShouldPreserveUseListOrder);

117}

118

120 const std::string &Banner) {

121 return new PrintFunctionPassWrapper(OS, Banner);

122}

123

125 const char *PID = (const char *)P->getPassID();

126

127 return (PID == &PrintModulePassWrapper::ID) ||

128 (PID == &PrintFunctionPassWrapper::ID);

129}

static bool runOnFunction(Function &F, bool PostInlining)

This file contains an interface for creating legacy passes to print out IR in various granularities.

Module.h This file contains the declarations for the Module class.

Machine Check Debug Module

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)

void setPreservesAll()

Set by analyses that do not transform their input at all.

FunctionPass class - This class is used to implement most global optimizations.

ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...

Pass interface - Implemented by all 'passes'.

This class implements an extremely fast bulk output stream that can only output to a stream.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

This is an optimization pass for GlobalISel generic memory operations.

bool forcePrintModuleIR()

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

bool isFunctionInPrintList(StringRef FunctionName)

LLVM_ABI bool isIRPrintingPass(Pass *P)

Return true if a pass is for IR printing.

Definition IRPrintingPasses.cpp:124

LLVM_ABI ModulePass * createPrintModulePass(raw_ostream &OS, const std::string &Banner="", bool ShouldPreserveUseListOrder=false)

Create and return a pass that writes the module to the specified raw_ostream.

LLVM_ABI FunctionPass * createPrintFunctionPass(raw_ostream &OS, const std::string &Banner="")

Create and return a pass that prints functions to the specified raw_ostream as they are processed.

Definition IRPrintingPasses.cpp:119

Implement std::hash so that hash_code can be used in STL containers.