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

Side by Side Diff: src/IceConverter.cpp

Issue 587893003: Test generation of global initializers in Subzero bitcode reader. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nit Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « src/IceConverter.h ('k') | src/IceTranslator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceConverter.cpp - Converts LLVM to Ice ---------------===// 1 //===- subzero/src/IceConverter.cpp - Converts LLVM to Ice ---------------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file implements the LLVM to ICE converter. 10 // This file implements the LLVM to ICE converter.
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 Ice::TypeConverter TypeConverter; 620 Ice::TypeConverter TypeConverter;
621 }; 621 };
622 622
623 } // end of anonymous namespace 623 } // end of anonymous namespace
624 624
625 namespace Ice { 625 namespace Ice {
626 626
627 void Converter::convertToIce() { 627 void Converter::convertToIce() {
628 nameUnnamedGlobalAddresses(Mod); 628 nameUnnamedGlobalAddresses(Mod);
629 if (!Ctx->getFlags().DisableGlobals) 629 if (!Ctx->getFlags().DisableGlobals)
630 convertGlobals(); 630 convertGlobals(Mod);
631 convertFunctions(); 631 convertFunctions();
632 } 632 }
633 633
634 void Converter::convertGlobals() {
635 OwningPtr<TargetGlobalInitLowering> GlobalLowering(
636 TargetGlobalInitLowering::createLowering(Ctx->getTargetArch(), Ctx));
637 for (Module::const_global_iterator I = Mod->global_begin(),
638 E = Mod->global_end();
639 I != E; ++I) {
640 if (!I->hasInitializer())
641 continue;
642 const llvm::Constant *Initializer = I->getInitializer();
643 IceString Name = I->getName();
644 unsigned Align = I->getAlignment();
645 uint64_t NumElements = 0;
646 const char *Data = NULL;
647 bool IsInternal = I->hasInternalLinkage();
648 bool IsConst = I->isConstant();
649 bool IsZeroInitializer = false;
650
651 if (const ConstantDataArray *CDA =
652 dyn_cast<ConstantDataArray>(Initializer)) {
653 NumElements = CDA->getNumElements();
654 assert(isa<IntegerType>(CDA->getElementType()) &&
655 cast<IntegerType>(CDA->getElementType())->getBitWidth() == 8);
656 Data = CDA->getRawDataValues().data();
657 } else if (isa<ConstantAggregateZero>(Initializer)) {
658 if (const ArrayType *AT = dyn_cast<ArrayType>(Initializer->getType())) {
659 assert(isa<IntegerType>(AT->getElementType()) &&
660 cast<IntegerType>(AT->getElementType())->getBitWidth() == 8);
661 NumElements = AT->getNumElements();
662 IsZeroInitializer = true;
663 } else {
664 llvm_unreachable("Unhandled constant aggregate zero type");
665 }
666 } else {
667 llvm_unreachable("Unhandled global initializer");
668 }
669
670 GlobalLowering->lower(Name, Align, IsInternal, IsConst, IsZeroInitializer,
671 NumElements, Data,
672 Ctx->getFlags().DisableTranslation);
673 }
674 GlobalLowering.reset();
675 }
676
677 void Converter::convertFunctions() { 634 void Converter::convertFunctions() {
678 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { 635 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
679 if (I->empty()) 636 if (I->empty())
680 continue; 637 continue;
681 LLVM2ICEConverter FunctionConverter(Ctx, Mod->getContext()); 638 LLVM2ICEConverter FunctionConverter(Ctx, Mod->getContext());
682 639
683 Timer TConvert; 640 Timer TConvert;
684 Cfg *Fcn = FunctionConverter.convertFunction(I); 641 Cfg *Fcn = FunctionConverter.convertFunction(I);
685 if (Ctx->getFlags().SubzeroTimingEnabled) { 642 if (Ctx->getFlags().SubzeroTimingEnabled) {
686 std::cerr << "[Subzero timing] Convert function " 643 std::cerr << "[Subzero timing] Convert function "
687 << Fcn->getFunctionName() << ": " << TConvert.getElapsedSec() 644 << Fcn->getFunctionName() << ": " << TConvert.getElapsedSec()
688 << " sec\n"; 645 << " sec\n";
689 } 646 }
690 translateFcn(Fcn); 647 translateFcn(Fcn);
691 } 648 }
692 649
693 emitConstants(); 650 emitConstants();
694 } 651 }
695 652
696 } // end of namespace Ice 653 } // end of namespace Ice
OLDNEW
« 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