Skip to content

Commit

Permalink
Fix handling of multiple extra keys
Browse files Browse the repository at this point in the history
Increment offset when handing extra keys in CodegenLLVM::getMultiMapKey
and infer their size from DataLayout. The total size of extra keys is now
also inferred from DataLayout and the extra_keys_size argument previously
used for it is removed.

Currently this has no effect, since multiple extra keys are never used.
  • Loading branch information
lenticularis39 authored and fbs committed Aug 10, 2022
1 parent 82ddfdd commit 14ec7ea
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 9 additions & 5 deletions src/ast/passes/codegen_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2581,7 +2581,7 @@ std::tuple<Value *, CodegenLLVM::ScopedExprDeleter> CodegenLLVM::getMapKey(
else
{
// Two or more values as a map key (e.g, @[comm, pid] = 1;)
key = getMultiMapKey(map, {}, 0);
key = getMultiMapKey(map, {});
}
}
else
Expand All @@ -2599,14 +2599,17 @@ std::tuple<Value *, CodegenLLVM::ScopedExprDeleter> CodegenLLVM::getMapKey(
}

AllocaInst *CodegenLLVM::getMultiMapKey(Map &map,
const std::vector<Value *> &extra_keys,
size_t extra_keys_size)
const std::vector<Value *> &extra_keys)
{
size_t size = extra_keys_size;
size_t size = 0;
for (auto &key_type : map.key_type.args_)
{
size += key_type.GetSize();
}
for (auto *extra_key : extra_keys)
{
size += module_->getDataLayout().getTypeAllocSize(extra_key->getType());
}
AllocaInst *key = b_.CreateAllocaBPF(size, map.ident + "_key");
auto *key_type = ArrayType::get(b_.getInt8Ty(), size);

Expand Down Expand Up @@ -2673,6 +2676,7 @@ AllocaInst *CodegenLLVM::getMultiMapKey(Map &map,
b_.CreateStore(extra_key, offset_val_cast);
else
b_.createAlignedStore(extra_key, offset_val_cast, 1);
offset += module_->getDataLayout().getTypeAllocSize(extra_key->getType());
}

return key;
Expand All @@ -2681,7 +2685,7 @@ AllocaInst *CodegenLLVM::getMultiMapKey(Map &map,
AllocaInst *CodegenLLVM::getHistMapKey(Map &map, Value *log2)
{
if (map.vargs)
return getMultiMapKey(map, { log2 }, 8);
return getMultiMapKey(map, { log2 });

AllocaInst *key = b_.CreateAllocaBPF(CreateUInt64(), map.ident + "_key");
b_.CreateStore(log2, key);
Expand Down
4 changes: 1 addition & 3 deletions src/ast/passes/codegen_llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ class CodegenLLVM : public Visitor

[[nodiscard]] ScopedExprDeleter accept(Node *node);
[[nodiscard]] std::tuple<Value *, ScopedExprDeleter> getMapKey(Map &map);
AllocaInst *getMultiMapKey(Map &map,
const std::vector<Value *> &extra_keys,
size_t extra_keys_size);
AllocaInst *getMultiMapKey(Map &map, const std::vector<Value *> &extra_keys);

void compareStructure(SizedType &our_type, llvm::Type *llvm_type);

Expand Down

0 comments on commit 14ec7ea

Please sign in to comment.