void CodeGen::ThrowIfOverflow(llvm::Value *overflow) const { PELOTON_ASSERT(overflow->getType() == BoolType()); // Get the overflow basic block for the currently generating function auto *func = code_context_.GetCurrentFunction(); auto *overflow_bb = func->GetOverflowBB(); // Construct a new block that we jump if there *isn't* an overflow llvm::BasicBlock *no_overflow_bb = llvm::BasicBlock::Create(GetContext(), "cont", func->GetFunction()); // Create a branch that goes to the overflow BB if an overflow exists auto &builder = GetBuilder(); builder.CreateCondBr(overflow, overflow_bb, no_overflow_bb); // Start insertion in the block builder.SetInsertPoint(no_overflow_bb); }
void CodeGen::ThrowIfDivideByZero(llvm::Value *divide_by_zero) const { PELOTON_ASSERT(divide_by_zero->getType() == BoolType()); // Get the divide-by-zero basic block for the currently generating function auto *func = code_context_.GetCurrentFunction(); auto *div0_bb = func->GetDivideByZeroBB(); // Construct a new block that we jump if there *isn't* a divide-by-zero llvm::BasicBlock *no_div0_bb = llvm::BasicBlock::Create(GetContext(), "cont", func->GetFunction()); // Create a branch that goes to the divide-by-zero BB if an error exists auto &builder = GetBuilder(); builder.CreateCondBr(divide_by_zero, div0_bb, no_div0_bb); // Start insertion in the block builder.SetInsertPoint(no_div0_bb); }
Value BoolValue(bool b){return Value( BoolType(),1,b);}