Skip to content

Commit

Permalink
fix a compilation error with latest llvm 10
Browse files Browse the repository at this point in the history
Two issues:
First, the recent llvm commit "[Alignment][NFC] CreateMemSet use MaybeAlign"
(https://reviews.llvm.org/D71213) changed IR/IRBuilder.h
CreateMemSet() signature which caused the following compilation error:
  [ 16%] Building CXX object src/cc/frontends/b/CMakeFiles/b_frontend.dir/codegen_llvm.cc.o
  /home/yhs/work/bcc/src/cc/frontends/b/codegen_llvm.cc: In member function
  ‘virtual ebpf::StatusTuple ebpf::cc::CodegenLLVM::visit_table_index_expr_node(ebpf::cc::TableIndexExprNode*)’:
  /home/yhs/work/bcc/src/cc/frontends/b/codegen_llvm.cc:824:96: error: no matching function for call to
  ‘llvm::IRBuilder<>::CreateMemSet(llvm::Value*&, llvm::ConstantInt*, llvm::ConstantInt*, int)’
       B.CreateMemSet(leaf_ptr, B.getInt8(0), B.getInt64(n->table_->leaf_id()->bit_width_ >> 3), 1);
                                                                                                ^
  ....
  /home/yhs/work/llvm-project/llvm/build/install/include/llvm/IR/IRBuilder.h:460:13: note: candidate:
  llvm::CallInst* llvm::IRBuilderBase::CreateMemSet(llvm::Value*, llvm::Value*, llvm::Value*,
  llvm::MaybeAlign, bool, llvm::MDNode*, llvm::MDNode*, llvm::MDNode*)
     CallInst *CreateMemSet(Value *Ptr, Value *Val, Value *Size, MaybeAlign Align,
               ^~~~~~~~~~~~
  /home/yhs/work/llvm-project/llvm/build/install/include/llvm/IR/IRBuilder.h:460:13: note:
  no known conversion for argument 4 from ‘int’ to ‘llvm::MaybeAlign’

Second, the commit "[OpenMP][NFCI] Introduce llvm/IR/OpenMPConstants.h"
(https://reviews.llvm.org/D69853) introduced a new library "FrontendOpenMP"
which is used by clang Parser, and caused the following errors:
  [ 99%] Building CXX object tests/cc/CMakeFiles/test_libbcc.dir/test_hash_table.cc.o
  /home/yhs/work/llvm-project/llvm/build/install/lib/libclangParse.a(ParseOpenMP.cpp.o): In function
  `clang::Parser::ParseOpenMPDeclareReductionDirective(clang::AccessSpecifier)':
  ParseOpenMP.cpp:(.text._ZN5clang6Parser36ParseOpenMPDeclareReductionDirectiveENS_15AccessSpecifierE+0x86):
  undefined reference to `llvm::omp::getOpenMPDirectiveName(llvm::omp::Directive)'

This patch fixed both issues and bcc can compile with latest llvm 10.
  • Loading branch information
yonghong-song committed Dec 10, 2019
1 parent 5cf529e commit f9f1050
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmake/clang_libs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ list(FIND LLVM_AVAILABLE_LIBS "LLVMCoroutines" _llvm_coroutines)
if (${_llvm_coroutines} GREATER -1)
list(APPEND llvm_raw_libs coroutines)
endif()
list(FIND LLVM_AVAILABLE_LIBS "LLVMFrontendOpenMP" _llvm_frontendOpenMP)
if (${_llvm_frontendOpenMP} GREATER -1)
list(APPEND llvm_raw_libs frontendopenmp)
endif()
if (${LLVM_PACKAGE_VERSION} VERSION_EQUAL 6 OR ${LLVM_PACKAGE_VERSION} VERSION_GREATER 6)
list(APPEND llvm_raw_libs bpfasmparser)
list(APPEND llvm_raw_libs bpfdisassembler)
Expand Down
8 changes: 8 additions & 0 deletions src/cc/frontends/b/codegen_llvm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,11 @@ StatusTuple CodegenLLVM::visit_table_index_expr_node(TableIndexExprNode *n) {
// var Leaf leaf {0}
Value *leaf_ptr = B.CreateBitCast(
make_alloca(resolve_entry_stack(), leaf_type), B.getInt8PtrTy());
#if LLVM_MAJOR_VERSION >= 10
B.CreateMemSet(leaf_ptr, B.getInt8(0), B.getInt64(n->table_->leaf_id()->bit_width_ >> 3), MaybeAlign(1));
#else
B.CreateMemSet(leaf_ptr, B.getInt8(0), B.getInt64(n->table_->leaf_id()->bit_width_ >> 3), 1);
#endif
// update(key, leaf)
B.CreateCall(update_fn, vector<Value *>({pseudo_map_fd, key_ptr, leaf_ptr, B.getInt64(BPF_NOEXIST)}));

Expand Down Expand Up @@ -1003,7 +1007,11 @@ StatusTuple CodegenLLVM::visit_struct_variable_decl_stmt_node(StructVariableDecl
B.CreateStore(const_null, ptr_a);
}
} else {
#if LLVM_MAJOR_VERSION >= 10
B.CreateMemSet(ptr_a, B.getInt8(0), B.getInt64(decl->bit_width_ >> 3), MaybeAlign(1));
#else
B.CreateMemSet(ptr_a, B.getInt8(0), B.getInt64(decl->bit_width_ >> 3), 1);
#endif
if (!n->init_.empty()) {
for (auto it = n->init_.begin(); it != n->init_.end(); ++it)
TRY2((*it)->accept(this));
Expand Down

0 comments on commit f9f1050

Please sign in to comment.