From f9f1050f0d61e56ed43df0f1338a30389bfcc2ba Mon Sep 17 00:00:00 2001 From: Yonghong Song Date: Tue, 10 Dec 2019 08:36:10 -0800 Subject: [PATCH] fix a compilation error with latest llvm 10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- cmake/clang_libs.cmake | 4 ++++ src/cc/frontends/b/codegen_llvm.cc | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/cmake/clang_libs.cmake b/cmake/clang_libs.cmake index 5ebfaa541981..c33b635cd188 100644 --- a/cmake/clang_libs.cmake +++ b/cmake/clang_libs.cmake @@ -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) diff --git a/src/cc/frontends/b/codegen_llvm.cc b/src/cc/frontends/b/codegen_llvm.cc index 7753be91e7c8..a69fdba92e2a 100644 --- a/src/cc/frontends/b/codegen_llvm.cc +++ b/src/cc/frontends/b/codegen_llvm.cc @@ -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({pseudo_map_fd, key_ptr, leaf_ptr, B.getInt64(BPF_NOEXIST)})); @@ -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));