Skip to content

Commit

Permalink
it's only in LLVM 12+ that llvm::SplitEdge() gains a 6th param BBName…
Browse files Browse the repository at this point in the history
… for naming blocks. use macros to provide a version-agnostic API (which discards the BBName -- LLVM will use a default block name '%s.split' derived from one of the blocks bifurcated by the edge)
  • Loading branch information
Birch-san committed Jun 17, 2021
1 parent 078c5f0 commit e4a5d6a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/ast/irbuilderbpf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

#include <llvm/IR/DataLayout.h>
#include <llvm/IR/Module.h>
#include <llvm/Transforms/Utils/BasicBlockUtils.h>

namespace libbpf {
#undef __BPF_FUNC_MAPPER
Expand Down Expand Up @@ -379,12 +378,12 @@ CallInst *IRBuilderBPF::CreateGetScratchMap(Value *ctx,
{
assert(post_hoist_block_ != nullptr);
auto ip = saveIP();
BasicBlock *get_map = SplitEdge(post_hoist_block_->getSinglePredecessor(),
post_hoist_block_,
nullptr,
nullptr,
nullptr,
"validate_map_lookup_" + name);
BasicBlock *get_map = SPLIT_EDGE(post_hoist_block_->getSinglePredecessor(),
post_hoist_block_,
nullptr,
nullptr,
nullptr,
"validate_map_lookup_" + name);
// remove the unconditional break to posthoist which SplitEdge gives us,
// because CreateHelperErrorCond() will emit a conditional break to posthoist
// instead
Expand Down
14 changes: 14 additions & 0 deletions src/ast/irbuilderbpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <llvm/Config/llvm-config.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/Transforms/Utils/BasicBlockUtils.h>

#if LLVM_VERSION_MAJOR >= 5 && LLVM_VERSION_MAJOR < 7
#define CREATE_MEMCPY(dst, src, size, algn) \
Expand Down Expand Up @@ -35,6 +36,19 @@
CreateMemSet((ptr), (val), (size), (align))
#endif

#if LLVM_VERSION_MAJOR >= 5 && LLVM_VERSION_MAJOR < 8
#define SPLIT_EDGE(from, to, dt, li, mssau, bbname) \
SplitEdge((from), (to), (dt), (li))
#elif LLVM_VERSION_MAJOR >= 8 && LLVM_VERSION_MAJOR < 12
#define SPLIT_EDGE(from, to, dt, li, mssau, bbname) \
SplitEdge((from), (to), (dt), (li), (mssau))
#elif LLVM_VERSION_MAJOR >= 12
#define SPLIT_EDGE(from, to, dt, li, mssau, bbname) \
SplitEdge((from), (to), (dt), (li), (mssau), (bbname))
#else
#error Unsupported LLVM version
#endif

namespace bpftrace {
namespace ast {

Expand Down

0 comments on commit e4a5d6a

Please sign in to comment.