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. |