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

Side by Side Diff: src/llvm2ice.cpp

Issue 358013003: Subzero: Partial implementation of global initializers. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: 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 unified diff | Download patch
OLDNEW
1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===// 1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===//
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 defines a driver that uses LLVM capabilities to parse a 10 // This file defines a driver that uses LLVM capabilities to parse a
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 raw_os_ostream *Os = 719 raw_os_ostream *Os =
720 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs); 720 new raw_os_ostream(OutputFilename == "-" ? std::cout : Ofs);
721 Os->SetUnbuffered(); 721 Os->SetUnbuffered();
722 std::ofstream Lfs; 722 std::ofstream Lfs;
723 if (LogFilename != "-") { 723 if (LogFilename != "-") {
724 Lfs.open(LogFilename.c_str(), std::ofstream::out); 724 Lfs.open(LogFilename.c_str(), std::ofstream::out);
725 } 725 }
726 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); 726 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs);
727 Ls->SetUnbuffered(); 727 Ls->SetUnbuffered();
728 728
729 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix);
730
731 Ice::TargetGlobalInitLowering *GlobalLowering =
732 Ice::TargetGlobalInitLowering::createLowering(TargetArch, &Ctx);
733 for (Module::const_global_iterator I = Mod->global_begin(),
734 E = Mod->global_end();
735 I != E; ++I) {
736 if (!I->hasInitializer())
737 continue;
738 const Constant *Initializer = I->getInitializer();
739 Ice::IceString Name = I->getName();
740 unsigned Align = I->getAlignment();
741 uint64_t NumElements = 0;
742 const char *Data = NULL;
743 bool DeleteData = false;
744 bool IsInternal = I->hasInternalLinkage();
745 bool IsConst = I->isConstant();
746 bool IsZeroInitializer = false;
747
748 if (const ConstantDataArray *CDA =
749 dyn_cast<ConstantDataArray>(Initializer)) {
750 NumElements = CDA->getNumElements();
751 assert(isa<IntegerType>(CDA->getElementType()) &&
752 cast<IntegerType>(CDA->getElementType())->getBitWidth() == 8);
753 Data = CDA->getRawDataValues().data();
754 } else if (isa<ConstantAggregateZero>(Initializer)) {
755 if (const ArrayType *AT = dyn_cast<ArrayType>(Initializer->getType())) {
756 assert(isa<IntegerType>(AT->getElementType()) &&
757 cast<IntegerType>(AT->getElementType())->getBitWidth() == 8);
758 NumElements = AT->getNumElements();
759 char *MyData = new char[NumElements];
760 memset(MyData, 0, NumElements);
761 Data = MyData;
762 DeleteData = true;
763 IsZeroInitializer = true;
764 } else {
765 llvm_unreachable("Unhandled constant aggregate zero type");
766 }
767 } else {
768 llvm_unreachable("Unhandled global initializer");
769 }
770
771 GlobalLowering->lower(Name, Align, IsInternal, IsConst, IsZeroInitializer,
772 NumElements, Data, DisableTranslation);
773 if (DeleteData)
774 delete Data;
775 }
776 delete GlobalLowering;
777
729 // Ideally, Func would be declared inside the loop and its object 778 // Ideally, Func would be declared inside the loop and its object
730 // would be automatically deleted at the end of the loop iteration. 779 // would be automatically deleted at the end of the loop iteration.
731 // However, emitting the constant pool requires a valid Cfg object, 780 // However, emitting the constant pool requires a valid Cfg object,
732 // so we need to defer deleting the last non-empty Cfg object until 781 // so we need to defer deleting the last non-empty Cfg object until
733 // outside the loop and after emitting the constant pool. TODO: 782 // outside the loop and after emitting the constant pool. TODO:
734 // Since all constants are globally pooled in the Ice::GlobalContext 783 // Since all constants are globally pooled in the Ice::GlobalContext
735 // object, change all Ice::Constant related functions to use 784 // object, change all Ice::Constant related functions to use
736 // GlobalContext instead of Cfg, and then clean up this loop. 785 // GlobalContext instead of Cfg, and then clean up this loop.
737 OwningPtr<Ice::Cfg> Func; 786 OwningPtr<Ice::Cfg> Func;
738 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix);
739 787
740 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { 788 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
741 if (I->empty()) 789 if (I->empty())
742 continue; 790 continue;
743 LLVM2ICEConverter FunctionConverter(&Ctx); 791 LLVM2ICEConverter FunctionConverter(&Ctx);
744 792
745 Ice::Timer TConvert; 793 Ice::Timer TConvert;
746 Func.reset(FunctionConverter.convertFunction(I)); 794 Func.reset(FunctionConverter.convertFunction(I));
747 if (DisableInternal) 795 if (DisableInternal)
748 Func->setInternal(false); 796 Func->setInternal(false);
(...skipping 27 matching lines...) Expand all
776 << " sec\n"; 824 << " sec\n";
777 } 825 }
778 } 826 }
779 } 827 }
780 828
781 if (!DisableTranslation && Func) 829 if (!DisableTranslation && Func)
782 Func->getTarget()->emitConstants(); 830 Func->getTarget()->emitConstants();
783 831
784 return ExitStatus; 832 return ExitStatus;
785 } 833 }
OLDNEW
« no previous file with comments | « src/IceTargetLoweringX8632.cpp ('k') | szdiff.py » ('j') | szdiff.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698