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

Side by Side Diff: src/IceConverter.cpp

Issue 1838753002: Subzero: Remove IceString. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review changes Created 4 years, 8 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/IceCompiler.cpp ('k') | src/IceDefs.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 /// \file 10 /// \file
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 explicit LLVM2ICEFunctionConverter(Ice::Converter &Converter) 95 explicit LLVM2ICEFunctionConverter(Ice::Converter &Converter)
96 : LLVM2ICEConverter(Converter), Func(nullptr) {} 96 : LLVM2ICEConverter(Converter), Func(nullptr) {}
97 97
98 void convertFunction(const Function *F) { 98 void convertFunction(const Function *F) {
99 Func = Ice::Cfg::create(Ctx, Converter.getNextSequenceNumber()); 99 Func = Ice::Cfg::create(Ctx, Converter.getNextSequenceNumber());
100 { 100 {
101 Ice::CfgLocalAllocatorScope _(Func.get()); 101 Ice::CfgLocalAllocatorScope _(Func.get());
102 102
103 VarMap.clear(); 103 VarMap.clear();
104 NodeMap.clear(); 104 NodeMap.clear();
105 Func->setFunctionName(Ice::mangleName(F->getName())); 105 Func->setFunctionName(
106 Ctx->getGlobalString(Ice::mangleName(F->getName())));
106 Func->setReturnType(convertToIceType(F->getReturnType())); 107 Func->setReturnType(convertToIceType(F->getReturnType()));
107 Func->setInternal(F->hasInternalLinkage()); 108 Func->setInternal(F->hasInternalLinkage());
108 Ice::TimerMarker T(Ice::TimerStack::TT_llvmConvert, Func.get()); 109 Ice::TimerMarker T(Ice::TimerStack::TT_llvmConvert, Func.get());
109 110
110 // The initial definition/use of each arg is the entry node. 111 // The initial definition/use of each arg is the entry node.
111 for (auto ArgI = F->arg_begin(), ArgE = F->arg_end(); ArgI != ArgE; 112 for (auto ArgI = F->arg_begin(), ArgE = F->arg_end(); ArgI != ArgE;
112 ++ArgI) { 113 ++ArgI) {
113 Func->addArg(mapValueToIceVar(ArgI)); 114 Func->addArg(mapValueToIceVar(ArgI));
114 } 115 }
115 116
(...skipping 19 matching lines...) Expand all
135 if (const auto *Func = llvm::dyn_cast<Ice::FunctionDeclaration>(Decl)) 136 if (const auto *Func = llvm::dyn_cast<Ice::FunctionDeclaration>(Decl))
136 IsUndefined = Func->isProto(); 137 IsUndefined = Func->isProto();
137 else if (const auto *Var = llvm::dyn_cast<Ice::VariableDeclaration>(Decl)) 138 else if (const auto *Var = llvm::dyn_cast<Ice::VariableDeclaration>(Decl))
138 IsUndefined = !Var->hasInitializer(); 139 IsUndefined = !Var->hasInitializer();
139 else 140 else
140 report_fatal_error("Unhandled GlobalDeclaration type"); 141 report_fatal_error("Unhandled GlobalDeclaration type");
141 if (IsUndefined) 142 if (IsUndefined)
142 return Ctx->getConstantExternSym(Decl->getName()); 143 return Ctx->getConstantExternSym(Decl->getName());
143 else { 144 else {
144 const Ice::RelocOffsetT Offset = 0; 145 const Ice::RelocOffsetT Offset = 0;
145 return Ctx->getConstantSym(Offset, Decl->getName()); 146 return Ctx->getConstantSym(
147 Offset, Ctx->getGlobalString(Decl->getName().toString()));
146 } 148 }
147 } else if (const auto CI = dyn_cast<ConstantInt>(Const)) { 149 } else if (const auto CI = dyn_cast<ConstantInt>(Const)) {
148 Ice::Type Ty = convertToIceType(CI->getType()); 150 Ice::Type Ty = convertToIceType(CI->getType());
149 return Ctx->getConstantInt(Ty, CI->getSExtValue()); 151 return Ctx->getConstantInt(Ty, CI->getSExtValue());
150 } else if (const auto CFP = dyn_cast<ConstantFP>(Const)) { 152 } else if (const auto CFP = dyn_cast<ConstantFP>(Const)) {
151 Ice::Type Type = convertToIceType(CFP->getType()); 153 Ice::Type Type = convertToIceType(CFP->getType());
152 if (Type == Ice::IceType_f32) 154 if (Type == Ice::IceType_f32)
153 return Ctx->getConstantFloat(CFP->getValueAPF().convertToFloat()); 155 return Ctx->getConstantFloat(CFP->getValueAPF().convertToFloat());
154 else if (Type == Ice::IceType_f64) 156 else if (Type == Ice::IceType_f64)
155 return Ctx->getConstantDouble(CFP->getValueAPF().convertToDouble()); 157 return Ctx->getConstantDouble(CFP->getValueAPF().convertToDouble());
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 raw_string_ostream StrBuf(Buffer); 800 raw_string_ostream StrBuf(Buffer);
799 StrBuf << "Unhandled global initializer: " << Initializer; 801 StrBuf << "Unhandled global initializer: " << Initializer;
800 report_fatal_error(StrBuf.str()); 802 report_fatal_error(StrBuf.str());
801 } 803 }
802 804
803 } // end of anonymous namespace 805 } // end of anonymous namespace
804 806
805 namespace Ice { 807 namespace Ice {
806 808
807 void Converter::nameUnnamedGlobalVariables(Module *Mod) { 809 void Converter::nameUnnamedGlobalVariables(Module *Mod) {
808 const IceString &GlobalPrefix = Ctx->getFlags().getDefaultGlobalPrefix(); 810 const std::string GlobalPrefix = Ctx->getFlags().getDefaultGlobalPrefix();
809 if (GlobalPrefix.empty()) 811 if (GlobalPrefix.empty())
810 return; 812 return;
811 uint32_t NameIndex = 0; 813 uint32_t NameIndex = 0;
812 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) {
813 if (!V->hasName()) { 815 if (!V->hasName()) {
814 V->setName(createUnnamedName(GlobalPrefix, NameIndex)); 816 V->setName(createUnnamedName(GlobalPrefix, NameIndex));
815 ++NameIndex; 817 ++NameIndex;
816 } else { 818 } else {
817 checkIfUnnamedNameSafe(V->getName(), "global", GlobalPrefix); 819 checkIfUnnamedNameSafe(V->getName(), "global", GlobalPrefix);
818 } 820 }
819 } 821 }
820 } 822 }
821 823
822 void Converter::nameUnnamedFunctions(Module *Mod) { 824 void Converter::nameUnnamedFunctions(Module *Mod) {
823 const IceString &FunctionPrefix = Ctx->getFlags().getDefaultFunctionPrefix(); 825 const std::string FunctionPrefix = Ctx->getFlags().getDefaultFunctionPrefix();
824 if (FunctionPrefix.empty()) 826 if (FunctionPrefix.empty())
825 return; 827 return;
826 uint32_t NameIndex = 0; 828 uint32_t NameIndex = 0;
827 for (Function &F : *Mod) { 829 for (Function &F : *Mod) {
828 if (!F.hasName()) { 830 if (!F.hasName()) {
829 F.setName(createUnnamedName(FunctionPrefix, NameIndex)); 831 F.setName(createUnnamedName(FunctionPrefix, NameIndex));
830 ++NameIndex; 832 ++NameIndex;
831 } else { 833 } else {
832 checkIfUnnamedNameSafe(F.getName(), "function", FunctionPrefix); 834 checkIfUnnamedNameSafe(F.getName(), "function", FunctionPrefix);
833 } 835 }
(...skipping 27 matching lines...) Expand all
861 FuncSigType Signature; 863 FuncSigType Signature;
862 FunctionType *FuncType = Func.getFunctionType(); 864 FunctionType *FuncType = Func.getFunctionType();
863 Signature.setReturnType( 865 Signature.setReturnType(
864 Converter.convertToIceType(FuncType->getReturnType())); 866 Converter.convertToIceType(FuncType->getReturnType()));
865 for (size_t I = 0; I < FuncType->getNumParams(); ++I) { 867 for (size_t I = 0; I < FuncType->getNumParams(); ++I) {
866 Signature.appendArgType( 868 Signature.appendArgType(
867 Converter.convertToIceType(FuncType->getParamType(I))); 869 Converter.convertToIceType(FuncType->getParamType(I)));
868 } 870 }
869 auto *IceFunc = FunctionDeclaration::create( 871 auto *IceFunc = FunctionDeclaration::create(
870 Ctx, Signature, Func.getCallingConv(), Func.getLinkage(), Func.empty()); 872 Ctx, Signature, Func.getCallingConv(), Func.getLinkage(), Func.empty());
871 IceFunc->setName(Func.getName()); 873 IceFunc->setName(Ctx, Func.getName());
872 if (!IceFunc->verifyLinkageCorrect(Ctx)) { 874 if (!IceFunc->verifyLinkageCorrect(Ctx)) {
873 std::string Buffer; 875 std::string Buffer;
874 raw_string_ostream StrBuf(Buffer); 876 raw_string_ostream StrBuf(Buffer);
875 StrBuf << "Function " << IceFunc->getName() 877 StrBuf << "Function " << IceFunc->getName()
876 << " has incorrect linkage: " << IceFunc->getLinkageName(); 878 << " has incorrect linkage: " << IceFunc->getLinkageName();
877 if (IceFunc->isExternal()) 879 if (IceFunc->isExternal())
878 StrBuf << "\n Use flag -allow-externally-defined-symbols to override"; 880 StrBuf << "\n Use flag -allow-externally-defined-symbols to override";
879 report_fatal_error(StrBuf.str()); 881 report_fatal_error(StrBuf.str());
880 } 882 }
881 if (!IceFunc->validateTypeSignature(Ctx)) 883 if (!IceFunc->validateTypeSignature(Ctx))
882 report_fatal_error(IceFunc->getTypeSignatureError(Ctx)); 884 report_fatal_error(IceFunc->getTypeSignatureError(Ctx));
883 GlobalDeclarationMap[&Func] = IceFunc; 885 GlobalDeclarationMap[&Func] = IceFunc;
884 } 886 }
885 // Install global variable declarations. 887 // Install global variable declarations.
886 for (Module::const_global_iterator I = Mod->global_begin(), 888 for (Module::const_global_iterator I = Mod->global_begin(),
887 E = Mod->global_end(); 889 E = Mod->global_end();
888 I != E; ++I) { 890 I != E; ++I) {
889 const GlobalVariable *GV = I; 891 const GlobalVariable *GV = I;
890 constexpr bool NoSuppressMangling = false; 892 constexpr bool NoSuppressMangling = false;
891 auto *Var = VariableDeclaration::create( 893 auto *Var = VariableDeclaration::create(
892 GlobalDeclarationsPool.get(), NoSuppressMangling, GV->getLinkage()); 894 GlobalDeclarationsPool.get(), NoSuppressMangling, GV->getLinkage());
893 Var->setAlignment(GV->getAlignment()); 895 Var->setAlignment(GV->getAlignment());
894 Var->setIsConstant(GV->isConstant()); 896 Var->setIsConstant(GV->isConstant());
895 Var->setName(GV->getName()); 897 Var->setName(Ctx, GV->getName());
896 if (!Var->verifyLinkageCorrect(Ctx)) { 898 if (!Var->verifyLinkageCorrect(Ctx)) {
897 std::string Buffer; 899 std::string Buffer;
898 raw_string_ostream StrBuf(Buffer); 900 raw_string_ostream StrBuf(Buffer);
899 StrBuf << "Global " << Var->getName() 901 StrBuf << "Global " << Var->getName()
900 << " has incorrect linkage: " << Var->getLinkageName(); 902 << " has incorrect linkage: " << Var->getLinkageName();
901 if (Var->isExternal()) 903 if (Var->isExternal())
902 StrBuf << "\n Use flag -allow-externally-defined-symbols to override"; 904 StrBuf << "\n Use flag -allow-externally-defined-symbols to override";
903 report_fatal_error(StrBuf.str()); 905 report_fatal_error(StrBuf.str());
904 } 906 }
905 GlobalDeclarationMap[GV] = Var; 907 GlobalDeclarationMap[GV] = Var;
(...skipping 10 matching lines...) Expand all
916 for (const Function &I : *Mod) { 918 for (const Function &I : *Mod) {
917 if (I.empty()) 919 if (I.empty())
918 continue; 920 continue;
919 TimerMarker _(Ctx, I.getName()); 921 TimerMarker _(Ctx, I.getName());
920 LLVM2ICEFunctionConverter FunctionConverter(*this); 922 LLVM2ICEFunctionConverter FunctionConverter(*this);
921 FunctionConverter.convertFunction(&I); 923 FunctionConverter.convertFunction(&I);
922 } 924 }
923 } 925 }
924 926
925 } // end of namespace Ice 927 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceCompiler.cpp ('k') | src/IceDefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698