| 109 | } // namespace |
| 110 | |
| 111 | CompiledModuleSP RowContainerCodeGenerator::codegen() { |
| 112 | auto fn = GetCmpFuncName(); |
| 113 | |
| 114 | auto jit = ThrustJITv2::getInstance(); |
| 115 | |
| 116 | if (auto mod = jit->LookupSymbolsInCache(fn)) { |
| 117 | return mod; |
| 118 | } |
| 119 | |
| 120 | auto genIR = [this](llvm::Module& m) -> bool { |
| 121 | ensureBuiltinDeclarations(m); |
| 122 | this->setModule(&m); |
| 123 | return this->GenCmpIR(); |
| 124 | }; |
| 125 | |
| 126 | auto module = jit->CompileModule(genIR, fn); |
| 127 | if (isEqualOp() || !flags.empty()) { // only for row cmp/= row |
| 128 | auto cacheTypes = std::make_unique<std::vector<bytedance::bolt::TypePtr>>(); |
| 129 | for (auto& t : keysTypes) { |
| 130 | switch (t->kind()) { |
| 131 | case bytedance::bolt::TypeKind::ARRAY: |
| 132 | case bytedance::bolt::TypeKind::ROW: |
| 133 | case bytedance::bolt::TypeKind::MAP: |
| 134 | cacheTypes->push_back(t); |
| 135 | break; |
| 136 | default: |
| 137 | break; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | if (cacheTypes->size() > 0) { |
| 142 | auto* userData = static_cast<void*>(cacheTypes.get()); |
| 143 | if (module->compareExchangeUserData(nullptr, userData)) { |
| 144 | cacheTypes.release(); |
| 145 | module->appendCleanCallback([mod = module.get()] { |
| 146 | auto* raw = mod->getUserData(); |
| 147 | mod->compareExchangeUserData(raw, nullptr); |
| 148 | auto* cacheTypes = |
| 149 | static_cast<std::vector<bytedance::bolt::TypePtr>*>(raw); |
| 150 | delete cacheTypes; |
| 151 | }); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | return module; |
| 156 | } |
| 157 | |
| 158 | /// util functions |
| 159 | std::string RowContainerCodeGenerator::GetCmpFuncName() { |