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
5d00cea5
Commit
5d00cea5
authored
Feb 25, 2018
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use base IRBuilder's CreateMemCpy and CreateMemSet functions
parent
d1fbcb11
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
23 deletions
+9
-23
src/ast/codegen_llvm.cpp
src/ast/codegen_llvm.cpp
+4
-4
src/ast/irbuilderbpf.cpp
src/ast/irbuilderbpf.cpp
+2
-14
src/ast/irbuilderbpf.h
src/ast/irbuilderbpf.h
+0
-2
tests/codegen.cpp
tests/codegen.cpp
+3
-3
No files found.
src/ast/codegen_llvm.cpp
View file @
5d00cea5
...
...
@@ -153,7 +153,7 @@ void CodegenLLVM::visit(Call &call)
else
if
(
call
.
func
==
"str"
)
{
AllocaInst
*
buf
=
b_
.
CreateAllocaBPF
(
call
.
type
,
"str"
);
b_
.
CreateMem
set
(
buf
,
b_
.
getInt8
(
0
),
call
.
type
.
size
);
b_
.
CreateMem
Set
(
buf
,
b_
.
getInt8
(
0
),
call
.
type
.
size
,
1
);
call
.
vargs
->
front
()
->
accept
(
*
this
);
b_
.
CreateProbeReadStr
(
buf
,
call
.
type
.
size
,
expr_
);
expr_
=
buf
;
...
...
@@ -195,7 +195,7 @@ void CodegenLLVM::visit(Call &call)
arg
.
accept
(
*
this
);
Value
*
offset
=
b_
.
CreateGEP
(
printf_args
,
{
b_
.
getInt32
(
0
),
b_
.
getInt32
(
i
)});
if
(
arg
.
type
.
type
==
Type
::
string
)
b_
.
CreateMem
cpy
(
offset
,
expr_
,
arg
.
type
.
size
);
b_
.
CreateMem
Cpy
(
offset
,
expr_
,
arg
.
type
.
size
,
1
);
else
b_
.
CreateStore
(
expr_
,
offset
);
}
...
...
@@ -421,7 +421,7 @@ AllocaInst *CodegenLLVM::getMapKey(Map &map)
expr
->
accept
(
*
this
);
Value
*
offset_val
=
b_
.
CreateGEP
(
key
,
{
b_
.
getInt64
(
0
),
b_
.
getInt64
(
offset
)});
if
(
expr
->
type
.
type
==
Type
::
string
)
b_
.
CreateMem
cpy
(
offset_val
,
expr_
,
expr
->
type
.
size
);
b_
.
CreateMem
Cpy
(
offset_val
,
expr_
,
expr
->
type
.
size
,
1
);
else
b_
.
CreateStore
(
expr_
,
offset_val
);
offset
+=
expr
->
type
.
size
;
...
...
@@ -451,7 +451,7 @@ AllocaInst *CodegenLLVM::getQuantizeMapKey(Map &map, Value *log2)
expr
->
accept
(
*
this
);
Value
*
offset_val
=
b_
.
CreateGEP
(
key
,
{
b_
.
getInt64
(
0
),
b_
.
getInt64
(
offset
)});
if
(
expr
->
type
.
type
==
Type
::
string
)
b_
.
CreateMem
cpy
(
offset_val
,
expr_
,
expr
->
type
.
size
);
b_
.
CreateMem
Cpy
(
offset_val
,
expr_
,
expr
->
type
.
size
,
1
);
else
b_
.
CreateStore
(
expr_
,
offset_val
);
offset
+=
expr
->
type
.
size
;
...
...
src/ast/irbuilderbpf.cpp
View file @
5d00cea5
...
...
@@ -92,18 +92,6 @@ AllocaInst *IRBuilderBPF::CreateAllocaMapKey(int bytes, const std::string &name)
return
CreateAllocaBPF
(
ty
,
name
);
}
void
IRBuilderBPF
::
CreateMemcpy
(
Value
*
dst
,
Value
*
src
,
size_t
len
)
{
Function
*
memcpy_func
=
module_
.
getFunction
(
"llvm.memcpy.p0i8.p0i8.i64"
);
CreateCall
(
memcpy_func
,
{
dst
,
src
,
getInt64
(
len
),
getInt32
(
1
),
getInt1
(
0
)},
"memcpy"
);
}
void
IRBuilderBPF
::
CreateMemset
(
Value
*
dst
,
Value
*
val
,
size_t
len
)
{
Function
*
memset_func
=
module_
.
getFunction
(
"llvm.memset.p0i8.i64"
);
CreateCall
(
memset_func
,
{
dst
,
val
,
getInt64
(
len
),
getInt32
(
1
),
getInt1
(
0
)},
"memset"
);
}
CallInst
*
IRBuilderBPF
::
CreateBpfPseudoCall
(
int
mapfd
)
{
Function
*
pseudo_func
=
module_
.
getFunction
(
"llvm.bpf.pseudo"
);
...
...
@@ -148,14 +136,14 @@ Value *IRBuilderBPF::CreateMapLookupElem(Map &map, AllocaInst *key)
SetInsertPoint
(
lookup_success_block
);
if
(
map
.
type
.
type
==
Type
::
string
)
CreateMem
cpy
(
value
,
call
,
map
.
type
.
size
);
CreateMem
Cpy
(
value
,
call
,
map
.
type
.
size
,
1
);
else
CreateStore
(
CreateLoad
(
getInt64Ty
(),
call
),
value
);
CreateBr
(
lookup_merge_block
);
SetInsertPoint
(
lookup_failure_block
);
if
(
map
.
type
.
type
==
Type
::
string
)
CreateMem
set
(
value
,
getInt8
(
0
),
map
.
type
.
size
);
CreateMem
Set
(
value
,
getInt8
(
0
),
map
.
type
.
size
,
1
);
else
CreateStore
(
getInt64
(
0
),
value
);
CreateBr
(
lookup_merge_block
);
...
...
src/ast/irbuilderbpf.h
View file @
5d00cea5
...
...
@@ -21,8 +21,6 @@ public:
AllocaInst
*
CreateAllocaBPF
(
llvm
::
Type
*
ty
,
const
std
::
string
&
name
=
""
);
AllocaInst
*
CreateAllocaBPF
(
const
SizedType
&
stype
,
const
std
::
string
&
name
=
""
);
AllocaInst
*
CreateAllocaMapKey
(
int
bytes
,
const
std
::
string
&
name
=
""
);
void
CreateMemcpy
(
Value
*
dst
,
Value
*
src
,
size_t
len
);
void
CreateMemset
(
Value
*
dst
,
Value
*
val
,
size_t
len
);
CallInst
*
CreateBpfPseudoCall
(
int
mapfd
);
CallInst
*
CreateBpfPseudoCall
(
Map
&
map
);
Value
*
CreateMapLookupElem
(
Map
&
map
,
AllocaInst
*
key
);
...
...
tests/codegen.cpp
View file @
5d00cea5
...
...
@@ -782,7 +782,7 @@ entry:
%str = alloca [64 x i8], align 1
%1 = getelementptr inbounds [64 x i8], [64 x i8]* %str, i64 0, i64 0
call void @llvm.lifetime.start.p0i8(i64 -1, i8* nonnull %1)
%memset = call void @llvm.memset.p0i8.i64([64 x i8]* nonnull %str
, i8 0, i64 64, i32 1, i1 false)
call void @llvm.memset.p0i8.i64(i8* nonnull %1
, i8 0, i64 64, i32 1, i1 false)
%2 = bitcast i64* %arg0 to i8*
call void @llvm.lifetime.start.p0i8(i64 -1, i8* nonnull %2)
%3 = getelementptr i8, i8* %0, i64 112
...
...
@@ -986,11 +986,11 @@ entry:
br i1 %map_lookup_cond, label %lookup_failure, label %lookup_success
lookup_success: ; preds = %entry
%memcpy = call void @llvm.memcpy.p0i8.p0i8.i64([64 x i8]* nonnull %lookup_elem_val
, i8* nonnull %lookup_elem, i64 64, i32 1, i1 false)
call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull %4
, i8* nonnull %lookup_elem, i64 64, i32 1, i1 false)
br label %lookup_merge
lookup_failure: ; preds = %entry
%memset = call void @llvm.memset.p0i8.i64([64 x i8]* nonnull %lookup_elem_val
, i8 0, i64 64, i32 1, i1 false)
call void @llvm.memset.p0i8.i64(i8* nonnull %4
, i8 0, i64 64, i32 1, i1 false)
br label %lookup_merge
lookup_merge: ; preds = %lookup_failure, %lookup_success
...
...
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