| 211 | } |
| 212 | |
| 213 | LlvmCodeGen::LlvmCodeGen(FragmentState* state, ObjectPool* pool, |
| 214 | MemTracker* parent_mem_tracker, const string& id) |
| 215 | : state_(state), |
| 216 | id_(id), |
| 217 | profile_(RuntimeProfile::Create(pool, "CodeGen")), |
| 218 | mem_tracker_(pool->Add(new MemTracker(profile_, -1, "CodeGen", parent_mem_tracker))), |
| 219 | optimizations_enabled_(false), |
| 220 | is_corrupt_(false), |
| 221 | is_compiled_(false), |
| 222 | context_(new llvm::LLVMContext()), |
| 223 | module_(nullptr), |
| 224 | memory_manager_(nullptr), |
| 225 | cross_compiled_functions_(IRFunction::FN_END, nullptr) { |
| 226 | DCHECK(llvm_initialized_) << "Must call LlvmCodeGen::InitializeLlvm first."; |
| 227 | |
| 228 | context_->setDiagnosticHandler(&DiagnosticHandler::DiagnosticHandlerFn, this); |
| 229 | load_module_timer_ = ADD_TIMER(profile_, "LoadTime"); |
| 230 | prepare_module_timer_ = ADD_TIMER(profile_, "PrepareTime"); |
| 231 | codegen_cache_lookup_timer_ = ADD_TIMER(profile_, "CodegenCacheLookupTime"); |
| 232 | codegen_cache_save_timer_ = ADD_TIMER(profile_, "CodegenCacheSaveTime"); |
| 233 | module_bitcode_gen_timer_ = ADD_TIMER(profile_, "ModuleBitcodeGenTime"); |
| 234 | module_bitcode_size_ = ADD_COUNTER(profile_, "ModuleBitcodeSize", TUnit::BYTES); |
| 235 | ir_generation_timer_ = ADD_TIMER(profile_, "IrGenerationTime"); |
| 236 | function_prune_timer_ = ADD_TIMER(profile_, "FunctionPruneTime"); |
| 237 | optimization_timer_ = ADD_TIMER(profile_, "OptimizationTime"); |
| 238 | compile_timer_ = ADD_TIMER(profile_, "CompileTime"); |
| 239 | main_thread_timer_ = ADD_TIMER(profile_, "MainThreadCodegenTime"); |
| 240 | compile_thread_counters_ = ADD_THREAD_COUNTERS(profile_, |
| 241 | ASYNC_CODEGEN_THREAD_COUNTERS_PREFIX); |
| 242 | num_functions_ = ADD_COUNTER(profile_, "NumFunctions", TUnit::UNIT); |
| 243 | num_instructions_ = ADD_COUNTER(profile_, "NumInstructions", TUnit::UNIT); |
| 244 | num_opt_functions_ = ADD_COUNTER(profile_, "NumOptimizedFunctions", TUnit::UNIT); |
| 245 | num_opt_instructions_ = ADD_COUNTER(profile_, "NumOptimizedInstructions", TUnit::UNIT); |
| 246 | num_cached_functions_ = ADD_COUNTER(profile_, "NumCachedFunctions", TUnit::UNIT); |
| 247 | llvm_thread_counters_ = ADD_THREAD_COUNTERS(profile_, "Codegen"); |
| 248 | } |
| 249 | |
| 250 | Status LlvmCodeGen::CreateFromFile(FragmentState* state, ObjectPool* pool, |
| 251 | MemTracker* parent_mem_tracker, const string& file, const string& id, |