Index: src/llvm2ice.cpp |
diff --git a/src/llvm2ice.cpp b/src/llvm2ice.cpp |
index c3a98dfed6b2d13a06f6dbeeb054d700990864ab..523b6d3f8b58fa2b5c75bac8c8e63cd9dcd1b2eb 100644 |
--- a/src/llvm2ice.cpp |
+++ b/src/llvm2ice.cpp |
@@ -726,6 +726,48 @@ int main(int argc, char **argv) { |
raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); |
Ls->SetUnbuffered(); |
+ Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix); |
+ |
+ OwningPtr<Ice::TargetGlobalInitLowering> GlobalLowering( |
+ Ice::TargetGlobalInitLowering::createLowering(TargetArch, &Ctx)); |
+ for (Module::const_global_iterator I = Mod->global_begin(), |
+ E = Mod->global_end(); |
+ I != E; ++I) { |
+ if (!I->hasInitializer()) |
+ continue; |
+ const Constant *Initializer = I->getInitializer(); |
+ Ice::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, DisableTranslation); |
+ } |
+ GlobalLowering.reset(); |
+ |
// Ideally, Func would be declared inside the loop and its object |
// would be automatically deleted at the end of the loop iteration. |
// However, emitting the constant pool requires a valid Cfg object, |
@@ -735,7 +777,6 @@ int main(int argc, char **argv) { |
// object, change all Ice::Constant related functions to use |
// GlobalContext instead of Cfg, and then clean up this loop. |
OwningPtr<Ice::Cfg> Func; |
- Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix); |
for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { |
if (I->empty()) |