OLD | NEW |
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 /// \file | 10 /// \file |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 GlobalPool->push_back(VarDecl); | 715 GlobalPool->push_back(VarDecl); |
716 | 716 |
717 if (!GV->hasInternalLinkage() && GV->hasInitializer()) { | 717 if (!GV->hasInternalLinkage() && GV->hasInitializer()) { |
718 std::string Buffer; | 718 std::string Buffer; |
719 raw_string_ostream StrBuf(Buffer); | 719 raw_string_ostream StrBuf(Buffer); |
720 StrBuf << "Can't define external global declaration: " << GV->getName(); | 720 StrBuf << "Can't define external global declaration: " << GV->getName(); |
721 report_fatal_error(StrBuf.str()); | 721 report_fatal_error(StrBuf.str()); |
722 } | 722 } |
723 | 723 |
724 if (!GV->hasInitializer()) { | 724 if (!GV->hasInitializer()) { |
725 if (Ctx->getFlags().getAllowUninitializedGlobals()) | 725 if (Ice::getFlags().getAllowUninitializedGlobals()) |
726 continue; | 726 continue; |
727 else { | 727 else { |
728 std::string Buffer; | 728 std::string Buffer; |
729 raw_string_ostream StrBuf(Buffer); | 729 raw_string_ostream StrBuf(Buffer); |
730 StrBuf << "Global declaration missing initializer: " << GV->getName(); | 730 StrBuf << "Global declaration missing initializer: " << GV->getName(); |
731 report_fatal_error(StrBuf.str()); | 731 report_fatal_error(StrBuf.str()); |
732 } | 732 } |
733 } | 733 } |
734 | 734 |
735 const Constant *Initializer = GV->getInitializer(); | 735 const Constant *Initializer = GV->getInitializer(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 raw_string_ostream StrBuf(Buffer); | 800 raw_string_ostream StrBuf(Buffer); |
801 StrBuf << "Unhandled global initializer: " << Initializer; | 801 StrBuf << "Unhandled global initializer: " << Initializer; |
802 report_fatal_error(StrBuf.str()); | 802 report_fatal_error(StrBuf.str()); |
803 } | 803 } |
804 | 804 |
805 } // end of anonymous namespace | 805 } // end of anonymous namespace |
806 | 806 |
807 namespace Ice { | 807 namespace Ice { |
808 | 808 |
809 void Converter::nameUnnamedGlobalVariables(Module *Mod) { | 809 void Converter::nameUnnamedGlobalVariables(Module *Mod) { |
810 const std::string GlobalPrefix = Ctx->getFlags().getDefaultGlobalPrefix(); | 810 const std::string GlobalPrefix = getFlags().getDefaultGlobalPrefix(); |
811 if (GlobalPrefix.empty()) | 811 if (GlobalPrefix.empty()) |
812 return; | 812 return; |
813 uint32_t NameIndex = 0; | 813 uint32_t NameIndex = 0; |
814 for (auto V = Mod->global_begin(), E = Mod->global_end(); V != E; ++V) { | 814 for (auto V = Mod->global_begin(), E = Mod->global_end(); V != E; ++V) { |
815 if (!V->hasName()) { | 815 if (!V->hasName()) { |
816 V->setName(createUnnamedName(GlobalPrefix, NameIndex)); | 816 V->setName(createUnnamedName(GlobalPrefix, NameIndex)); |
817 ++NameIndex; | 817 ++NameIndex; |
818 } else { | 818 } else { |
819 checkIfUnnamedNameSafe(V->getName(), "global", GlobalPrefix); | 819 checkIfUnnamedNameSafe(V->getName(), "global", GlobalPrefix); |
820 } | 820 } |
821 } | 821 } |
822 } | 822 } |
823 | 823 |
824 void Converter::nameUnnamedFunctions(Module *Mod) { | 824 void Converter::nameUnnamedFunctions(Module *Mod) { |
825 const std::string FunctionPrefix = Ctx->getFlags().getDefaultFunctionPrefix(); | 825 const std::string FunctionPrefix = getFlags().getDefaultFunctionPrefix(); |
826 if (FunctionPrefix.empty()) | 826 if (FunctionPrefix.empty()) |
827 return; | 827 return; |
828 uint32_t NameIndex = 0; | 828 uint32_t NameIndex = 0; |
829 for (Function &F : *Mod) { | 829 for (Function &F : *Mod) { |
830 if (!F.hasName()) { | 830 if (!F.hasName()) { |
831 F.setName(createUnnamedName(FunctionPrefix, NameIndex)); | 831 F.setName(createUnnamedName(FunctionPrefix, NameIndex)); |
832 ++NameIndex; | 832 ++NameIndex; |
833 } else { | 833 } else { |
834 checkIfUnnamedNameSafe(F.getName(), "function", FunctionPrefix); | 834 checkIfUnnamedNameSafe(F.getName(), "function", FunctionPrefix); |
835 } | 835 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
888 for (Module::const_global_iterator I = Mod->global_begin(), | 888 for (Module::const_global_iterator I = Mod->global_begin(), |
889 E = Mod->global_end(); | 889 E = Mod->global_end(); |
890 I != E; ++I) { | 890 I != E; ++I) { |
891 const GlobalVariable *GV = I; | 891 const GlobalVariable *GV = I; |
892 constexpr bool NoSuppressMangling = false; | 892 constexpr bool NoSuppressMangling = false; |
893 auto *Var = VariableDeclaration::create( | 893 auto *Var = VariableDeclaration::create( |
894 GlobalDeclarationsPool.get(), NoSuppressMangling, GV->getLinkage()); | 894 GlobalDeclarationsPool.get(), NoSuppressMangling, GV->getLinkage()); |
895 Var->setAlignment(GV->getAlignment()); | 895 Var->setAlignment(GV->getAlignment()); |
896 Var->setIsConstant(GV->isConstant()); | 896 Var->setIsConstant(GV->isConstant()); |
897 Var->setName(Ctx, GV->getName()); | 897 Var->setName(Ctx, GV->getName()); |
898 if (!Var->verifyLinkageCorrect(Ctx)) { | 898 if (!Var->verifyLinkageCorrect()) { |
899 std::string Buffer; | 899 std::string Buffer; |
900 raw_string_ostream StrBuf(Buffer); | 900 raw_string_ostream StrBuf(Buffer); |
901 StrBuf << "Global " << Var->getName() | 901 StrBuf << "Global " << Var->getName() |
902 << " has incorrect linkage: " << Var->getLinkageName(); | 902 << " has incorrect linkage: " << Var->getLinkageName(); |
903 if (Var->isExternal()) | 903 if (Var->isExternal()) |
904 StrBuf << "\n Use flag -allow-externally-defined-symbols to override"; | 904 StrBuf << "\n Use flag -allow-externally-defined-symbols to override"; |
905 report_fatal_error(StrBuf.str()); | 905 report_fatal_error(StrBuf.str()); |
906 } | 906 } |
907 GlobalDeclarationMap[GV] = Var; | 907 GlobalDeclarationMap[GV] = Var; |
908 } | 908 } |
909 } | 909 } |
910 | 910 |
911 void Converter::convertGlobals(Module *Mod) { | 911 void Converter::convertGlobals(Module *Mod) { |
912 LLVM2ICEGlobalsConverter(*this, GlobalDeclarationsPool.get()) | 912 LLVM2ICEGlobalsConverter(*this, GlobalDeclarationsPool.get()) |
913 .convertGlobalsToIce(Mod); | 913 .convertGlobalsToIce(Mod); |
914 lowerGlobals(std::move(GlobalDeclarationsPool)); | 914 lowerGlobals(std::move(GlobalDeclarationsPool)); |
915 } | 915 } |
916 | 916 |
917 void Converter::convertFunctions() { | 917 void Converter::convertFunctions() { |
918 for (const Function &I : *Mod) { | 918 for (const Function &I : *Mod) { |
919 if (I.empty()) | 919 if (I.empty()) |
920 continue; | 920 continue; |
921 TimerMarker _(Ctx, I.getName()); | 921 TimerMarker _(Ctx, I.getName()); |
922 LLVM2ICEFunctionConverter FunctionConverter(*this); | 922 LLVM2ICEFunctionConverter FunctionConverter(*this); |
923 FunctionConverter.convertFunction(&I); | 923 FunctionConverter.convertFunction(&I); |
924 } | 924 } |
925 } | 925 } |
926 | 926 |
927 } // end of namespace Ice | 927 } // end of namespace Ice |
OLD | NEW |