6 DMLC_REGISTRY_FILE_TAG(split);
8 void ASTBuilder::Split(
int parallel_comp) {
9 if (parallel_comp <= 0) {
10 LOG(INFO) <<
"Parallel compilation disabled; all member trees will be " 11 <<
"dumped to a single source file. This may increase " 12 <<
"compilation time and memory usage.";
15 LOG(INFO) <<
"Parallel compilation enabled; member trees will be " 16 <<
"divided into " << parallel_comp <<
" translation units.";
17 CHECK_EQ(this->main_node->children.size(), 1);
18 ASTNode* top_ac_node = this->main_node->children[0];
19 CHECK(dynamic_cast<AccumulatorContextNode*>(top_ac_node));
22 std::vector<ConditionNode*> tree_head;
23 for (ASTNode* node : top_ac_node->children) {
24 ConditionNode* tree_head_node =
dynamic_cast<ConditionNode*
>(node);
25 CHECK(tree_head_node);
26 tree_head.push_back(tree_head_node);
31 const int ntree =
static_cast<int>(tree_head.size());
32 const int nunit = parallel_comp;
33 const int unit_size = (ntree + nunit - 1) / nunit;
34 std::vector<ASTNode*> tu_list;
35 for (
int unit_id = 0; unit_id < nunit; ++unit_id) {
36 const int tree_begin = unit_id * unit_size;
37 const int tree_end = std::min((unit_id + 1) * unit_size, ntree);
38 if (tree_begin < tree_end) {
39 TranslationUnitNode* tu = AddNode<TranslationUnitNode>(top_ac_node,
41 tu_list.push_back(tu);
42 AccumulatorContextNode* ac = AddNode<AccumulatorContextNode>(tu);
43 tu->children.push_back(ac);
44 for (
int tree_id = tree_begin; tree_id < tree_end; ++tree_id) {
45 ConditionNode* tree_head_node = tree_head[tree_id];
46 tree_head_node->parent = ac;
47 ac->children.push_back(tree_head_node);
51 top_ac_node->children = tu_list;