Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Standalone View
llvm/tools/lto/lto.cpp
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | |||||
// Holds most recent error string. | // Holds most recent error string. | ||||
// *** Not thread safe *** | // *** Not thread safe *** | ||||
static std::string sLastErrorString; | static std::string sLastErrorString; | ||||
// Holds the initialization state of the LTO module. | // Holds the initialization state of the LTO module. | ||||
// *** Not thread safe *** | // *** Not thread safe *** | ||||
static bool initialized = false; | static bool initialized = false; | ||||
// Holds the command-line option parsing state of the LTO module. | // Represent the state of parsing command line debug options. | ||||
static bool parsedOptions = false; | static enum class OptParsingState { | ||||
NotParsed, // Initial state. | |||||
Early, // After lto_set_debug_options is called. | |||||
Done // After maybeParseOptions is called. | |||||
} optionParsingState = OptParsingState::NotParsed; | |||||
static LLVMContext *LTOContext = nullptr; | static LLVMContext *LTOContext = nullptr; | ||||
struct LTOToolDiagnosticHandler : public DiagnosticHandler { | struct LTOToolDiagnosticHandler : public DiagnosticHandler { | ||||
bool handleDiagnostics(const DiagnosticInfo &DI) override { | bool handleDiagnostics(const DiagnosticInfo &DI) override { | ||||
if (DI.getSeverity() != DS_Error) { | if (DI.getSeverity() != DS_Error) { | ||||
DiagnosticPrinterRawOStream DP(errs()); | DiagnosticPrinterRawOStream DP(errs()); | ||||
DI.print(DP); | DI.print(DP); | ||||
▲ Show 20 Lines • Show All 337 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, | void lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, | ||||
const char *symbol) { | const char *symbol) { | ||||
unwrap(cg)->addMustPreserveSymbol(symbol); | unwrap(cg)->addMustPreserveSymbol(symbol); | ||||
} | } | ||||
static void maybeParseOptions(lto_code_gen_t cg) { | static void maybeParseOptions(lto_code_gen_t cg) { | ||||
if (!parsedOptions) { | if (optionParsingState != OptParsingState::Done) { | ||||
// Parse options if any were set by the lto_codegen_debug_options* function. | |||||
steven_wu: Shouldn't this be:
```
if (optionParsingState == OptParsingState::NotParsed)
unwrap(cg)… | |||||
I considered that... the only disadvantage with guarding unwrap(cg)->parseCodeGenDebugOptions(); is that now it's not going to run when early option parsing occurs and we would need an additional function in LTOCodeGenerator to contain code that we want to execute after debug option parsing has occurred. For example the code to register save-temps (that D98183 is planning to add). Other than that I think your suggestion is abit more intuitive when reading the code. w2yehia: I considered that... the only disadvantage with guarding `unwrap(cg)->parseCodeGenDebugOptions… | |||||
Not Done ReplyInline ActionsD98183 is really a debug option which is not used for production and it doesn't matter when you parse that option. Actually thinking about this again, maybe keep this as it was if the command line can just be parsed twice. The way you implement it makes two options exclusive. If you use your parsing function, lto_add_attrs cannot be reached so you lost some codegen options. steven_wu: D98183 is really a debug option which is not used for production and it doesn't matter when you… | |||||
unwrap(cg)->parseCodeGenDebugOptions(); | unwrap(cg)->parseCodeGenDebugOptions(); | ||||
lto_add_attrs(cg); | lto_add_attrs(cg); | ||||
parsedOptions = true; | optionParsingState = OptParsingState::Done; | ||||
} | } | ||||
} | } | ||||
bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) { | bool lto_codegen_write_merged_modules(lto_code_gen_t cg, const char *path) { | ||||
maybeParseOptions(cg); | maybeParseOptions(cg); | ||||
return !unwrap(cg)->writeMergedModules(path); | return !unwrap(cg)->writeMergedModules(path); | ||||
} | } | ||||
Show All 22 Lines | const void *lto_codegen_compile_optimized(lto_code_gen_t cg, size_t *length) { | ||||
return CG->NativeObjectFile->getBufferStart(); | return CG->NativeObjectFile->getBufferStart(); | ||||
} | } | ||||
bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) { | bool lto_codegen_compile_to_file(lto_code_gen_t cg, const char **name) { | ||||
maybeParseOptions(cg); | maybeParseOptions(cg); | ||||
return !unwrap(cg)->compile_to_file(name); | return !unwrap(cg)->compile_to_file(name); | ||||
} | } | ||||
void lto_set_debug_options(const char *const *options, int number) { | |||||
Not Done ReplyInline ActionsIf you have to pick an interface, use the new _array interface. This is also not correct since you skipped lto_add_attrs function when you called your version. steven_wu: If you have to pick an interface, use the new `_array` interface.
This is also not correct… | |||||
I might be missing something. I think some function and variable names could be improved to reflect their intended purpose. w2yehia: > This is also not correct since you skipped lto_add_attrs function when you called your… | |||||
assert(optionParsingState == OptParsingState::NotParsed && | |||||
"option processing already happened"); | |||||
// Need to put each suboption in a null-terminated string before passing to | |||||
// parseCommandLineOptions(). | |||||
std::vector<std::string> Options; | |||||
for (int i = 0; i < number; ++i) | |||||
Options.push_back(options[i]); | |||||
llvm::parseCommandLineOptions(Options); | |||||
optionParsingState = OptParsingState::Early; | |||||
} | |||||
void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) { | void lto_codegen_debug_options(lto_code_gen_t cg, const char *opt) { | ||||
assert(optionParsingState != OptParsingState::Early && | |||||
"early option processing already happened"); | |||||
SmallVector<StringRef, 4> Options; | SmallVector<StringRef, 4> Options; | ||||
for (std::pair<StringRef, StringRef> o = getToken(opt); !o.first.empty(); | for (std::pair<StringRef, StringRef> o = getToken(opt); !o.first.empty(); | ||||
o = getToken(o.second)) | o = getToken(o.second)) | ||||
Options.push_back(o.first); | Options.push_back(o.first); | ||||
unwrap(cg)->setCodeGenDebugOptions(Options); | unwrap(cg)->setCodeGenDebugOptions(Options); | ||||
} | } | ||||
void lto_codegen_debug_options_array(lto_code_gen_t cg, | void lto_codegen_debug_options_array(lto_code_gen_t cg, | ||||
const char *const *options, int number) { | const char *const *options, int number) { | ||||
assert(optionParsingState != OptParsingState::Early && | |||||
"early option processing already happened"); | |||||
SmallVector<StringRef, 4> Options; | SmallVector<StringRef, 4> Options; | ||||
for (int i = 0; i < number; ++i) | for (int i = 0; i < number; ++i) | ||||
Options.push_back(options[i]); | Options.push_back(options[i]); | ||||
unwrap(cg)->setCodeGenDebugOptions(makeArrayRef(Options)); | unwrap(cg)->setCodeGenDebugOptions(makeArrayRef(Options)); | ||||
} | } | ||||
unsigned int lto_api_version() { return LTO_API_VERSION; } | unsigned int lto_api_version() { return LTO_API_VERSION; } | ||||
▲ Show 20 Lines • Show All 200 Lines • Show Last 20 Lines |
Shouldn't this be: