OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CodeGenerator::NullCheckCodegen Struct Reference

#include <CodeGenerator.h>

+ Collaboration diagram for CodeGenerator::NullCheckCodegen:

Public Member Functions

 NullCheckCodegen (CgenState *cgen_state, Executor *executor, llvm::Value *nullable_lv, const SQLTypeInfo &nullable_ti, const std::string &name="")
 
llvm::Value * finalize (llvm::Value *null_lv, llvm::Value *notnull_lv)
 

Public Attributes

CgenStatecgen_state {nullptr}
 
std::string name
 
llvm::BasicBlock * nullcheck_bb {nullptr}
 
llvm::PHINode * nullcheck_value {nullptr}
 
std::unique_ptr< DiamondCodegennull_check
 

Detailed Description

Definition at line 135 of file CodeGenerator.h.

Constructor & Destructor Documentation

CodeGenerator::NullCheckCodegen::NullCheckCodegen ( CgenState cgen_state,
Executor executor,
llvm::Value *  nullable_lv,
const SQLTypeInfo nullable_ti,
const std::string &  name = "" 
)

Definition at line 1493 of file IRCodegen.cpp.

References AUTOMATIC_IR_METADATA, CHECK, CgenState::context_, CgenState::current_func_, CodeGenerator::executor(), CgenState::inlineFpNull(), CgenState::inlineIntNull(), CgenState::ir_builder_, SQLTypeInfo::is_boolean(), SQLTypeInfo::is_dict_encoded_string(), SQLTypeInfo::is_fp(), SQLTypeInfo::is_number(), SQLTypeInfo::is_time(), CgenState::llBool(), name, null_check, and nullcheck_bb.

1498  : cgen_state(cgen_state), name(name) {
1499  AUTOMATIC_IR_METADATA(cgen_state);
1500  CHECK(nullable_ti.is_number() || nullable_ti.is_time() || nullable_ti.is_boolean() ||
1501  nullable_ti.is_dict_encoded_string());
1502 
1503  llvm::Value* is_null_lv{nullptr};
1504  if (nullable_ti.is_fp()) {
1505  is_null_lv = cgen_state->ir_builder_.CreateFCmp(
1506  llvm::FCmpInst::FCMP_OEQ, nullable_lv, cgen_state->inlineFpNull(nullable_ti));
1507  } else if (nullable_ti.is_boolean() &&
1508  nullable_lv->getType()->getIntegerBitWidth() == 1) {
1509  is_null_lv = cgen_state->ir_builder_.CreateICmp(
1510  llvm::ICmpInst::ICMP_EQ, nullable_lv, cgen_state->llBool(true));
1511  } else {
1512  is_null_lv = cgen_state->ir_builder_.CreateICmp(
1513  llvm::ICmpInst::ICMP_EQ, nullable_lv, cgen_state->inlineIntNull(nullable_ti));
1514  }
1515  CHECK(is_null_lv);
1516  null_check =
1517  std::make_unique<DiamondCodegen>(is_null_lv, executor, false, name, nullptr, false);
1518 
1519  // generate a phi node depending on whether we got a null or not
1520  nullcheck_bb = llvm::BasicBlock::Create(
1521  cgen_state->context_, name + "_bb", cgen_state->current_func_);
1522 
1523  // update the blocks created by diamond codegen to point to the newly created phi
1524  // block
1525  cgen_state->ir_builder_.SetInsertPoint(null_check->cond_true_);
1526  cgen_state->ir_builder_.CreateBr(nullcheck_bb);
1527  cgen_state->ir_builder_.SetInsertPoint(null_check->cond_false_);
1528 }
llvm::BasicBlock * nullcheck_bb
bool is_fp() const
Definition: sqltypes.h:573
llvm::IRBuilder ir_builder_
Definition: CgenState.h:384
llvm::ConstantInt * llBool(const bool v) const
Definition: CgenState.h:263
bool is_number() const
Definition: sqltypes.h:576
bool is_time() const
Definition: sqltypes.h:579
llvm::LLVMContext & context_
Definition: CgenState.h:382
llvm::Function * current_func_
Definition: CgenState.h:376
llvm::ConstantInt * inlineIntNull(const SQLTypeInfo &)
Definition: CgenState.cpp:65
bool is_boolean() const
Definition: sqltypes.h:582
#define AUTOMATIC_IR_METADATA(CGENSTATE)
#define CHECK(condition)
Definition: Logger.h:291
bool is_dict_encoded_string() const
Definition: sqltypes.h:643
std::unique_ptr< DiamondCodegen > null_check
llvm::ConstantFP * inlineFpNull(const SQLTypeInfo &)
Definition: CgenState.cpp:104
Executor * executor() const

+ Here is the call graph for this function:

Member Function Documentation

llvm::Value * CodeGenerator::NullCheckCodegen::finalize ( llvm::Value *  null_lv,
llvm::Value *  notnull_lv 
)

Definition at line 1530 of file IRCodegen.cpp.

References AUTOMATIC_IR_METADATA, CHECK, CHECK_EQ, and setup::name.

Referenced by spatial_type::Transform::codegen().

1531  {
1533  CHECK(null_check);
1534  cgen_state->ir_builder_.CreateBr(nullcheck_bb);
1535 
1536  CHECK_EQ(null_lv->getType(), notnull_lv->getType());
1537 
1538  cgen_state->ir_builder_.SetInsertPoint(nullcheck_bb);
1539  nullcheck_value =
1540  cgen_state->ir_builder_.CreatePHI(null_lv->getType(), 2, name + "_value");
1541  nullcheck_value->addIncoming(notnull_lv, null_check->cond_false_);
1542  nullcheck_value->addIncoming(null_lv, null_check->cond_true_);
1543 
1544  null_check.reset(nullptr);
1545  cgen_state->ir_builder_.SetInsertPoint(nullcheck_bb);
1546  return nullcheck_value;
1547 }
#define CHECK_EQ(x, y)
Definition: Logger.h:301
llvm::BasicBlock * nullcheck_bb
llvm::IRBuilder ir_builder_
Definition: CgenState.h:384
#define AUTOMATIC_IR_METADATA(CGENSTATE)
#define CHECK(condition)
Definition: Logger.h:291
std::unique_ptr< DiamondCodegen > null_check

+ Here is the caller graph for this function:

Member Data Documentation

CgenState* CodeGenerator::NullCheckCodegen::cgen_state {nullptr}

Definition at line 144 of file CodeGenerator.h.

std::unique_ptr<DiamondCodegen> CodeGenerator::NullCheckCodegen::null_check

Definition at line 148 of file CodeGenerator.h.

Referenced by NullCheckCodegen().

llvm::BasicBlock* CodeGenerator::NullCheckCodegen::nullcheck_bb {nullptr}

Definition at line 146 of file CodeGenerator.h.

Referenced by NullCheckCodegen().

llvm::PHINode* CodeGenerator::NullCheckCodegen::nullcheck_value {nullptr}

Definition at line 147 of file CodeGenerator.h.


The documentation for this struct was generated from the following files: