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
719c34ea
Commit
719c34ea
authored
Oct 09, 2018
by
Mateusz Lenik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial LLVM 7 support
parent
4c606137
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
24 deletions
+23
-24
src/ast/codegen_llvm.cpp
src/ast/codegen_llvm.cpp
+10
-10
src/ast/irbuilderbpf.cpp
src/ast/irbuilderbpf.cpp
+1
-1
src/bpforc.h
src/bpforc.h
+12
-13
No files found.
src/ast/codegen_llvm.cpp
View file @
719c34ea
...
@@ -429,7 +429,7 @@ void CodegenLLVM::visit(Call &call)
...
@@ -429,7 +429,7 @@ void CodegenLLVM::visit(Call &call)
arg
.
accept
(
*
this
);
arg
.
accept
(
*
this
);
Value
*
offset
=
b_
.
CreateGEP
(
printf_args
,
{
b_
.
getInt32
(
0
),
b_
.
getInt32
(
i
)});
Value
*
offset
=
b_
.
CreateGEP
(
printf_args
,
{
b_
.
getInt32
(
0
),
b_
.
getInt32
(
i
)});
if
(
arg
.
type
.
IsArray
())
if
(
arg
.
type
.
IsArray
())
b_
.
CreateMemCpy
(
offset
,
expr_
,
arg
.
type
.
size
,
1
);
b_
.
CreateMemCpy
(
offset
,
0
,
expr_
,
0
,
arg
.
type
.
size
);
else
else
b_
.
CreateStore
(
expr_
,
offset
);
b_
.
CreateStore
(
expr_
,
offset
);
}
}
...
@@ -478,7 +478,7 @@ void CodegenLLVM::visit(Call &call)
...
@@ -478,7 +478,7 @@ void CodegenLLVM::visit(Call &call)
arg
.
accept
(
*
this
);
arg
.
accept
(
*
this
);
Value
*
offset
=
b_
.
CreateGEP
(
system_args
,
{
b_
.
getInt32
(
0
),
b_
.
getInt32
(
i
)});
Value
*
offset
=
b_
.
CreateGEP
(
system_args
,
{
b_
.
getInt32
(
0
),
b_
.
getInt32
(
i
)});
if
(
arg
.
type
.
IsArray
())
if
(
arg
.
type
.
IsArray
())
b_
.
CreateMemCpy
(
offset
,
expr_
,
arg
.
type
.
size
,
1
);
b_
.
CreateMemCpy
(
offset
,
0
,
expr_
,
0
,
arg
.
type
.
size
);
else
else
b_
.
CreateStore
(
expr_
,
offset
);
b_
.
CreateStore
(
expr_
,
offset
);
}
}
...
@@ -551,7 +551,7 @@ void CodegenLLVM::visit(Call &call)
...
@@ -551,7 +551,7 @@ void CodegenLLVM::visit(Call &call)
b_
.
CreateStore
(
b_
.
getInt64
(
0
),
b_
.
CreateGEP
(
perfdata
,
{
b_
.
getInt64
(
0
),
b_
.
getInt64
(
sizeof
(
uint64_t
)
+
sizeof
(
uint64_t
))}));
b_
.
CreateStore
(
b_
.
getInt64
(
0
),
b_
.
CreateGEP
(
perfdata
,
{
b_
.
getInt64
(
0
),
b_
.
getInt64
(
sizeof
(
uint64_t
)
+
sizeof
(
uint64_t
))}));
// store map ident:
// store map ident:
b_
.
CreateMemCpy
(
b_
.
CreateGEP
(
perfdata
,
{
b_
.
getInt64
(
0
),
b_
.
getInt64
(
sizeof
(
uint64_t
)
+
2
*
sizeof
(
uint64_t
))}),
str_buf
,
map
.
ident
.
length
()
+
1
,
1
);
b_
.
CreateMemCpy
(
b_
.
CreateGEP
(
perfdata
,
{
b_
.
getInt64
(
0
),
b_
.
getInt64
(
sizeof
(
uint64_t
)
+
2
*
sizeof
(
uint64_t
))}),
0
,
str_buf
,
0
,
map
.
ident
.
length
()
+
1
);
b_
.
CreatePerfEventOutput
(
ctx_
,
perfdata
,
sizeof
(
uint64_t
)
+
2
*
sizeof
(
uint64_t
)
+
map
.
ident
.
length
()
+
1
);
b_
.
CreatePerfEventOutput
(
ctx_
,
perfdata
,
sizeof
(
uint64_t
)
+
2
*
sizeof
(
uint64_t
)
+
map
.
ident
.
length
()
+
1
);
b_
.
CreateLifetimeEnd
(
perfdata
);
b_
.
CreateLifetimeEnd
(
perfdata
);
expr_
=
nullptr
;
expr_
=
nullptr
;
...
@@ -570,7 +570,7 @@ void CodegenLLVM::visit(Call &call)
...
@@ -570,7 +570,7 @@ void CodegenLLVM::visit(Call &call)
b_
.
CreateStore
(
b_
.
getInt64
(
asyncactionint
(
AsyncAction
::
clear
)),
perfdata
);
b_
.
CreateStore
(
b_
.
getInt64
(
asyncactionint
(
AsyncAction
::
clear
)),
perfdata
);
else
else
b_
.
CreateStore
(
b_
.
getInt64
(
asyncactionint
(
AsyncAction
::
zero
)),
perfdata
);
b_
.
CreateStore
(
b_
.
getInt64
(
asyncactionint
(
AsyncAction
::
zero
)),
perfdata
);
b_
.
CreateMemCpy
(
b_
.
CreateGEP
(
perfdata
,
{
b_
.
getInt64
(
0
),
b_
.
getInt64
(
sizeof
(
uint64_t
))}),
str_buf
,
map
.
ident
.
length
()
+
1
,
1
);
b_
.
CreateMemCpy
(
b_
.
CreateGEP
(
perfdata
,
{
b_
.
getInt64
(
0
),
b_
.
getInt64
(
sizeof
(
uint64_t
))}),
0
,
str_buf
,
0
,
map
.
ident
.
length
()
+
1
);
b_
.
CreatePerfEventOutput
(
ctx_
,
perfdata
,
sizeof
(
uint64_t
)
+
map
.
ident
.
length
()
+
1
);
b_
.
CreatePerfEventOutput
(
ctx_
,
perfdata
,
sizeof
(
uint64_t
)
+
map
.
ident
.
length
()
+
1
);
b_
.
CreateLifetimeEnd
(
perfdata
);
b_
.
CreateLifetimeEnd
(
perfdata
);
expr_
=
nullptr
;
expr_
=
nullptr
;
...
@@ -764,12 +764,12 @@ void CodegenLLVM::visit(Ternary &ternary)
...
@@ -764,12 +764,12 @@ void CodegenLLVM::visit(Ternary &ternary)
// copy selected string via CreateMemCpy
// copy selected string via CreateMemCpy
b_
.
SetInsertPoint
(
left_block
);
b_
.
SetInsertPoint
(
left_block
);
ternary
.
left
->
accept
(
*
this
);
ternary
.
left
->
accept
(
*
this
);
b_
.
CreateMemCpy
(
buf
,
expr_
,
ternary
.
type
.
size
,
1
);
b_
.
CreateMemCpy
(
buf
,
0
,
expr_
,
0
,
ternary
.
type
.
size
);
b_
.
CreateBr
(
done
);
b_
.
CreateBr
(
done
);
b_
.
SetInsertPoint
(
right_block
);
b_
.
SetInsertPoint
(
right_block
);
ternary
.
right
->
accept
(
*
this
);
ternary
.
right
->
accept
(
*
this
);
b_
.
CreateMemCpy
(
buf
,
expr_
,
ternary
.
type
.
size
,
1
);
b_
.
CreateMemCpy
(
buf
,
0
,
expr_
,
0
,
ternary
.
type
.
size
);
b_
.
CreateBr
(
done
);
b_
.
CreateBr
(
done
);
b_
.
SetInsertPoint
(
done
);
b_
.
SetInsertPoint
(
done
);
...
@@ -796,7 +796,7 @@ void CodegenLLVM::visit(FieldAccess &acc)
...
@@ -796,7 +796,7 @@ void CodegenLLVM::visit(FieldAccess &acc)
{
{
// TODO This should be do-able without allocating more memory here
// TODO This should be do-able without allocating more memory here
AllocaInst
*
dst
=
b_
.
CreateAllocaBPF
(
field
.
type
,
"internal_"
+
type
.
cast_type
+
"."
+
acc
.
field
);
AllocaInst
*
dst
=
b_
.
CreateAllocaBPF
(
field
.
type
,
"internal_"
+
type
.
cast_type
+
"."
+
acc
.
field
);
b_
.
CreateMemCpy
(
dst
,
src
,
field
.
type
.
size
,
1
);
b_
.
CreateMemCpy
(
dst
,
0
,
src
,
0
,
field
.
type
.
size
);
expr_
=
dst
;
expr_
=
dst
;
// TODO clean up dst memory?
// TODO clean up dst memory?
}
}
...
@@ -920,7 +920,7 @@ void CodegenLLVM::visit(AssignVarStatement &assignment)
...
@@ -920,7 +920,7 @@ void CodegenLLVM::visit(AssignVarStatement &assignment)
}
}
else
else
{
{
b_
.
CreateMemCpy
(
variables_
[
var
.
ident
],
expr_
,
var
.
type
.
size
,
1
);
b_
.
CreateMemCpy
(
variables_
[
var
.
ident
],
0
,
expr_
,
0
,
var
.
type
.
size
);
}
}
}
}
...
@@ -1119,7 +1119,7 @@ AllocaInst *CodegenLLVM::getMapKey(Map &map)
...
@@ -1119,7 +1119,7 @@ AllocaInst *CodegenLLVM::getMapKey(Map &map)
expr
->
accept
(
*
this
);
expr
->
accept
(
*
this
);
Value
*
offset_val
=
b_
.
CreateGEP
(
key
,
{
b_
.
getInt64
(
0
),
b_
.
getInt64
(
offset
)});
Value
*
offset_val
=
b_
.
CreateGEP
(
key
,
{
b_
.
getInt64
(
0
),
b_
.
getInt64
(
offset
)});
if
(
expr
->
type
.
type
==
Type
::
string
||
expr
->
type
.
type
==
Type
::
usym
)
if
(
expr
->
type
.
type
==
Type
::
string
||
expr
->
type
.
type
==
Type
::
usym
)
b_
.
CreateMemCpy
(
offset_val
,
expr_
,
expr
->
type
.
size
,
1
);
b_
.
CreateMemCpy
(
offset_val
,
0
,
expr_
,
0
,
expr
->
type
.
size
);
else
else
b_
.
CreateStore
(
expr_
,
offset_val
);
b_
.
CreateStore
(
expr_
,
offset_val
);
offset
+=
expr
->
type
.
size
;
offset
+=
expr
->
type
.
size
;
...
@@ -1149,7 +1149,7 @@ AllocaInst *CodegenLLVM::getHistMapKey(Map &map, Value *log2)
...
@@ -1149,7 +1149,7 @@ AllocaInst *CodegenLLVM::getHistMapKey(Map &map, Value *log2)
expr
->
accept
(
*
this
);
expr
->
accept
(
*
this
);
Value
*
offset_val
=
b_
.
CreateGEP
(
key
,
{
b_
.
getInt64
(
0
),
b_
.
getInt64
(
offset
)});
Value
*
offset_val
=
b_
.
CreateGEP
(
key
,
{
b_
.
getInt64
(
0
),
b_
.
getInt64
(
offset
)});
if
(
expr
->
type
.
type
==
Type
::
string
||
expr
->
type
.
type
==
Type
::
usym
)
if
(
expr
->
type
.
type
==
Type
::
string
||
expr
->
type
.
type
==
Type
::
usym
)
b_
.
CreateMemCpy
(
offset_val
,
expr_
,
expr
->
type
.
size
,
1
);
b_
.
CreateMemCpy
(
offset_val
,
0
,
expr_
,
0
,
expr
->
type
.
size
);
else
else
b_
.
CreateStore
(
expr_
,
offset_val
);
b_
.
CreateStore
(
expr_
,
offset_val
);
offset
+=
expr
->
type
.
size
;
offset
+=
expr
->
type
.
size
;
...
...
src/ast/irbuilderbpf.cpp
View file @
719c34ea
...
@@ -193,7 +193,7 @@ Value *IRBuilderBPF::CreateMapLookupElem(Map &map, AllocaInst *key)
...
@@ -193,7 +193,7 @@ Value *IRBuilderBPF::CreateMapLookupElem(Map &map, AllocaInst *key)
SetInsertPoint
(
lookup_success_block
);
SetInsertPoint
(
lookup_success_block
);
if
(
map
.
type
.
type
==
Type
::
string
||
map
.
type
.
type
==
Type
::
cast
)
if
(
map
.
type
.
type
==
Type
::
string
||
map
.
type
.
type
==
Type
::
cast
)
CreateMemCpy
(
value
,
call
,
map
.
type
.
size
,
1
);
CreateMemCpy
(
value
,
0
,
call
,
0
,
map
.
type
.
size
,
1
);
else
else
CreateStore
(
CreateLoad
(
getInt64Ty
(),
call
),
value
);
CreateStore
(
CreateLoad
(
getInt64Ty
(),
call
),
value
);
CreateBr
(
lookup_merge_block
);
CreateBr
(
lookup_merge_block
);
...
...
src/bpforc.h
View file @
719c34ea
...
@@ -5,7 +5,6 @@
...
@@ -5,7 +5,6 @@
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetMachine.h"
...
@@ -40,35 +39,35 @@ private:
...
@@ -40,35 +39,35 @@ private:
class
BpfOrc
class
BpfOrc
{
{
private:
private:
ExecutionSession
ES
;
std
::
unique_ptr
<
TargetMachine
>
TM
;
std
::
unique_ptr
<
TargetMachine
>
TM
;
std
::
shared_ptr
<
SymbolResolver
>
Resolver
;
RTDyldObjectLinkingLayer
ObjectLayer
;
RTDyldObjectLinkingLayer
ObjectLayer
;
IRCompileLayer
<
decltype
(
ObjectLayer
),
SimpleCompiler
>
CompileLayer
;
IRCompileLayer
<
decltype
(
ObjectLayer
),
SimpleCompiler
>
CompileLayer
;
public:
public:
std
::
map
<
std
::
string
,
std
::
tuple
<
uint8_t
*
,
uintptr_t
>>
sections_
;
std
::
map
<
std
::
string
,
std
::
tuple
<
uint8_t
*
,
uintptr_t
>>
sections_
;
using
ModuleHandle
=
decltype
(
CompileLayer
)
::
ModuleHandleT
;
BpfOrc
(
TargetMachine
*
TM_
)
BpfOrc
(
TargetMachine
*
TM_
)
:
TM
(
TM_
),
:
TM
(
TM_
),
ObjectLayer
([
this
]()
{
return
std
::
make_shared
<
MemoryManager
>
(
sections_
);
}),
Resolver
(
createLegacyLookupResolver
(
ES
,
[](
const
std
::
string
&
Name
)
->
JITSymbol
{
return
nullptr
;
},
[](
Error
Err
)
{
cantFail
(
std
::
move
(
Err
),
"lookup failed"
);
})),
ObjectLayer
(
ES
,
[
this
](
VModuleKey
)
{
return
RTDyldObjectLinkingLayer
::
Resources
{
std
::
make_shared
<
MemoryManager
>
(
sections_
),
Resolver
};
}),
CompileLayer
(
ObjectLayer
,
SimpleCompiler
(
*
TM
))
CompileLayer
(
ObjectLayer
,
SimpleCompiler
(
*
TM
))
{
{
}
}
void
compileModule
(
std
::
unique_ptr
<
Module
>
M
)
void
compileModule
(
std
::
unique_ptr
<
Module
>
M
)
{
{
auto
mod
=
addModule
(
move
(
M
));
auto
K
=
addModule
(
move
(
M
));
CompileLayer
.
emitAndFinalize
(
mod
);
CompileLayer
.
emitAndFinalize
(
K
);
}
}
ModuleHandle
addModule
(
std
::
unique_ptr
<
Module
>
M
)
{
VModuleKey
addModule
(
std
::
unique_ptr
<
Module
>
M
)
{
// We don't actually care about resolving symbols from other modules
auto
K
=
ES
.
allocateVModule
();
auto
Resolver
=
createLambdaResolver
(
cantFail
(
CompileLayer
.
addModule
(
K
,
std
::
move
(
M
)));
[](
const
std
::
string
&
Name
)
{
return
JITSymbol
(
nullptr
);
},
return
K
;
[](
const
std
::
string
&
Name
)
{
return
JITSymbol
(
nullptr
);
});
return
cantFail
(
CompileLayer
.
addModule
(
std
::
move
(
M
),
std
::
move
(
Resolver
)));
}
}
};
};
...
...
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