OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DiamondCodegen.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #include "Logger/Logger.h"
20 #include "QueryEngine/Execute.h"
21 
23  Executor* executor,
24  const bool chain_to_next,
25  const std::string& label_prefix,
26  DiamondCodegen* parent,
27  const bool share_false_edge_with_parent)
28  : executor_(executor), chain_to_next_(chain_to_next), parent_(parent) {
29  auto* cgen_state = executor_->cgen_state_.get();
30  CHECK(cgen_state);
31  AUTOMATIC_IR_METADATA(cgen_state);
32  if (parent_) {
34  }
35  cond_true_ = llvm::BasicBlock::Create(
36  cgen_state->context_, label_prefix + "_true", cgen_state->current_func_);
37  if (share_false_edge_with_parent) {
38  CHECK(parent);
40  } else {
41  orig_cond_false_ = cond_false_ = llvm::BasicBlock::Create(
42  cgen_state->context_, label_prefix + "_false", cgen_state->current_func_);
43  }
44 
45  cgen_state->ir_builder_.CreateCondBr(cond, cond_true_, cond_false_);
46  cgen_state->ir_builder_.SetInsertPoint(cond_true_);
47 }
48 
50  CHECK(!parent_);
51  chain_to_next_ = true;
52 }
53 
54 void DiamondCodegen::setFalseTarget(llvm::BasicBlock* cond_false) {
56  cond_false_ = cond_false;
57 }
58 
60  AUTOMATIC_IR_METADATA(executor_->cgen_state_.get());
61  auto& builder = executor_->cgen_state_->ir_builder_;
63  builder.CreateBr(parent_->cond_false_);
64  } else if (chain_to_next_) {
65  builder.CreateBr(cond_false_);
66  }
68  builder.SetInsertPoint(orig_cond_false_);
69  }
70 }
llvm::BasicBlock * cond_false_
DiamondCodegen(llvm::Value *cond, Executor *executor, const bool chain_to_next, const std::string &label_prefix, DiamondCodegen *parent, const bool share_false_edge_with_parent)
void setFalseTarget(llvm::BasicBlock *cond_false)
llvm::BasicBlock * cond_true_
DiamondCodegen * parent_
executor_(executor)
#define AUTOMATIC_IR_METADATA(CGENSTATE)
llvm::BasicBlock * orig_cond_false_
#define CHECK(condition)
Definition: Logger.h:291
Executor * executor_