Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
llvm-watermarker
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nagayama15
llvm-watermarker
Commits
0a126b1c
Commit
0a126b1c
authored
Nov 16, 2018
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ディレクトリ構造を変更
parent
1f5c48fc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
63 deletions
+95
-63
Makefile
Makefile
+1
-3
TestPass.cpp
src/nykk/TestPass.cpp
+0
-60
TestPass.cpp
src/nykk/pass/TestPass.cpp
+94
-0
No files found.
Makefile
View file @
0a126b1c
...
...
@@ -16,10 +16,8 @@ LDFLAGS := \
all
:
testpass.so
testpass.so
:
src/nykk/TestPass.o
testpass.so
:
src/nykk/
pass/
TestPass.o
${
CXX
}
${
CXXFLAGS
}
-shared
-o
$@
$<
${
LDFLAGS
}
src/nykk/TestPass.o
:
src/nykk/TestPass.cpp src/nykk/TestPass.hpp
clean
:
${
RM
}
*
.so src/
*
/
*
.o
src/nykk/TestPass.cpp
deleted
100644 → 0
View file @
1f5c48fc
#include "TestPass.hpp"
#include <llvm/IR/Function.h>
#include <llvm/IR/Module.h>
#include <llvm/Support/raw_ostream.h>
// Register pass.
llvm
::
RegisterPass
<
nykk
::
TestPass
>
g_test_pass
{
"testpass"
,
"Test pass"
,
};
namespace
nykk
{
// Pass id.
char
TestPass
::
ID
;
// Constructor of TestPass.
TestPass
::
TestPass
()
:
FunctionPass
(
ID
)
{
}
// Initialization before pass is run
bool
TestPass
::
doInitialization
(
llvm
::
Module
&
module
)
{
llvm
::
errs
()
<<
__FUNCTION__
<<
" : "
<<
module
.
getName
()
<<
"
\n
"
;
return
false
;
}
// Finalization after pass is run
bool
TestPass
::
doFinalization
(
llvm
::
Module
&
module
)
{
llvm
::
errs
()
<<
__FUNCTION__
<<
" : "
<<
module
.
getName
()
<<
"
\n
"
;
return
false
;
}
// Processes functions.
bool
TestPass
::
runOnFunction
(
llvm
::
Function
&
func
)
{
llvm
::
errs
()
<<
__FUNCTION__
<<
" : "
<<
func
.
getName
()
<<
"
\n
"
;
llvm
::
errs
()
<<
" "
<<
"bbs : "
<<
func
.
getBasicBlockList
().
size
()
<<
"
\n
"
;
if
(
func
.
getBasicBlockList
().
size
()
<
3
)
{
return
false
;
}
// Swap 2nd and 3rd basic blocks.
llvm
::
BasicBlock
&
entry_bb
=
func
.
getEntryBlock
();
llvm
::
BasicBlock
*
bb1
=
entry_bb
.
getNextNode
();
llvm
::
BasicBlock
*
bb2
=
bb1
->
getNextNode
();
bb1
->
moveAfter
(
bb2
);
return
true
;
}
}
src/nykk/
TestPass.h
pp
→
src/nykk/
pass/TestPass.c
pp
View file @
0a126b1c
#ifndef INCLUDE_NYKK_TESTPASS_HPP
#define INCLUDE_NYKK_TESTPASS_HPP
#include <llvm/IR/Function.h>
#include <llvm/IR/Module.h>
#include <llvm/Pass.h>
#include <llvm/Support/raw_ostream.h>
namespace
nykk
namespace
{
class
TestPass
:
public
llvm
::
FunctionPass
{
public
:
static
char
ID
;
//
F
or LLVM.
static
char
ID
;
//
Needed f
or LLVM.
explicit
TestPass
();
/**
* @brief Constructor.
*/
explicit
TestPass
()
:
FunctionPass
(
ID
)
{
}
// Uncopyable, unmovable.
TestPass
(
const
TestPass
&
)
=
delete
;
...
...
@@ -29,7 +35,12 @@ namespace nykk
*
* @return ?
*/
bool
doInitialization
(
llvm
::
Module
&
module
)
override
;
bool
doInitialization
(
llvm
::
Module
&
module
)
override
{
llvm
::
errs
()
<<
__FUNCTION__
<<
" : "
<<
module
.
getName
()
<<
"
\n
"
;
return
false
;
}
/**
* @brief Finalization after pass is run.
...
...
@@ -38,7 +49,12 @@ namespace nykk
*
* @return ?
*/
bool
doFinalization
(
llvm
::
Module
&
module
)
override
;
bool
doFinalization
(
llvm
::
Module
&
module
)
override
{
llvm
::
errs
()
<<
__FUNCTION__
<<
" : "
<<
module
.
getName
()
<<
"
\n
"
;
return
false
;
}
/**
* @brief Processes functions.
...
...
@@ -47,8 +63,32 @@ namespace nykk
*
* @return `true` if the function was changed.
*/
bool
runOnFunction
(
llvm
::
Function
&
func
)
override
;
bool
runOnFunction
(
llvm
::
Function
&
func
)
override
{
llvm
::
errs
()
<<
__FUNCTION__
<<
" : "
<<
func
.
getName
()
<<
"
\n
"
;
llvm
::
errs
()
<<
" "
<<
"bbs : "
<<
func
.
getBasicBlockList
().
size
()
<<
"
\n
"
;
if
(
func
.
getBasicBlockList
().
size
()
<
3
)
{
return
false
;
}
// Swap 2nd and 3rd basic blocks.
llvm
::
BasicBlock
&
entry_bb
=
func
.
getEntryBlock
();
llvm
::
BasicBlock
*
bb1
=
entry_bb
.
getNextNode
();
llvm
::
BasicBlock
*
bb2
=
bb1
->
getNextNode
();
bb1
->
moveAfter
(
bb2
);
return
true
;
}
};
}
#endif
char
TestPass
::
ID
;
// Register pass.
llvm
::
RegisterPass
<
TestPass
>
test_pass_registry
{
"testpass"
,
"Test pass"
,
};
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment