Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bcc
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
bcc
Commits
97997afd
Commit
97997afd
authored
Apr 27, 2017
by
4ast
Committed by
GitHub
Apr 27, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1140 from iovisor/llvm_alloca_irbuilder_fix
frontend/b: fixes for LLVM 4.0 API change
parents
eced7b69
c089423a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
7 deletions
+35
-7
src/cc/frontends/b/codegen_llvm.cc
src/cc/frontends/b/codegen_llvm.cc
+28
-7
src/cc/frontends/b/codegen_llvm.h
src/cc/frontends/b/codegen_llvm.h
+7
-0
No files found.
src/cc/frontends/b/codegen_llvm.cc
View file @
97997afd
...
...
@@ -422,7 +422,8 @@ StatusTuple CodegenLLVM::visit_string_expr_node(StringExprNode *n) {
if
(
n
->
is_lhs
())
return
mkstatus_
(
n
,
"cannot assign to a string"
);
Value
*
global
=
B
.
CreateGlobalString
(
n
->
val_
);
Value
*
ptr
=
new
AllocaInst
(
B
.
getInt8Ty
(),
B
.
getInt64
(
n
->
val_
.
size
()
+
1
),
""
,
resolve_entry_stack
());
Value
*
ptr
=
make_alloca
(
resolve_entry_stack
(),
B
.
getInt8Ty
(),
""
,
B
.
getInt64
(
n
->
val_
.
size
()
+
1
));
B
.
CreateMemCpy
(
ptr
,
global
,
n
->
val_
.
size
()
+
1
,
1
);
expr_
=
ptr
;
...
...
@@ -813,7 +814,8 @@ StatusTuple CodegenLLVM::visit_table_index_expr_node(TableIndexExprNode *n) {
B
.
SetInsertPoint
(
label_then
);
// var Leaf leaf {0}
Value
*
leaf_ptr
=
B
.
CreateBitCast
(
new
AllocaInst
(
leaf_type
,
""
,
resolve_entry_stack
()),
B
.
getInt8PtrTy
());
Value
*
leaf_ptr
=
B
.
CreateBitCast
(
make_alloca
(
resolve_entry_stack
(),
leaf_type
),
B
.
getInt8PtrTy
());
B
.
CreateMemSet
(
leaf_ptr
,
B
.
getInt8
(
0
),
B
.
getInt64
(
n
->
table_
->
leaf_id
()
->
bit_width_
>>
3
),
1
);
// update(key, leaf)
B
.
CreateCall
(
update_fn
,
vector
<
Value
*>
({
pseudo_map_fd
,
key_ptr
,
leaf_ptr
,
B
.
getInt64
(
BPF_NOEXIST
)}));
...
...
@@ -957,7 +959,7 @@ StatusTuple CodegenLLVM::visit_struct_variable_decl_stmt_node(StructVariableDecl
TRY2
(
lookup_struct_type
(
n
,
&
stype
,
&
decl
));
Type
*
ptr_stype
=
n
->
is_pointer
()
?
PointerType
::
getUnqual
(
stype
)
:
(
PointerType
*
)
stype
;
AllocaInst
*
ptr_a
=
new
AllocaInst
(
ptr_stype
,
""
,
resolve_entry_stack
()
);
AllocaInst
*
ptr_a
=
make_alloca
(
resolve_entry_stack
(),
ptr_stype
);
vars_
[
n
]
=
ptr_a
;
if
(
n
->
struct_id_
->
scope_name_
==
"proto"
)
{
...
...
@@ -1011,7 +1013,8 @@ StatusTuple CodegenLLVM::visit_integer_variable_decl_stmt_node(IntegerVariableDe
return
StatusTuple
(
0
);
// uintX var = init
AllocaInst
*
ptr_a
=
new
AllocaInst
(
B
.
getIntNTy
(
n
->
bit_width_
),
n
->
id_
->
name_
,
resolve_entry_stack
());
AllocaInst
*
ptr_a
=
make_alloca
(
resolve_entry_stack
(),
B
.
getIntNTy
(
n
->
bit_width_
),
n
->
id_
->
name_
);
vars_
[
n
]
=
ptr_a
;
// todo
...
...
@@ -1172,9 +1175,9 @@ StatusTuple CodegenLLVM::visit_func_decl_stmt_node(FuncDeclStmtNode *n) {
string
scoped_entry_label
=
to_string
((
uintptr_t
)
fn
)
+
"::entry"
;
labels_
[
scoped_entry_label
]
=
label_entry
;
BasicBlock
*
label_return
=
resolve_label
(
"DONE"
);
retval_
=
new
AllocaInst
(
fn
->
getReturnType
(),
"ret"
,
label_entry
);
retval_
=
make_alloca
(
label_entry
,
fn
->
getReturnType
(),
"ret"
);
B
.
CreateStore
(
B
.
getInt32
(
0
),
retval_
);
errval_
=
new
AllocaInst
(
B
.
getInt64Ty
(),
"err"
,
label_entry
);
errval_
=
make_alloca
(
label_entry
,
B
.
getInt64Ty
(),
"err"
);
B
.
CreateStore
(
B
.
getInt64
(
0
),
errval_
);
auto
formal
=
n
->
formals_
.
begin
();
...
...
@@ -1194,7 +1197,7 @@ StatusTuple CodegenLLVM::visit_func_decl_stmt_node(FuncDeclStmtNode *n) {
// }
// arg->setName((*formal)->id_->name_);
// AllocaInst *ptr =
new AllocaInst(ptype, nullptr, (*formal)->id_->name_, label_entry
);
// AllocaInst *ptr =
make_alloca(label_entry, ptype, (*formal)->id_->name_
);
// B.CreateStore(arg, ptr);
// vars_[formal->get()] = ptr;
}
...
...
@@ -1318,5 +1321,23 @@ Instruction * CodegenLLVM::resolve_entry_stack() {
return
&
label_entry
->
back
();
}
AllocaInst
*
CodegenLLVM
::
make_alloca
(
Instruction
*
Inst
,
Type
*
Ty
,
const
string
&
name
,
Value
*
ArraySize
)
{
IRBuilderBase
::
InsertPoint
ip
=
B
.
saveIP
();
B
.
SetInsertPoint
(
Inst
);
AllocaInst
*
a
=
B
.
CreateAlloca
(
Ty
,
ArraySize
,
name
);
B
.
restoreIP
(
ip
);
return
a
;
}
AllocaInst
*
CodegenLLVM
::
make_alloca
(
BasicBlock
*
BB
,
Type
*
Ty
,
const
string
&
name
,
Value
*
ArraySize
)
{
IRBuilderBase
::
InsertPoint
ip
=
B
.
saveIP
();
B
.
SetInsertPoint
(
BB
);
AllocaInst
*
a
=
B
.
CreateAlloca
(
Ty
,
ArraySize
,
name
);
B
.
restoreIP
(
ip
);
return
a
;
}
}
// namespace cc
}
// namespace ebpf
src/cc/frontends/b/codegen_llvm.h
View file @
97997afd
...
...
@@ -36,6 +36,7 @@ class LLVMContext;
class
Module
;
class
StructType
;
class
SwitchInst
;
class
Type
;
class
Value
;
class
GlobalVariable
;
}
...
...
@@ -91,6 +92,12 @@ class CodegenLLVM : public Visitor {
llvm
::
Value
*
pop_expr
();
llvm
::
BasicBlock
*
resolve_label
(
const
string
&
label
);
llvm
::
Instruction
*
resolve_entry_stack
();
llvm
::
AllocaInst
*
make_alloca
(
llvm
::
Instruction
*
Inst
,
llvm
::
Type
*
Ty
,
const
std
::
string
&
name
=
""
,
llvm
::
Value
*
ArraySize
=
nullptr
);
llvm
::
AllocaInst
*
make_alloca
(
llvm
::
BasicBlock
*
BB
,
llvm
::
Type
*
Ty
,
const
std
::
string
&
name
=
""
,
llvm
::
Value
*
ArraySize
=
nullptr
);
StatusTuple
lookup_var
(
Node
*
n
,
const
std
::
string
&
name
,
Scopes
::
VarScope
*
scope
,
VariableDeclStmtNode
**
decl
,
llvm
::
Value
**
mem
)
const
;
StatusTuple
lookup_struct_type
(
StructDeclStmtNode
*
decl
,
llvm
::
StructType
**
stype
)
const
;
...
...
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