Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===-LTOCodeGenerator.cpp - LLVM Link Time Optimizer ---------------------===// | 1 //===-LTOCodeGenerator.cpp - LLVM Link Time Optimizer ---------------------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This file implements the Link Time Optimization library. This library is | 10 // This file implements the Link Time Optimization library. This library is |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) { | 94 bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) { |
| 95 bool ret = _linker.LinkInModule(mod->getLLVVMModule(), &errMsg); | 95 bool ret = _linker.LinkInModule(mod->getLLVVMModule(), &errMsg); |
| 96 | 96 |
| 97 const std::vector<const char*> &undefs = mod->getAsmUndefinedRefs(); | 97 const std::vector<const char*> &undefs = mod->getAsmUndefinedRefs(); |
| 98 for (int i = 0, e = undefs.size(); i != e; ++i) | 98 for (int i = 0, e = undefs.size(); i != e; ++i) |
| 99 _asmUndefinedRefs[undefs[i]] = 1; | 99 _asmUndefinedRefs[undefs[i]] = 1; |
| 100 | 100 |
| 101 return ret; | 101 return ret; |
| 102 } | 102 } |
| 103 | 103 |
| 104 | |
| 105 // @LOCALMOD-BEGIN | |
| 106 bool LTOCodeGenerator::gatherModule(LTOModule* mod) { | |
|
robertm
2012/08/01 14:02:31
gather is no a very specific term.
Maybe add a com
jvoung (off chromium)
2012/08/01 17:11:01
renamed to gatherModuleForLink(), but yeah, not su
| |
| 107 _gatheredModules.push_back(mod); | |
| 108 } | |
| 109 | |
| 110 bool LTOCodeGenerator::linkGatheredModulesAndDispose(std::string& errMsg) { | |
| 111 // We gather the asm undefs earlier than addModule() does, | |
|
robertm
2012/08/01 14:02:31
since the llvm folks did not seem to have commente
jvoung (off chromium)
2012/08/01 17:11:01
Added some comments. Hopefully this is a constant
| |
| 112 // since we delete the modules earlier. | |
| 113 for (unsigned i = 0, ei = _gatheredModules.size(); i != ei; ++i) { | |
| 114 const std::vector<const char*> &undefs = | |
| 115 _gatheredModules[i]->getAsmUndefinedRefs(); | |
| 116 for (int j = 0, ej = undefs.size(); j != ej; ++j) { | |
| 117 _asmUndefinedRefs[undefs[j]] = 1; | |
| 118 } | |
| 119 } | |
| 120 | |
| 121 // Tree-reduce the mods, re-using the incoming mods as scratch | |
| 122 // intermediate results. Module i is linked with (i + stride), with i as | |
| 123 // the dest. Eventually the Module with the content of all other modules | |
| 124 // will be Module 0. | |
|
robertm
2012/08/01 14:02:31
not sure whether this adds all that much:
After th
jvoung (off chromium)
2012/08/01 17:11:01
Done.
| |
| 125 unsigned stride = 1; | |
| 126 unsigned len = _gatheredModules.size(); | |
| 127 while (stride < len) { | |
|
robertm
2012/08/01 14:02:31
why not use a for loop here as well
jvoung (off chromium)
2012/08/01 17:11:01
Done.
| |
| 128 for (unsigned i = 0; i + stride < len; i = i + (stride * 2)) { | |
| 129 if (Linker::LinkModules(_gatheredModules[i]->getLLVVMModule(), | |
| 130 _gatheredModules[i+stride]->getLLVVMModule(), | |
| 131 Linker::DestroySource, &errMsg)) { | |
| 132 errs() << "LinkModules " << i << " w/ " << i + stride << " failed...\n"; | |
| 133 // We leak the memory in this case... | |
| 134 return true; | |
| 135 } | |
| 136 delete _gatheredModules[i+stride]; | |
| 137 } | |
| 138 stride = stride * 2; | |
| 139 } | |
| 140 | |
| 141 // Finally, link Node 0 with the Dest and delete Node 0. | |
| 142 if (_linker.LinkInModule(_gatheredModules[0]->getLLVVMModule(), &errMsg)) { | |
| 143 errs() << "LinkModules Dst w/ _gatheredModules[0] failed...\n"; | |
| 144 return true; | |
| 145 } | |
| 146 delete _gatheredModules[0]; | |
| 147 | |
| 148 return false; | |
| 149 } | |
| 150 // @LOCALMOD-END | |
| 151 | |
| 104 bool LTOCodeGenerator::setDebugInfo(lto_debug_model debug, | 152 bool LTOCodeGenerator::setDebugInfo(lto_debug_model debug, |
| 105 std::string& errMsg) { | 153 std::string& errMsg) { |
| 106 switch (debug) { | 154 switch (debug) { |
| 107 case LTO_DEBUG_MODEL_NONE: | 155 case LTO_DEBUG_MODEL_NONE: |
| 108 _emitDwarfDebugInfo = false; | 156 _emitDwarfDebugInfo = false; |
| 109 return false; | 157 return false; |
| 110 | 158 |
| 111 case LTO_DEBUG_MODEL_DWARF: | 159 case LTO_DEBUG_MODEL_DWARF: |
| 112 _emitDwarfDebugInfo = true; | 160 _emitDwarfDebugInfo = true; |
| 113 return false; | 161 return false; |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 void LTOCodeGenerator::setCodeGenDebugOptions(const char *options) { | 534 void LTOCodeGenerator::setCodeGenDebugOptions(const char *options) { |
| 487 for (std::pair<StringRef, StringRef> o = getToken(options); | 535 for (std::pair<StringRef, StringRef> o = getToken(options); |
| 488 !o.first.empty(); o = getToken(o.second)) { | 536 !o.first.empty(); o = getToken(o.second)) { |
| 489 // ParseCommandLineOptions() expects argv[0] to be program name. Lazily add | 537 // ParseCommandLineOptions() expects argv[0] to be program name. Lazily add |
| 490 // that. | 538 // that. |
| 491 if ( _codegenOptions.empty() ) | 539 if ( _codegenOptions.empty() ) |
| 492 _codegenOptions.push_back(strdup("libLTO")); | 540 _codegenOptions.push_back(strdup("libLTO")); |
| 493 _codegenOptions.push_back(strdup(o.first.str().c_str())); | 541 _codegenOptions.push_back(strdup(o.first.str().c_str())); |
| 494 } | 542 } |
| 495 } | 543 } |
| OLD | NEW |