Skip to content

Commit

Permalink
Add support for llvm 15
Browse files Browse the repository at this point in the history
llvm 15 removes PointerType::getElementType() ([0]) which breaks
bpftrace build. Use Type::getPointerElementType() instead to fix
it.

  [0]: llvm/llvm-project@d593cf7
  • Loading branch information
chenhengqi authored and fbs committed Mar 9, 2022
1 parent 8f88925 commit f94e018
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ else()
endif()

set(MIN_LLVM_MAJOR 6)
set(MAX_LLVM_MAJOR 14)
set(MAX_LLVM_MAJOR 15)

if((${LLVM_VERSION_MAJOR} VERSION_LESS ${MIN_LLVM_MAJOR}) OR (${LLVM_VERSION_MAJOR} VERSION_GREATER ${MAX_LLVM_MAJOR}))
message(SEND_ERROR "Unsupported LLVM version found via ${LLVM_INCLUDE_DIRS}: ${LLVM_VERSION_MAJOR}")
Expand Down
25 changes: 14 additions & 11 deletions src/ast/irbuilderbpf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ CallInst *IRBuilderBPF::createCall(Value *callee,
{
#if LLVM_VERSION_MAJOR >= 11
auto *calleePtrType = cast<PointerType>(callee->getType());
auto *calleeType = cast<FunctionType>(calleePtrType->getElementType());
auto *calleeType = cast<FunctionType>(calleePtrType->getPointerElementType());
return CreateCall(calleeType, callee, args, Name);
#else
return CreateCall(callee, args, Name);
Expand Down Expand Up @@ -383,7 +383,7 @@ Value *IRBuilderBPF::CreateMapLookupElem(Value *ctx,
else
{
assert(value->getType()->isPointerTy() &&
(value->getType()->getElementType() == getInt64Ty()));
(value->getType()->getPointerElementType() == getInt64Ty()));
// createMapLookup returns an u8*
auto *cast = CreatePointerCast(call, value->getType(), "cast");
CreateStore(CreateLoad(getInt64Ty(), cast), value);
Expand Down Expand Up @@ -768,14 +768,16 @@ Value *IRBuilderBPF::CreateStrncmp(Value *val1,
if (!literal1)
{
assert(val1p);
assert(val1p->getElementType()->isArrayTy() &&
val1p->getElementType()->getArrayElementType() == getInt8Ty());
assert(val1p->getPointerElementType()->isArrayTy() &&
val1p->getPointerElementType()->getArrayElementType() ==
getInt8Ty());
}
if (!literal2)
{
assert(val2p);
assert(val2p->getElementType()->isArrayTy() &&
val2p->getElementType()->getArrayElementType() == getInt8Ty());
assert(val2p->getPointerElementType()->isArrayTy() &&
val2p->getPointerElementType()->getArrayElementType() ==
getInt8Ty());
}
#endif

Expand Down Expand Up @@ -805,7 +807,7 @@ Value *IRBuilderBPF::CreateStrncmp(Value *val1,
l = getInt8(literal1->c_str()[i]);
else
{
auto *ptr_l = CreateGEP(val1p->getElementType(),
auto *ptr_l = CreateGEP(val1p->getPointerElementType(),
val1,
{ getInt32(0), getInt32(i) });
l = CreateLoad(getInt8Ty(), ptr_l);
Expand All @@ -816,7 +818,7 @@ Value *IRBuilderBPF::CreateStrncmp(Value *val1,
r = getInt8(literal2->c_str()[i]);
else
{
auto *ptr_r = CreateGEP(val2p->getElementType(),
auto *ptr_r = CreateGEP(val2p->getPointerElementType(),
val2,
{ getInt32(0), getInt32(i) });
r = CreateLoad(getInt8Ty(), ptr_r);
Expand Down Expand Up @@ -981,9 +983,10 @@ void IRBuilderBPF::CreateGetCurrentComm(Value *ctx,
size_t size,
const location &loc)
{
assert(buf->getType()->getElementType()->isArrayTy() &&
buf->getType()->getElementType()->getArrayNumElements() >= size &&
buf->getType()->getElementType()->getArrayElementType() ==
assert(buf->getType()->getPointerElementType()->isArrayTy() &&
buf->getType()->getPointerElementType()->getArrayNumElements() >=
size &&
buf->getType()->getPointerElementType()->getArrayElementType() ==
getInt8Ty());

// int bpf_get_current_comm(char *buf, int size_of_buf)
Expand Down
5 changes: 3 additions & 2 deletions src/ast/passes/codegen_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,8 @@ void CodegenLLVM::visit(Variable &var)
else
{
auto *var_alloca = variables_[var.ident];
expr_ = b_.CreateLoad(var_alloca->getType()->getElementType(), var_alloca);
expr_ = b_.CreateLoad(var_alloca->getType()->getPointerElementType(),
var_alloca);
}
}

Expand Down Expand Up @@ -3319,7 +3320,7 @@ void CodegenLLVM::createIncDec(Unop &unop)
{
Variable &var = static_cast<Variable &>(*unop.expr);
Value *oldval = b_.CreateLoad(
variables_[var.ident]->getType()->getElementType(),
variables_[var.ident]->getType()->getPointerElementType(),
variables_[var.ident]);
Value *newval;
if (is_increment)
Expand Down

0 comments on commit f94e018

Please sign in to comment.