21 #include <llvm/Analysis/Dominators.h>
22 #include <llvm/Analysis/InstructionSimplify.h>
23 #include <llvm/Analysis/Passes.h>
24 #include <llvm/Support/InstIterator.h>
25 #include "llvm/Transforms/IPO.h"
26 #include <llvm/Transforms/Scalar.h>
27 #include <llvm/Transforms/Utils/SSAUpdater.h>
28 #include <llvm/Transforms/Utils/BasicBlockUtils.h>
32 #include "impala-ir/impala-ir-names.h"
38 using namespace impala;
132 }
while (num_inlined > 0);
139 DominatorTree dom_tree;
140 dom_tree.runOnFunction(*fn);
142 inst_iterator fn_end = inst_end(fn);
143 inst_iterator instr_iter = inst_begin(fn);
145 while (instr_iter != fn_end) {
146 Instruction* instr = &*instr_iter;
149 if (!CallInst::classof(instr))
continue;
151 CallInst* call_instr =
reinterpret_cast<CallInst*
>(instr);
152 Function* called_fn = call_instr->getCalledFunction();
165 DCHECK_EQ(call_instr->getNumArgOperands(), 3);
166 Value* row_arg = call_instr->getArgOperand(0);
168 DCHECK(BitCastInst::classof(row_arg));
169 BitCastInst* row_cast =
reinterpret_cast<BitCastInst*
>(row_arg);
172 row_arg = row_cast->getOperand(0);
174 instr = &*instr_iter;
177 if (!LoadInst::classof(instr))
continue;
178 LoadInst* is_null_value =
reinterpret_cast<LoadInst*
>(instr);
179 Value* loaded_ptr = is_null_value->getPointerOperand();
186 DCHECK_EQ(loaded_ptr, call_instr->getArgOperand(2));
188 pair<Function*, Value*> call_desc = make_pair(called_fn, row_arg);
189 if (cached_slot_ref_results.find(call_desc) == cached_slot_ref_results.end()) {
191 cache_entry.
result = call_instr;
193 cached_slot_ref_results[call_desc] = cache_entry;
197 if (dom_tree.dominates(cache_entry.
result, call_instr)) {
198 new StoreInst(cache_entry.
is_null_value, loaded_ptr, call_instr);
199 call_instr->replaceAllUsesWith(cache_entry.
result);
200 call_instr->eraseFromParent();
bool Run(llvm::Function *function)
Perform subexpr elimination on function.
SubExprElimination(LlvmCodeGen *codegen)
int InlineCallSites(llvm::Function *fn, bool skip_registered_fns)
LlvmCodeGen * codegen_
Parent codegen object.
Instruction * is_null_value
LLVM code generator. This is the top level object to generate jitted code.
std::set< llvm::Function * > registered_exprs_
A set of all the functions in 'registered_exprs_map_' for quick lookup.