Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wasm-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
wasm-watermarker
Commits
84c4df98
Commit
84c4df98
authored
Apr 09, 2019
by
nagayama15
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract side effect checking from watermarker
parent
38f1c1e2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
295 additions
and
258 deletions
+295
-258
operand_swapping_watermarker.cpp
src/kyut/pass/operand_swapping_watermarker.cpp
+5
-258
side_effect_checker.hpp
src/kyut/pass/side_effect_checker.hpp
+290
-0
No files found.
src/kyut/pass/operand_swapping_watermarker.cpp
View file @
84c4df98
...
@@ -4,11 +4,12 @@
...
@@ -4,11 +4,12 @@
#include "../commutativity.hpp"
#include "../commutativity.hpp"
#include "../comparison.hpp"
#include "../comparison.hpp"
#include "../side_effect.hpp"
#include "side_effect_checker.hpp"
namespace
kyut
::
pass
{
namespace
kyut
::
pass
{
class
OperandSwappingWatermarkingVisitor
class
OperandSwappingWatermarkingVisitor
:
public
wasm
::
Overridde
nVisitor
<
OperandSwappingWatermarkingVisitor
,
SideEffect
>
{
:
public
wasm
::
UnifiedExpressio
nVisitor
<
OperandSwappingWatermarkingVisitor
,
SideEffect
>
{
public
:
public
:
explicit
OperandSwappingWatermarkingVisitor
(
CircularBitStream
&
stream
)
explicit
OperandSwappingWatermarkingVisitor
(
CircularBitStream
&
stream
)
:
stream_
(
stream
)
{}
:
stream_
(
stream
)
{}
...
@@ -21,199 +22,8 @@ namespace kyut::pass {
...
@@ -21,199 +22,8 @@ namespace kyut::pass {
~
OperandSwappingWatermarkingVisitor
()
noexcept
=
default
;
~
OperandSwappingWatermarkingVisitor
()
noexcept
=
default
;
SideEffect
visitBlock
(
wasm
::
Block
*
curr
)
{
SideEffect
visitExpression
(
wasm
::
Expression
*
curr
)
{
auto
side_effect
=
SideEffect
::
none
;
return
SideEffectCheckingVisitor
{}.
visit
(
curr
);
for
(
const
auto
&
expr
:
curr
->
list
)
{
side_effect
=
(
std
::
max
)(
visit
(
expr
),
side_effect
);
}
return
side_effect
;
}
SideEffect
visitIf
(
wasm
::
If
*
curr
)
{
auto
side_effect
=
SideEffect
::
none
;
side_effect
=
(
std
::
max
)(
visit
(
curr
->
condition
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
ifTrue
),
side_effect
);
if
(
curr
->
ifFalse
)
{
side_effect
=
(
std
::
max
)(
visit
(
curr
->
ifFalse
),
side_effect
);
}
return
side_effect
;
}
SideEffect
visitLoop
(
wasm
::
Loop
*
curr
)
{
return
visit
(
curr
->
body
);
}
SideEffect
visitBreak
(
wasm
::
Break
*
curr
)
{
if
(
curr
->
condition
)
{
visit
(
curr
->
condition
);
}
if
(
curr
->
value
)
{
visit
(
curr
->
value
);
}
return
SideEffect
::
write
;
}
SideEffect
visitSwitch
(
wasm
::
Switch
*
curr
)
{
visit
(
curr
->
condition
);
if
(
curr
->
value
)
{
visit
(
curr
->
value
);
}
return
SideEffect
::
write
;
}
SideEffect
visitCall
(
wasm
::
Call
*
curr
)
{
for
(
const
auto
&
expr
:
curr
->
operands
)
{
visit
(
expr
);
}
return
SideEffect
::
write
;
}
SideEffect
visitCallIndirect
(
wasm
::
CallIndirect
*
curr
)
{
visit
(
curr
->
target
);
for
(
const
auto
&
expr
:
curr
->
operands
)
{
visit
(
expr
);
}
return
SideEffect
::
write
;
}
SideEffect
visitGetLocal
([[
maybe_unused
]]
wasm
::
GetLocal
*
curr
)
{
return
SideEffect
::
read
;
}
SideEffect
visitSetLocal
(
wasm
::
SetLocal
*
curr
)
{
visit
(
curr
->
value
);
return
SideEffect
::
write
;
}
SideEffect
visitGetGlobal
([[
maybe_unused
]]
wasm
::
GetGlobal
*
curr
)
{
return
SideEffect
::
read
;
}
SideEffect
visitSetGlobal
(
wasm
::
SetGlobal
*
curr
)
{
visit
(
curr
->
value
);
return
SideEffect
::
write
;
}
SideEffect
visitLoad
(
wasm
::
Load
*
curr
)
{
return
(
std
::
max
)(
visit
(
curr
->
ptr
),
SideEffect
::
read
);
}
SideEffect
visitStore
(
wasm
::
Store
*
curr
)
{
visit
(
curr
->
ptr
);
visit
(
curr
->
value
);
return
SideEffect
::
write
;
}
SideEffect
visitAtomicRMW
(
wasm
::
AtomicRMW
*
curr
)
{
visit
(
curr
->
ptr
);
visit
(
curr
->
value
);
return
SideEffect
::
write
;
}
SideEffect
visitAtomicCmpxchg
(
wasm
::
AtomicCmpxchg
*
curr
)
{
visit
(
curr
->
ptr
);
visit
(
curr
->
expected
);
visit
(
curr
->
replacement
);
return
SideEffect
::
write
;
}
SideEffect
visitAtomicWait
(
wasm
::
AtomicWait
*
curr
)
{
visit
(
curr
->
ptr
);
visit
(
curr
->
expected
);
visit
(
curr
->
timeout
);
return
SideEffect
::
write
;
}
SideEffect
visitAtomicNotify
(
wasm
::
AtomicNotify
*
curr
)
{
visit
(
curr
->
ptr
);
visit
(
curr
->
notifyCount
);
return
SideEffect
::
write
;
}
SideEffect
visitSIMDExtract
(
wasm
::
SIMDExtract
*
curr
)
{
return
visit
(
curr
->
vec
);
}
SideEffect
visitSIMDReplace
(
wasm
::
SIMDReplace
*
curr
)
{
auto
side_effect
=
SideEffect
::
none
;
side_effect
=
(
std
::
max
)(
visit
(
curr
->
vec
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
value
),
side_effect
);
return
side_effect
;
}
SideEffect
visitSIMDShuffle
(
wasm
::
SIMDShuffle
*
curr
)
{
auto
side_effect
=
SideEffect
::
none
;
side_effect
=
(
std
::
max
)(
visit
(
curr
->
left
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
right
),
side_effect
);
return
side_effect
;
}
SideEffect
visitSIMDBitselect
(
wasm
::
SIMDBitselect
*
curr
)
{
auto
side_effect
=
SideEffect
::
none
;
side_effect
=
(
std
::
max
)(
visit
(
curr
->
cond
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
left
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
right
),
side_effect
);
return
side_effect
;
}
SideEffect
visitSIMDShift
(
wasm
::
SIMDShift
*
curr
)
{
auto
side_effect
=
SideEffect
::
none
;
side_effect
=
(
std
::
max
)(
visit
(
curr
->
vec
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
shift
),
side_effect
);
return
side_effect
;
}
SideEffect
visitMemoryInit
(
wasm
::
MemoryInit
*
curr
)
{
visit
(
curr
->
dest
);
visit
(
curr
->
offset
);
visit
(
curr
->
size
);
return
SideEffect
::
write
;
}
SideEffect
visitDataDrop
([[
maybe_unused
]]
wasm
::
DataDrop
*
curr
)
{
return
SideEffect
::
write
;
}
SideEffect
visitMemoryCopy
(
wasm
::
MemoryCopy
*
curr
)
{
visit
(
curr
->
dest
);
visit
(
curr
->
source
);
visit
(
curr
->
size
);
return
SideEffect
::
write
;
}
SideEffect
visitMemoryFill
(
wasm
::
MemoryFill
*
curr
)
{
visit
(
curr
->
dest
);
visit
(
curr
->
value
);
visit
(
curr
->
size
);
return
SideEffect
::
write
;
}
SideEffect
visitConst
([[
maybe_unused
]]
wasm
::
Const
*
curr
)
{
return
SideEffect
::
none
;
}
SideEffect
visitUnary
(
wasm
::
Unary
*
curr
)
{
return
visit
(
curr
->
value
);
}
}
SideEffect
visitBinary
(
wasm
::
Binary
*
curr
)
{
SideEffect
visitBinary
(
wasm
::
Binary
*
curr
)
{
...
@@ -235,69 +45,6 @@ namespace kyut::pass {
...
@@ -235,69 +45,6 @@ namespace kyut::pass {
return
(
std
::
max
)(
side_effect_left
,
side_effect_right
);
return
(
std
::
max
)(
side_effect_left
,
side_effect_right
);
}
}
SideEffect
visitSelect
(
wasm
::
Select
*
curr
)
{
auto
side_effect
=
SideEffect
::
none
;
side_effect
=
(
std
::
max
)(
visit
(
curr
->
condition
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
ifTrue
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
ifFalse
),
side_effect
);
return
side_effect
;
}
SideEffect
visitDrop
(
wasm
::
Drop
*
curr
)
{
return
visit
(
curr
->
value
);
}
SideEffect
visitReturn
(
wasm
::
Return
*
curr
)
{
if
(
curr
->
value
)
{
visit
(
curr
->
value
);
}
return
SideEffect
::
write
;
}
SideEffect
visitHost
(
wasm
::
Host
*
curr
)
{
for
(
const
auto
&
expr
:
curr
->
operands
)
{
visit
(
expr
);
}
if
(
curr
->
op
==
wasm
::
HostOp
::
CurrentMemory
)
{
return
SideEffect
::
read
;
}
else
{
return
SideEffect
::
write
;
}
}
SideEffect
visitNop
([[
maybe_unused
]]
wasm
::
Nop
*
curr
)
{
return
SideEffect
::
none
;
}
SideEffect
visitUnreachable
([[
maybe_unused
]]
wasm
::
Unreachable
*
curr
)
{
WASM_UNREACHABLE
();
}
SideEffect
visitFunctionType
([[
maybe_unused
]]
wasm
::
FunctionType
*
curr
)
{
WASM_UNREACHABLE
();
}
SideEffect
visitExport
([[
maybe_unused
]]
wasm
::
Export
*
curr
)
{
WASM_UNREACHABLE
();
}
SideEffect
visitGlobal
([[
maybe_unused
]]
wasm
::
Global
*
curr
)
{
WASM_UNREACHABLE
();
}
SideEffect
visitFunction
([[
maybe_unused
]]
wasm
::
Function
*
curr
)
{
WASM_UNREACHABLE
();
}
SideEffect
visitTable
([[
maybe_unused
]]
wasm
::
Table
*
curr
)
{
WASM_UNREACHABLE
();
}
SideEffect
visitMemory
([[
maybe_unused
]]
wasm
::
Memory
*
curr
)
{
WASM_UNREACHABLE
();
}
SideEffect
visitModule
([[
maybe_unused
]]
wasm
::
Module
*
curr
)
{
WASM_UNREACHABLE
();
}
private
:
private
:
CircularBitStream
&
stream_
;
CircularBitStream
&
stream_
;
};
};
...
...
src/kyut/pass/side_effect_checker.hpp
0 → 100644
View file @
84c4df98
#ifndef INCLUDE_kyut_pass_side_effect_checker_hpp
#define INCLUDE_kyut_pass_side_effect_checker_hpp
#include <wasm-traversal.h>
#include "../side_effect.hpp"
namespace
kyut
::
pass
{
class
SideEffectCheckingVisitor
:
public
wasm
::
OverriddenVisitor
<
SideEffectCheckingVisitor
,
SideEffect
>
{
public
:
explicit
SideEffectCheckingVisitor
()
=
default
;
SideEffectCheckingVisitor
(
const
SideEffectCheckingVisitor
&
)
=
delete
;
SideEffectCheckingVisitor
(
SideEffectCheckingVisitor
&&
)
=
delete
;
SideEffectCheckingVisitor
&
operator
=
(
const
SideEffectCheckingVisitor
&
)
=
delete
;
SideEffectCheckingVisitor
&
operator
=
(
SideEffectCheckingVisitor
&&
)
=
delete
;
~
SideEffectCheckingVisitor
()
noexcept
=
default
;
SideEffect
visitBlock
(
wasm
::
Block
*
curr
)
{
auto
side_effect
=
SideEffect
::
none
;
for
(
const
auto
&
expr
:
curr
->
list
)
{
side_effect
=
(
std
::
max
)(
visit
(
expr
),
side_effect
);
}
return
side_effect
;
}
SideEffect
visitIf
(
wasm
::
If
*
curr
)
{
auto
side_effect
=
SideEffect
::
none
;
side_effect
=
(
std
::
max
)(
visit
(
curr
->
condition
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
ifTrue
),
side_effect
);
if
(
curr
->
ifFalse
)
{
side_effect
=
(
std
::
max
)(
visit
(
curr
->
ifFalse
),
side_effect
);
}
return
side_effect
;
}
SideEffect
visitLoop
(
wasm
::
Loop
*
curr
)
{
return
visit
(
curr
->
body
);
}
SideEffect
visitBreak
(
wasm
::
Break
*
curr
)
{
if
(
curr
->
condition
)
{
visit
(
curr
->
condition
);
}
if
(
curr
->
value
)
{
visit
(
curr
->
value
);
}
return
SideEffect
::
write
;
}
SideEffect
visitSwitch
(
wasm
::
Switch
*
curr
)
{
visit
(
curr
->
condition
);
if
(
curr
->
value
)
{
visit
(
curr
->
value
);
}
return
SideEffect
::
write
;
}
SideEffect
visitCall
(
wasm
::
Call
*
curr
)
{
for
(
const
auto
&
expr
:
curr
->
operands
)
{
visit
(
expr
);
}
return
SideEffect
::
write
;
}
SideEffect
visitCallIndirect
(
wasm
::
CallIndirect
*
curr
)
{
visit
(
curr
->
target
);
for
(
const
auto
&
expr
:
curr
->
operands
)
{
visit
(
expr
);
}
return
SideEffect
::
write
;
}
SideEffect
visitGetLocal
([[
maybe_unused
]]
wasm
::
GetLocal
*
curr
)
{
return
SideEffect
::
read
;
}
SideEffect
visitSetLocal
(
wasm
::
SetLocal
*
curr
)
{
visit
(
curr
->
value
);
return
SideEffect
::
write
;
}
SideEffect
visitGetGlobal
([[
maybe_unused
]]
wasm
::
GetGlobal
*
curr
)
{
return
SideEffect
::
read
;
}
SideEffect
visitSetGlobal
(
wasm
::
SetGlobal
*
curr
)
{
visit
(
curr
->
value
);
return
SideEffect
::
write
;
}
SideEffect
visitLoad
(
wasm
::
Load
*
curr
)
{
return
(
std
::
max
)(
visit
(
curr
->
ptr
),
SideEffect
::
read
);
}
SideEffect
visitStore
(
wasm
::
Store
*
curr
)
{
visit
(
curr
->
ptr
);
visit
(
curr
->
value
);
return
SideEffect
::
write
;
}
SideEffect
visitAtomicRMW
(
wasm
::
AtomicRMW
*
curr
)
{
visit
(
curr
->
ptr
);
visit
(
curr
->
value
);
return
SideEffect
::
write
;
}
SideEffect
visitAtomicCmpxchg
(
wasm
::
AtomicCmpxchg
*
curr
)
{
visit
(
curr
->
ptr
);
visit
(
curr
->
expected
);
visit
(
curr
->
replacement
);
return
SideEffect
::
write
;
}
SideEffect
visitAtomicWait
(
wasm
::
AtomicWait
*
curr
)
{
visit
(
curr
->
ptr
);
visit
(
curr
->
expected
);
visit
(
curr
->
timeout
);
return
SideEffect
::
write
;
}
SideEffect
visitAtomicNotify
(
wasm
::
AtomicNotify
*
curr
)
{
visit
(
curr
->
ptr
);
visit
(
curr
->
notifyCount
);
return
SideEffect
::
write
;
}
SideEffect
visitSIMDExtract
(
wasm
::
SIMDExtract
*
curr
)
{
return
visit
(
curr
->
vec
);
}
SideEffect
visitSIMDReplace
(
wasm
::
SIMDReplace
*
curr
)
{
auto
side_effect
=
SideEffect
::
none
;
side_effect
=
(
std
::
max
)(
visit
(
curr
->
vec
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
value
),
side_effect
);
return
side_effect
;
}
SideEffect
visitSIMDShuffle
(
wasm
::
SIMDShuffle
*
curr
)
{
auto
side_effect
=
SideEffect
::
none
;
side_effect
=
(
std
::
max
)(
visit
(
curr
->
left
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
right
),
side_effect
);
return
side_effect
;
}
SideEffect
visitSIMDBitselect
(
wasm
::
SIMDBitselect
*
curr
)
{
auto
side_effect
=
SideEffect
::
none
;
side_effect
=
(
std
::
max
)(
visit
(
curr
->
cond
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
left
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
right
),
side_effect
);
return
side_effect
;
}
SideEffect
visitSIMDShift
(
wasm
::
SIMDShift
*
curr
)
{
auto
side_effect
=
SideEffect
::
none
;
side_effect
=
(
std
::
max
)(
visit
(
curr
->
vec
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
shift
),
side_effect
);
return
side_effect
;
}
SideEffect
visitMemoryInit
(
wasm
::
MemoryInit
*
curr
)
{
visit
(
curr
->
dest
);
visit
(
curr
->
offset
);
visit
(
curr
->
size
);
return
SideEffect
::
write
;
}
SideEffect
visitDataDrop
([[
maybe_unused
]]
wasm
::
DataDrop
*
curr
)
{
return
SideEffect
::
write
;
}
SideEffect
visitMemoryCopy
(
wasm
::
MemoryCopy
*
curr
)
{
visit
(
curr
->
dest
);
visit
(
curr
->
source
);
visit
(
curr
->
size
);
return
SideEffect
::
write
;
}
SideEffect
visitMemoryFill
(
wasm
::
MemoryFill
*
curr
)
{
visit
(
curr
->
dest
);
visit
(
curr
->
value
);
visit
(
curr
->
size
);
return
SideEffect
::
write
;
}
SideEffect
visitConst
([[
maybe_unused
]]
wasm
::
Const
*
curr
)
{
return
SideEffect
::
none
;
}
SideEffect
visitUnary
(
wasm
::
Unary
*
curr
)
{
return
visit
(
curr
->
value
);
}
SideEffect
visitBinary
(
wasm
::
Binary
*
curr
)
{
auto
side_effect
=
SideEffect
::
none
;
side_effect
=
(
std
::
max
)(
visit
(
curr
->
left
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
right
),
side_effect
);
return
side_effect
;
}
SideEffect
visitSelect
(
wasm
::
Select
*
curr
)
{
auto
side_effect
=
SideEffect
::
none
;
side_effect
=
(
std
::
max
)(
visit
(
curr
->
condition
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
ifTrue
),
side_effect
);
side_effect
=
(
std
::
max
)(
visit
(
curr
->
ifFalse
),
side_effect
);
return
side_effect
;
}
SideEffect
visitDrop
(
wasm
::
Drop
*
curr
)
{
return
visit
(
curr
->
value
);
}
SideEffect
visitReturn
(
wasm
::
Return
*
curr
)
{
if
(
curr
->
value
)
{
visit
(
curr
->
value
);
}
return
SideEffect
::
write
;
}
SideEffect
visitHost
(
wasm
::
Host
*
curr
)
{
for
(
const
auto
&
expr
:
curr
->
operands
)
{
visit
(
expr
);
}
if
(
curr
->
op
==
wasm
::
HostOp
::
CurrentMemory
)
{
return
SideEffect
::
read
;
}
else
{
return
SideEffect
::
write
;
}
}
SideEffect
visitNop
([[
maybe_unused
]]
wasm
::
Nop
*
curr
)
{
return
SideEffect
::
none
;
}
SideEffect
visitUnreachable
([[
maybe_unused
]]
wasm
::
Unreachable
*
curr
)
{
WASM_UNREACHABLE
();
}
SideEffect
visitFunctionType
([[
maybe_unused
]]
wasm
::
FunctionType
*
curr
)
{
WASM_UNREACHABLE
();
}
SideEffect
visitExport
([[
maybe_unused
]]
wasm
::
Export
*
curr
)
{
WASM_UNREACHABLE
();
}
SideEffect
visitGlobal
([[
maybe_unused
]]
wasm
::
Global
*
curr
)
{
WASM_UNREACHABLE
();
}
SideEffect
visitFunction
([[
maybe_unused
]]
wasm
::
Function
*
curr
)
{
WASM_UNREACHABLE
();
}
SideEffect
visitTable
([[
maybe_unused
]]
wasm
::
Table
*
curr
)
{
WASM_UNREACHABLE
();
}
SideEffect
visitMemory
([[
maybe_unused
]]
wasm
::
Memory
*
curr
)
{
WASM_UNREACHABLE
();
}
SideEffect
visitModule
([[
maybe_unused
]]
wasm
::
Module
*
curr
)
{
WASM_UNREACHABLE
();
}
};
}
// namespace kyut::pass
#endif // INCLUDE_kyut_pass_side_effect_checker_hpp
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