Skip to content

Commit

Permalink
Cast integers to the correct type
Browse files Browse the repository at this point in the history
Apply Brendan's patch
  • Loading branch information
mlen committed Oct 15, 2018
1 parent c86d02b commit de5e6d8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ast/codegen_llvm.cpp
Expand Up @@ -160,6 +160,7 @@ void CodegenLLVM::visit(Call &call)
AllocaInst *newval = b_.CreateAllocaBPF(map.type, map.ident + "_val");

call.vargs->front()->accept(*this);
expr_ = b_.CreateIntCast(expr_, b_.getInt64Ty(), false); // promote int to 64-bit
b_.CreateStore(b_.CreateAdd(expr_, oldval), newval);
b_.CreateMapUpdateElem(map, key, newval);

Expand All @@ -179,6 +180,7 @@ void CodegenLLVM::visit(Call &call)
// elements will always store on the first occurrance. Revent this later when printing.
Function *parent = b_.GetInsertBlock()->getParent();
call.vargs->front()->accept(*this);
expr_ = b_.CreateIntCast(expr_, b_.getInt64Ty(), false); // promote int to 64-bit
Value *inverted = b_.CreateSub(b_.getInt64(0xffffffff), expr_);
BasicBlock *lt = BasicBlock::Create(module_->getContext(), "min.lt", parent);
BasicBlock *ge = BasicBlock::Create(module_->getContext(), "min.ge", parent);
Expand All @@ -203,6 +205,7 @@ void CodegenLLVM::visit(Call &call)

Function *parent = b_.GetInsertBlock()->getParent();
call.vargs->front()->accept(*this);
expr_ = b_.CreateIntCast(expr_, b_.getInt64Ty(), false); // promote int to 64-bit
BasicBlock *lt = BasicBlock::Create(module_->getContext(), "min.lt", parent);
BasicBlock *ge = BasicBlock::Create(module_->getContext(), "min.ge", parent);
b_.CreateCondBr(b_.CreateICmpSGE(expr_, oldval), ge, lt);
Expand Down Expand Up @@ -235,6 +238,7 @@ void CodegenLLVM::visit(Call &call)
Value *total_old = b_.CreateMapLookupElem(map, total_key);
AllocaInst *total_new = b_.CreateAllocaBPF(map.type, map.ident + "_val");
call.vargs->front()->accept(*this);
expr_ = b_.CreateIntCast(expr_, b_.getInt64Ty(), false); // promote int to 64-bit
b_.CreateStore(b_.CreateAdd(expr_, total_old), total_new);
b_.CreateMapUpdateElem(map, total_key, total_new);
b_.CreateLifetimeEnd(total_key);
Expand All @@ -246,6 +250,7 @@ void CodegenLLVM::visit(Call &call)
{
Map &map = *call.map;
call.vargs->front()->accept(*this);
expr_ = b_.CreateIntCast(expr_, b_.getInt64Ty(), false); // promote int to 64-bit
Function *log2_func = module_->getFunction("log2");
Value *log2 = b_.CreateCall(log2_func, expr_, "log2");
AllocaInst *key = getHistMapKey(map, log2);
Expand Down Expand Up @@ -281,6 +286,12 @@ void CodegenLLVM::visit(Call &call)
step_arg.accept(*this);
step = expr_;

// promote int to 64-bit
value = b_.CreateIntCast(value, b_.getInt64Ty(), false);
min = b_.CreateIntCast(min, b_.getInt64Ty(), false);
max = b_.CreateIntCast(max, b_.getInt64Ty(), false);
step = b_.CreateIntCast(step, b_.getInt64Ty(), false);

Value *linear = b_.CreateCall(linear_func, {value, min, max, step} , "linear");

AllocaInst *key = getHistMapKey(map, linear);
Expand Down

0 comments on commit de5e6d8

Please sign in to comment.