Subzero: Emit functions and global initializers in a separate thread.
(This is a continuation of https://codereview.chromium.org/876083007/ .)
Emission is done in a separate thread when -threads=N with N>0 is specified. This includes both functions and global initializers.
Emission is deterministic. The parser assigns sequence numbers, and the emitter thread reassembles work units into their original order, regardless of the number of threads.
Dump output, however, is not intended to be in deterministic, reassembled order. As such, lit tests that test dump output (i.e., '-verbose inst') are explicitly run with -threads=0.
For -elf-writer and -ias=1, the translator thread invokes Cfg::emitIAS() and the assembler buffer is passed to the emitter thread. For -ias=0, the translator thread passed the Cfg to the emitter thread which then invokes Cfg::emit() to produce the textual asm.
Minor cleanup along the way:
* Removed Flags from the Ice::Translator object and ctor, since it was redundant with Ctx->getFlags().
* Cfg::getAssembler<> is the same as Cfg::getAssembler<Assembler> and is useful for just passing the assembler around.
* Removed the redundant Ctx argument from TargetDataLowering::lowerConstants() .
BUG= https://code.google.com/p/nativeclient/issues/detail?id=4075
R=jvoung@chromium.org
Review URL: https://codereview.chromium.org/916653004
diff --git a/src/IceConverter.cpp b/src/IceConverter.cpp
index 7cc8d5a..cc523fa 100644
--- a/src/IceConverter.cpp
+++ b/src/IceConverter.cpp
@@ -84,7 +84,9 @@
: LLVM2ICEConverter(Converter), Func(nullptr) {}
void convertFunction(const Function *F) {
- Func = Ice::Cfg::create(Ctx);
+ if (Ctx->isIRGenerationDisabled())
+ return;
+ Func = Ice::Cfg::create(Ctx, Converter.getNextSequenceNumber());
Ice::Cfg::setCurrentCfg(Func.get());
VarMap.clear();
@@ -658,10 +660,10 @@
: LLVM2ICEConverter(Converter) {}
/// Converts global variables, and their initializers into ICE
- /// global variable declarations, for module Mod. Puts corresponding
- /// converted declarations into VariableDeclarations.
- void convertGlobalsToIce(Module *Mod,
- Ice::VariableDeclarationList &VariableDeclarations);
+ /// global variable declarations, for module Mod. Returns the set of
+ /// converted declarations.
+ std::unique_ptr<Ice::VariableDeclarationList>
+ convertGlobalsToIce(Module *Mod);
private:
// Adds the Initializer to the list of initializers for the Global
@@ -696,8 +698,10 @@
}
};
-void LLVM2ICEGlobalsConverter::convertGlobalsToIce(
- Module *Mod, Ice::VariableDeclarationList &VariableDeclarations) {
+std::unique_ptr<Ice::VariableDeclarationList>
+LLVM2ICEGlobalsConverter::convertGlobalsToIce(Module *Mod) {
+ std::unique_ptr<Ice::VariableDeclarationList> VariableDeclarations(
+ new Ice::VariableDeclarationList);
for (Module::const_global_iterator I = Mod->global_begin(),
E = Mod->global_end();
I != E; ++I) {
@@ -706,7 +710,7 @@
Ice::GlobalDeclaration *Var = getConverter().getGlobalDeclaration(GV);
Ice::VariableDeclaration *VarDecl = cast<Ice::VariableDeclaration>(Var);
- VariableDeclarations.push_back(VarDecl);
+ VariableDeclarations->push_back(VarDecl);
if (!GV->hasInternalLinkage() && GV->hasInitializer()) {
std::string Buffer;
@@ -739,6 +743,7 @@
addGlobalInitializer(*VarDecl, Initializer);
}
}
+ return std::move(VariableDeclarations);
}
void LLVM2ICEGlobalsConverter::addGlobalInitializer(
@@ -801,7 +806,7 @@
namespace Ice {
void Converter::nameUnnamedGlobalVariables(Module *Mod) {
- const IceString &GlobalPrefix = Flags.getDefaultGlobalPrefix();
+ const IceString &GlobalPrefix = Ctx->getFlags().getDefaultGlobalPrefix();
if (GlobalPrefix.empty())
return;
uint32_t NameIndex = 0;
@@ -816,7 +821,7 @@
}
void Converter::nameUnnamedFunctions(Module *Mod) {
- const IceString &FunctionPrefix = Flags.getDefaultFunctionPrefix();
+ const IceString &FunctionPrefix = Ctx->getFlags().getDefaultFunctionPrefix();
if (FunctionPrefix.empty())
return;
uint32_t NameIndex = 0;
@@ -882,10 +887,7 @@
}
void Converter::convertGlobals(Module *Mod) {
- LLVM2ICEGlobalsConverter GlobalsConverter(*this);
- VariableDeclarationList VariableDeclarations;
- GlobalsConverter.convertGlobalsToIce(Mod, VariableDeclarations);
- lowerGlobals(VariableDeclarations);
+ lowerGlobals(LLVM2ICEGlobalsConverter(*this).convertGlobalsToIce(Mod));
}
void Converter::convertFunctions() {