Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Guruprasad Hegde
TAS-OPT
Commits
d957cce9
Commit
d957cce9
authored
Oct 24, 2019
by
guruhegde
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create tasopt binary
* Contains pass pipeline for tas.
parent
acfd7363
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
34 deletions
+73
-34
src/BatchMaker.cpp
src/BatchMaker.cpp
+2
-2
src/BatchMaker.h
src/BatchMaker.h
+1
-1
src/LoopSplitter.cpp
src/LoopSplitter.cpp
+3
-3
src/PassWrapper/BatchMakerPass.cpp
src/PassWrapper/BatchMakerPass.cpp
+3
-1
test/unittests/inputs/fast_flows.c
test/unittests/inputs/fast_flows.c
+21
-8
tools/tasopt.cpp
tools/tasopt.cpp
+43
-19
No files found.
src/BatchMaker.cpp
View file @
d957cce9
...
...
@@ -235,10 +235,10 @@ void BatchMaker::doBatchTransform() {
addBatchLoop
(
RetBlock
,
IdxPtr
);
}
bool
BatchMaker
::
run
()
{
Function
*
BatchMaker
::
run
()
{
detectBatchParameters
(
NonBatchFunc
,
ArgsToBatch
);
doBatchTransform
();
return
true
;
return
BatchFunc
;
}
}
// tas namespace
src/BatchMaker.h
View file @
d957cce9
...
...
@@ -54,7 +54,7 @@ class BatchMaker {
NonBatchFunc
(
F_
),
BatchFunc
(
nullptr
),
Builder
(
NonBatchFunc
->
getContext
())
{}
bool
run
();
llvm
::
Function
*
run
();
};
// tas namespace
}
...
...
src/LoopSplitter.cpp
View file @
d957cce9
...
...
@@ -62,9 +62,6 @@ void LoopSplitter::addAdapterBasicBlocks(Instruction * SP, Value * Idx) {
auto
BrValPtr
=
Builder
.
CreateGEP
(
BrTgtArray
,
{
Builder
.
getInt64
(
0
),
IdxVal64
});
Builder
.
CreateStore
(
TgtBBVal
,
BrValPtr
);
TermI
->
setSuccessor
(
1
,
CollectBB
);
SwitchI
->
addCase
(
BBToId
[
FalseBB
],
FalseBB
);
}
}
...
...
@@ -72,6 +69,7 @@ void LoopSplitter::addAdapterBasicBlocks(Instruction * SP, Value * Idx) {
bool
LoopSplitter
::
prepareForLoopSplit
(
Function
*
F
,
Loop
*
L0
,
Stats
&
stat
)
{
auto
Idx
=
getLoopIndexVar
(
L0
);
auto
AnnotatedVars
=
detectExpPtrVars
(
F
);
errs
()
<<
"AnnotatedVars = "
<<
AnnotatedVars
.
size
()
<<
" "
<<
*
AnnotatedVars
.
front
()
<<
"
\n
"
;
auto
VarUsePoints
=
detectExpPtrUses
(
AnnotatedVars
);
// Add unique id to each basic block
...
...
@@ -163,10 +161,12 @@ bool LoopSplitter::run() {
ExitBlock
=
L0
->
getExitBlock
();
assert
(
ExitBlock
&&
"Loop must have a single exit block!"
);
errs
()
<<
"Running prepareForLoopSplit
\n
"
;
bool
changed
=
prepareForLoopSplit
(
F
,
L0
,
stat
);
if
(
!
changed
)
return
false
;
auto
&
SplitBB
=
LoopSplitEdgeBlocks
.
front
();
errs
()
<<
"running doLoopSplit
\n
"
;
doLoopSplit
(
F
,
L0
,
SplitBB
);
return
true
;
...
...
src/PassWrapper/BatchMakerPass.cpp
View file @
d957cce9
...
...
@@ -34,7 +34,9 @@ bool TASBatchMaker::runOnModule(Module &M) {
for
(
auto
&
FnStr
:
AnnotatedFnList
)
{
if
(
FnStr
.
second
.
compare
(
"tas_batch_maker"
)
!=
0
)
continue
;
tas
::
BatchMaker
BM
(
FnStr
.
first
);
changed
|=
BM
.
run
();
auto
BatchF
=
BM
.
run
();
if
(
!
BatchF
)
changed
=
true
;
}
return
changed
;
}
...
...
test/unittests/inputs/fast_flows.c
View file @
d957cce9
...
...
@@ -37,6 +37,9 @@
#define TCP_MSS 1448
#define TCP_MAX_RTT 100000
#define TAS_BLOCK_PREDICATION __attribute__((annotate("tas_block_predicate")))
#define BATCH_ARG __attribute__((annotate("batch_arg")))
#define EXPENSIVE __attribute__((annotate("expensive")))
//#define SKIP_ACK 1
struct
flow_key
{
...
...
@@ -274,21 +277,31 @@ void fast_flows_packet_pfbufs(struct dataplane_context *ctx,
}
}
#define TAS_BATCH_START int TAS_batch_start __attribute__((annotate("batch_begin")));
/* Received packet */
int
fast_flows_packet
(
struct
dataplane_context
*
ctx
,
struct
network_buf_handle
*
nbh
,
void
*
fsp
,
struct
tcp_opts
*
opts
,
uint32_t
ts
)
struct
network_buf_handle
*
nbh
BATCH_ARG
,
void
*
fsp
BATCH_ARG
,
struct
tcp_opts
*
opts
BATCH_ARG
,
uint32_t
ts
)
TAS_BLOCK_PREDICATION
{
struct
pkt_tcp
*
p
=
network_buf_bufoff
(
nbh
)
;
struct
flextcp_pl_flowst
*
fs
=
fsp
;
struct
pkt_tcp
*
p
;
struct
flextcp_pl_flowst
*
fs
EXPENSIVE
;
uint32_t
payload_bytes
,
payload_off
,
seq
,
ack
,
old_avail
,
new_avail
,
orig_payload
;
uint8_t
*
payload
;
uint32_t
rx_bump
=
0
,
tx_bump
=
0
,
rx_pos
,
rtt
;
int
no_permanent_sp
=
0
;
uint32_t
rx_bump
,
tx_bump
,
rx_pos
,
rtt
;
int
no_permanent_sp
;
uint16_t
tcp_extra_hlen
,
trim_start
,
trim_end
;
uint16_t
flow_id
=
fs
-
fp_state
->
flowst
;
int
trigger_ack
=
0
,
fin_bump
=
0
;
uint16_t
flow_id
;
int
trigger_ack
,
fin_bump
;
TAS_BATCH_START
p
=
network_buf_bufoff
(
nbh
);
fs
=
fsp
;
rx_bump
=
0
,
tx_bump
=
0
;
no_permanent_sp
=
0
;
flow_id
=
fs
-
fp_state
->
flowst
;
trigger_ack
=
0
,
fin_bump
=
0
;
tcp_extra_hlen
=
(
TCPH_HDRLEN
(
&
p
->
tcp
)
-
5
)
*
4
;
payload_off
=
sizeof
(
*
p
)
+
tcp_extra_hlen
;
...
...
tools/tasopt.cpp
View file @
d957cce9
//
#include <llvm/Analysis/LoopInfo.h>
#include <llvm/Analysis/LoopInfo.h>
#include <llvm/AsmParser/Parser.h>
#include <llvm/IR/Dominators.h>
#include <llvm/IR/Function.h>
...
...
@@ -12,7 +12,9 @@
#include <llvm/Support/Debug.h>
#include <llvm/Support/SourceMgr.h>
#include "BatchMaker.h"
#include "BlockPredication.h"
#include "LoopSplitter.h"
#include "ToolUtil.h"
#include "Util.h"
...
...
@@ -38,35 +40,44 @@ cl::opt<unsigned> CacheLineSize ("cacheline-size",
LLVMContext
Ctx
;
SMDiagnostic
Err
;
static
unique_ptr
<
Module
>
parseIR
(
string
Filename
,
string
FileDir
)
{
std
::
unique_ptr
<
Module
>
M
(
parseIRFile
(
FileDir
+
Filename
,
Err
,
Ctx
));
if
(
!
M
)
Err
.
print
(
"Error parsing IR: "
,
errs
());
return
M
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
cl
::
ParseCommandLineOptions
(
argc
,
argv
);
Module
*
M
=
nullptr
;
if
(
!
SrcFile
.
empty
())
{
auto
OutFile
=
tas
::
generateIR
(
SrcFile
);
if
(
OutFile
.
empty
())
{
errs
()
<<
"Error reading source file.
\n
"
;
Err
.
print
(
argv
[
0
],
errs
());
return
-
1
;
}
M
=
parseIRFile
(
OutFile
,
Err
,
Ctx
).
get
();
if
(
!
M
)
{
errs
()
<<
"Error reading IR file.
\n
"
;
Err
.
print
(
argv
[
0
],
errs
());
return
-
1
;
}
}
else
{
if
(
SrcFile
.
empty
())
{
errs
()
<<
"Source file is not given
\n
"
;
Err
.
print
(
argv
[
0
],
errs
());
return
-
1
;
}
auto
OutFile
=
tas
::
generateIR
(
SrcFile
,
""
,
true
);
if
(
OutFile
.
empty
())
{
errs
()
<<
"Error reading source file.
\n
"
;
Err
.
print
(
argv
[
0
],
errs
());
return
-
1
;
}
auto
M
=
parseIR
(
OutFile
,
""
);
if
(
!
M
)
{
errs
()
<<
"Error reading IR file.
\n
"
;
Err
.
print
(
argv
[
0
],
errs
());
return
-
1
;
}
map
<
Function
*
,
string
>
FnLists
;
tas
::
getAnnotatedFnList
(
M
,
FnLists
);
tas
::
getAnnotatedFnList
(
M
.
get
(),
FnLists
);
errs
()
<<
"number of annotated functions = "
<<
FnLists
.
size
()
<<
"
\n
"
;
for
(
auto
&
FnStr
:
FnLists
)
{
if
(
FnStr
.
second
.
compare
(
"tas_batch_maker"
)
!=
0
)
continue
;
if
(
FnStr
.
second
.
compare
(
"tas_block_predicate"
)
!=
0
)
continue
;
// Block Predication
errs
()
<<
"Running block predication on "
<<
FnStr
.
second
<<
"
\n
"
;
tas
::
BlockPredication
BP
(
FnStr
.
first
);
auto
res
=
BP
.
run
();
if
(
!
res
)
{
...
...
@@ -74,7 +85,20 @@ int main(int argc, char * argv[]) {
Err
.
print
(
argv
[
0
],
errs
());
return
-
1
;
}
// Make Batch version
tas
::
BatchMaker
BM
(
FnStr
.
first
);
auto
BatchFunc
=
BM
.
run
();
// Loop Splitting
DominatorTree
DT
(
*
BatchFunc
);
LoopInfo
LI
(
DT
);
tas
::
LoopSplitter
LS
(
BatchFunc
,
&
LI
);
res
=
LS
.
run
();
errs
()
<<
res
<<
"
\n
"
;
}
writeToAsmFile
(
*
M
);
auto
TestObject
=
generateObject
(
writeToBitCodeFile
(
*
M
));
return
0
;
}
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