FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LLVM-Examples/NewPMExample/ModulePass.cpp at master · codersguild/LLVM-Examples · GitHub
codersguild
/
LLVM-Examples
Public
forked from
lahiri-phdworks/LLVM-Examples
Notifications
You must be signed in to change notification settings
Fork
1
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LLVM-Examples
/
NewPMExample
/
ModulePass.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
59 lines (51 loc) · 1.81 KB
Breadcrumbs
LLVM-Examples
/
NewPMExample
/
ModulePass.cpp
Copy path
File metadata and controls
59 lines (51 loc) · 1.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#
include
"
llvm/Analysis/CFG.h
"
#
include
"
llvm/IR/InstIterator.h
"
#
include
"
llvm/IR/Instructions.h
"
#
include
"
llvm/IR/Module.h
"
#
include
"
llvm/IR/PassManager.h
"
#
include
"
llvm/Passes/PassBuilder.h
"
#
include
"
llvm/Passes/PassPlugin.h
"
#
include
"
llvm/Support/raw_ostream.h
"
//
only needed for printing
#
include
<
iostream
>
using
namespace
llvm
;
namespace
{
struct
FirstModulePass
:
public
PassInfoMixin
<FirstModulePass> {
PreservedAnalyses
run
(Module &M, ModuleAnalysisManager &
FAM
) {
//
What we intend do do in the pass starts here.
errs
() <<
"
Module :
"
<< M.
getName
().
str
() <<
"
\n
"
;
for
(
auto
&F : M) {
if
(F.
getName
().
str
() !=
"
main
"
)
continue
;
errs
() <<
"
\t
Function :
"
<< F.
getName
().
str
() <<
"
\n
"
;
for
(
auto
&
BB
: F) {
errs
() <<
"
\t\t
Basic Block :
"
<<
BB
.
getName
().
str
() <<
"
\n
"
;
for
(
auto
inst =
BB
.
rbegin
(); inst !=
BB
.
rend
(); ++inst) {
Instruction *I = &*inst;
auto
phi = dyn_cast<PHINode>(&*inst);
if
(phi !=
NULL
)
errs
() <<
"
\t\t
Phi Nodes :
"
<< phi <<
"
\n
"
;
}
}
}
//
Preserve previous analysis in the pass. Like Dominator information.
//
THe pass we made does not modify that.
return
PreservedAnalyses::all
();
}
};
}
//
namespace
//
Registering the pass.
extern
"
C
"
::llvm::PassPluginLibraryInfo
LLVM_ATTRIBUTE_WEAK
llvmGetPassPluginInfo
() {
return
{
LLVM_PLUGIN_API_VERSION
,
"
FirstPass
"
,
"
v0.1
"
, [](PassBuilder &
PB
) {
PB
.
registerPipelineParsingCallback
(
[](StringRef Name, ModulePassManager &
FPM
,
ArrayRef<PassBuilder::PipelineElement>) {
if
(Name ==
"
firstpass
"
) {
FPM
.
addPass
(
FirstModulePass
());
return
true
;
}
return
false
;
});
}};
}
Back
|
FazBrowse Home
|
New Git URL