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

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: First-round updates 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 OwningPtr<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 IsInternal = I->hasInternalLinkage();
744 bool IsConst = I->isConstant();
745 bool IsZeroInitializer = false;
746
747 if (const ConstantDataArray *CDA =
748 dyn_cast<ConstantDataArray>(Initializer)) {
749 NumElements = CDA->getNumElements();
750 assert(isa<IntegerType>(CDA->getElementType()) &&
751 cast<IntegerType>(CDA->getElementType())->getBitWidth() == 8);
752 Data = CDA->getRawDataValues().data();
753 } else if (isa<ConstantAggregateZero>(Initializer)) {
754 if (const ArrayType *AT = dyn_cast<ArrayType>(Initializer->getType())) {
755 assert(isa<IntegerType>(AT->getElementType()) &&
756 cast<IntegerType>(AT->getElementType())->getBitWidth() == 8);
757 NumElements = AT->getNumElements();
758 IsZeroInitializer = true;
759 } else {
760 llvm_unreachable("Unhandled constant aggregate zero type");
761 }
762 } else {
763 llvm_unreachable("Unhandled global initializer");
764 }
765
766 GlobalLowering->lower(Name, Align, IsInternal, IsConst, IsZeroInitializer,
767 NumElements, Data, DisableTranslation);
768 }
769 GlobalLowering.reset();
770
729 // Ideally, Func would be declared inside the loop and its object 771 // Ideally, Func would be declared inside the loop and its object
730 // would be automatically deleted at the end of the loop iteration. 772 // would be automatically deleted at the end of the loop iteration.
731 // However, emitting the constant pool requires a valid Cfg object, 773 // However, emitting the constant pool requires a valid Cfg object,
732 // so we need to defer deleting the last non-empty Cfg object until 774 // so we need to defer deleting the last non-empty Cfg object until
733 // outside the loop and after emitting the constant pool. TODO: 775 // outside the loop and after emitting the constant pool. TODO:
734 // Since all constants are globally pooled in the Ice::GlobalContext 776 // Since all constants are globally pooled in the Ice::GlobalContext
735 // object, change all Ice::Constant related functions to use 777 // object, change all Ice::Constant related functions to use
736 // GlobalContext instead of Cfg, and then clean up this loop. 778 // GlobalContext instead of Cfg, and then clean up this loop.
737 OwningPtr<Ice::Cfg> Func; 779 OwningPtr<Ice::Cfg> Func;
738 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix);
739 780
740 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) { 781 for (Module::const_iterator I = Mod->begin(), E = Mod->end(); I != E; ++I) {
741 if (I->empty()) 782 if (I->empty())
742 continue; 783 continue;
743 LLVM2ICEConverter FunctionConverter(&Ctx); 784 LLVM2ICEConverter FunctionConverter(&Ctx);
744 785
745 Ice::Timer TConvert; 786 Ice::Timer TConvert;
746 Func.reset(FunctionConverter.convertFunction(I)); 787 Func.reset(FunctionConverter.convertFunction(I));
747 if (DisableInternal) 788 if (DisableInternal)
748 Func->setInternal(false); 789 Func->setInternal(false);
(...skipping 27 matching lines...) Expand all
776 << " sec\n"; 817 << " sec\n";
777 } 818 }
778 } 819 }
779 } 820 }
780 821
781 if (!DisableTranslation && Func) 822 if (!DisableTranslation && Func)
782 Func->getTarget()->emitConstants(); 823 Func->getTarget()->emitConstants();
783 824
784 return ExitStatus; 825 return ExitStatus;
785 } 826 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698