Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bpftrace
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bpftrace
Commits
4a2d0f83
Commit
4a2d0f83
authored
May 20, 2017
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
codegen: Create getMapKey function
parent
7fa7a2f0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
35 deletions
+26
-35
src/codegen_llvm.cpp
src/codegen_llvm.cpp
+25
-34
src/codegen_llvm.h
src/codegen_llvm.h
+1
-1
No files found.
src/codegen_llvm.cpp
View file @
4a2d0f83
...
...
@@ -59,21 +59,7 @@ void CodegenLLVM::visit(Call &call)
void
CodegenLLVM
::
visit
(
Map
&
map
)
{
AllocaInst
*
key
;
if
(
map
.
vargs
)
{
key
=
b_
.
CreateAllocaBPF
(
map
.
vargs
->
size
());
int
i
=
0
;
for
(
Expression
*
expr
:
*
map
.
vargs
)
{
expr
->
accept
(
*
this
);
Value
*
offset
=
b_
.
CreateGEP
(
key
,
b_
.
getInt64
(
i
++
));
b_
.
CreateStore
(
expr_
,
offset
);
}
}
else
{
key
=
b_
.
CreateAllocaBPF
();
b_
.
CreateStore
(
b_
.
getInt64
(
0
),
key
);
}
AllocaInst
*
key
=
getMapKey
(
map
);
expr_
=
b_
.
CreateMapLookupElem
(
map
,
key
);
}
...
...
@@ -125,27 +111,13 @@ void CodegenLLVM::visit(ExprStatement &expr)
void
CodegenLLVM
::
visit
(
AssignMapStatement
&
assignment
)
{
Map
&
map
=
*
assignment
.
map
;
AllocaInst
*
val
=
b_
.
CreateAllocaBPF
();
AllocaInst
*
key
;
if
(
map
.
vargs
)
{
key
=
b_
.
CreateAllocaBPF
(
map
.
vargs
->
size
());
int
i
=
0
;
for
(
Expression
*
expr
:
*
map
.
vargs
)
{
expr
->
accept
(
*
this
);
Value
*
offset
=
b_
.
CreateGEP
(
key
,
b_
.
getInt64
(
i
++
));
b_
.
CreateStore
(
expr_
,
offset
);
}
}
else
{
key
=
b_
.
CreateAllocaBPF
();
b_
.
CreateStore
(
b_
.
getInt64
(
0
),
key
);
}
AllocaInst
*
val
=
b_
.
CreateAllocaBPF
();
assignment
.
expr
->
accept
(
*
this
);
b_
.
CreateStore
(
expr_
,
val
);
AllocaInst
*
key
=
getMapKey
(
map
);
b_
.
CreateMapUpdateElem
(
map
,
key
,
val
);
}
...
...
@@ -156,8 +128,7 @@ void CodegenLLVM::visit(AssignMapCallStatement &assignment)
if
(
call
.
func
==
"count"
)
{
AllocaInst
*
key
=
b_
.
CreateAllocaBPF
();
b_
.
CreateStore
(
b_
.
getInt64
(
0
),
key
);
// TODO variable key
AllocaInst
*
key
=
getMapKey
(
map
);
Value
*
oldval
=
b_
.
CreateMapLookupElem
(
map
,
key
);
AllocaInst
*
newval
=
b_
.
CreateAllocaBPF
();
b_
.
CreateStore
(
b_
.
CreateAdd
(
oldval
,
b_
.
getInt64
(
1
)),
newval
);
...
...
@@ -220,6 +191,26 @@ void CodegenLLVM::visit(Program &program)
}
}
AllocaInst
*
CodegenLLVM
::
getMapKey
(
Map
&
map
)
{
AllocaInst
*
key
;
if
(
map
.
vargs
)
{
key
=
b_
.
CreateAllocaBPF
(
map
.
vargs
->
size
());
int
i
=
0
;
for
(
Expression
*
expr
:
*
map
.
vargs
)
{
expr
->
accept
(
*
this
);
Value
*
offset
=
b_
.
CreateGEP
(
key
,
b_
.
getInt64
(
i
++
));
b_
.
CreateStore
(
expr_
,
offset
);
}
}
else
{
key
=
b_
.
CreateAllocaBPF
();
b_
.
CreateStore
(
b_
.
getInt64
(
0
),
key
);
}
return
key
;
}
class
BPFtraceMemoryManager
:
public
SectionMemoryManager
{
public:
...
...
src/codegen_llvm.h
View file @
4a2d0f83
...
...
@@ -36,9 +36,9 @@ public:
void
visit
(
Predicate
&
pred
)
override
;
void
visit
(
Probe
&
probe
)
override
;
void
visit
(
Program
&
program
)
override
;
AllocaInst
*
getMapKey
(
Map
&
map
);
int
compile
(
bool
debug
=
false
);
AllocaInst
*
createAllocaBPF
(
llvm
::
Type
*
ty
,
const
std
::
string
&
name
=
""
)
const
;
private:
Node
*
root_
;
...
...
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