Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: src/IceConverter.cpp

Issue 387023002: Clean up exit status and globals procecessing in llvm2ice. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Change ExitStatus to ErrorStatus. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/IceConverter.h ('k') | src/IceTranslator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/IceConverter.cpp
diff --git a/src/IceConverter.cpp b/src/IceConverter.cpp
index 5a85034d2d34ef8bcabe4681f87d0d26cc8582ad..9ba1feace934e981195aac70b58e6a095eda2162 100644
--- a/src/IceConverter.cpp
+++ b/src/IceConverter.cpp
@@ -20,6 +20,7 @@
#include "IceGlobalContext.h"
#include "IceInst.h"
#include "IceOperand.h"
+#include "IceTargetLowering.h"
#include "IceTypes.h"
#include "llvm/IR/Constant.h"
@@ -657,14 +658,63 @@ private:
} // end of anonymous namespace.
-int Ice::Converter::convertToIce(llvm::Module *Mod) {
+namespace Ice {
+
+void Converter::convertToIce(Module *Mod) {
+ convertGlobals(Mod);
+ convertFunctions(Mod);
+}
+
+void Converter::convertGlobals(Module *Mod) {
+ OwningPtr<TargetGlobalInitLowering> GlobalLowering(
+ TargetGlobalInitLowering::createLowering(Ctx->getTargetArch(), Ctx));
+ for (Module::const_global_iterator I = Mod->global_begin(),
+ E = Mod->global_end();
+ I != E; ++I) {
+ if (!I->hasInitializer())
+ continue;
+ const llvm::Constant *Initializer = I->getInitializer();
+ IceString Name = I->getName();
+ unsigned Align = I->getAlignment();
+ uint64_t NumElements = 0;
+ const char *Data = NULL;
+ bool IsInternal = I->hasInternalLinkage();
+ bool IsConst = I->isConstant();
+ bool IsZeroInitializer = false;
+
+ if (const ConstantDataArray *CDA =
+ dyn_cast<ConstantDataArray>(Initializer)) {
+ NumElements = CDA->getNumElements();
+ assert(isa<IntegerType>(CDA->getElementType()) &&
+ cast<IntegerType>(CDA->getElementType())->getBitWidth() == 8);
+ Data = CDA->getRawDataValues().data();
+ } else if (isa<ConstantAggregateZero>(Initializer)) {
+ if (const ArrayType *AT = dyn_cast<ArrayType>(Initializer->getType())) {
+ assert(isa<IntegerType>(AT->getElementType()) &&
+ cast<IntegerType>(AT->getElementType())->getBitWidth() == 8);
+ NumElements = AT->getNumElements();
+ IsZeroInitializer = true;
+ } else {
+ llvm_unreachable("Unhandled constant aggregate zero type");
+ }
+ } else {
+ llvm_unreachable("Unhandled global initializer");
+ }
+
+ GlobalLowering->lower(Name, Align, IsInternal, IsConst, IsZeroInitializer,
+ NumElements, Data, Flags.DisableTranslation);
+ }
+ GlobalLowering.reset();
+}
+
+void Converter::convertFunctions(Module *Mod) {
for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
if (I->empty())
continue;
LLVM2ICEConverter FunctionConverter(Ctx);
- Ice::Timer TConvert;
- Ice::Cfg *Fcn = FunctionConverter.convertFunction(I);
+ Timer TConvert;
+ Cfg *Fcn = FunctionConverter.convertFunction(I);
if (Flags.SubzeroTimingEnabled) {
std::cerr << "[Subzero timing] Convert function "
<< Fcn->getFunctionName() << ": " << TConvert.getElapsedSec()
@@ -674,5 +724,6 @@ int Ice::Converter::convertToIce(llvm::Module *Mod) {
}
emitConstants();
- return ExitStatus;
}
+
+} // end of Ice namespace.
« no previous file with comments | « src/IceConverter.h ('k') | src/IceTranslator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698