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

Side by Side Diff: src/IceConverter.cpp

Issue 667763002: Fix handling of relocation names, so that prefix mangling works. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nits. 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
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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 Func->computePredecessors(); 107 Func->computePredecessors();
108 108
109 return Func; 109 return Func;
110 } 110 }
111 111
112 // convertConstant() does not use Func or require it to be a valid 112 // convertConstant() does not use Func or require it to be a valid
113 // Ice::Cfg pointer. As such, it's suitable for e.g. constructing 113 // Ice::Cfg pointer. As such, it's suitable for e.g. constructing
114 // global initializers. 114 // global initializers.
115 Ice::Constant *convertConstant(const Constant *Const) { 115 Ice::Constant *convertConstant(const Constant *Const) {
116 if (const auto GV = dyn_cast<GlobalValue>(Const)) { 116 if (const auto GV = dyn_cast<GlobalValue>(Const)) {
117 return Ctx->getConstantSym(convertToIceType(GV->getType()), 0, 117 Ice::GlobalDeclaration *Decl = getConverter().getGlobalDeclaration(GV);
118 GV->getName()); 118 const Ice::RelocOffsetT Offset = 0;
119 return Ctx->getConstantSym(TypeConverter.getIcePointerType(),
120 Offset, Decl->getName(),
121 Decl->getSuppressMangling());
119 } else if (const auto CI = dyn_cast<ConstantInt>(Const)) { 122 } else if (const auto CI = dyn_cast<ConstantInt>(Const)) {
120 Ice::Type Ty = convertToIceType(CI->getType()); 123 Ice::Type Ty = convertToIceType(CI->getType());
121 if (Ty == Ice::IceType_i64) { 124 if (Ty == Ice::IceType_i64) {
122 return Ctx->getConstantInt64(Ty, CI->getSExtValue()); 125 return Ctx->getConstantInt64(Ty, CI->getSExtValue());
123 } else { 126 } else {
124 return Ctx->getConstantInt32(Ty, CI->getSExtValue()); 127 return Ctx->getConstantInt32(Ty, CI->getSExtValue());
125 } 128 }
126 } else if (const auto CFP = dyn_cast<ConstantFP>(Const)) { 129 } else if (const auto CFP = dyn_cast<ConstantFP>(Const)) {
127 Ice::Type Type = convertToIceType(CFP->getType()); 130 Ice::Type Type = convertToIceType(CFP->getType());
128 if (Type == Ice::IceType_f32) 131 if (Type == Ice::IceType_f32)
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 return 0; 686 return 0;
684 } 687 }
685 }; 688 };
686 689
687 void LLVM2ICEGlobalsConverter::convertGlobalsToIce( 690 void LLVM2ICEGlobalsConverter::convertGlobalsToIce(
688 Module *Mod, 691 Module *Mod,
689 Ice::Translator::VariableDeclarationListType &VariableDeclarations) { 692 Ice::Translator::VariableDeclarationListType &VariableDeclarations) {
690 for (Module::const_global_iterator I = Mod->global_begin(), 693 for (Module::const_global_iterator I = Mod->global_begin(),
691 E = Mod->global_end(); 694 E = Mod->global_end();
692 I != E; ++I) { 695 I != E; ++I) {
693 if (!I->hasInitializer() && Ctx->getFlags().AllowUninitializedGlobals)
694 continue;
695 696
696 const GlobalVariable *GV = I; 697 const GlobalVariable *GV = I;
697 Ice::IceString Name = GV->getName();
698 if (!GV->hasInternalLinkage()) {
699 std::string Buffer;
700 raw_string_ostream StrBuf(Buffer);
701 StrBuf << "Can't define external global declaration: " << Name;
702 report_fatal_error(StrBuf.str());
703 }
704 698
705 Ice::GlobalDeclaration *Var = getConverter().getGlobalDeclaration(GV); 699 Ice::GlobalDeclaration *Var = getConverter().getGlobalDeclaration(GV);
706 Ice::VariableDeclaration* VarDecl = cast<Ice::VariableDeclaration>(Var); 700 Ice::VariableDeclaration* VarDecl = cast<Ice::VariableDeclaration>(Var);
707 VariableDeclarations.push_back(VarDecl); 701 VariableDeclarations.push_back(VarDecl);
708 702
703 if (!GV->hasInternalLinkage() && GV->hasInitializer()) {
704 std::string Buffer;
705 raw_string_ostream StrBuf(Buffer);
706 StrBuf << "Can't define external global declaration: " << GV->getName();
707 report_fatal_error(StrBuf.str());
708 }
709
710 if (!GV->hasInitializer()) {
711 if (Ctx->getFlags().AllowUninitializedGlobals)
712 continue;
713 else {
714 std::string Buffer;
715 raw_string_ostream StrBuf(Buffer);
716 StrBuf << "Global declaration missing initializer: " << GV->getName();
717 report_fatal_error(StrBuf.str());
718 }
719 }
720
709 const Constant *Initializer = GV->getInitializer(); 721 const Constant *Initializer = GV->getInitializer();
710 if (const auto CompoundInit = dyn_cast<ConstantStruct>(Initializer)) { 722 if (const auto CompoundInit = dyn_cast<ConstantStruct>(Initializer)) {
711 for (ConstantStruct::const_op_iterator I = CompoundInit->op_begin(), 723 for (ConstantStruct::const_op_iterator I = CompoundInit->op_begin(),
712 E = CompoundInit->op_end(); 724 E = CompoundInit->op_end();
713 I != E; ++I) { 725 I != E; ++I) {
714 if (const auto Init = dyn_cast<Constant>(I)) { 726 if (const auto Init = dyn_cast<Constant>(I)) {
715 addGlobalInitializer(*VarDecl, Init); 727 addGlobalInitializer(*VarDecl, Init);
716 } 728 }
717 } 729 }
718 } else { 730 } else {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 } 863 }
852 // Install global variable declarations. 864 // Install global variable declarations.
853 for (Module::const_global_iterator I = Mod->global_begin(), 865 for (Module::const_global_iterator I = Mod->global_begin(),
854 E = Mod->global_end(); 866 E = Mod->global_end();
855 I != E; ++I) { 867 I != E; ++I) {
856 const GlobalVariable *GV = I; 868 const GlobalVariable *GV = I;
857 VariableDeclaration *Var = VariableDeclaration::create(Ctx); 869 VariableDeclaration *Var = VariableDeclaration::create(Ctx);
858 Var->setName(GV->getName()); 870 Var->setName(GV->getName());
859 Var->setAlignment(GV->getAlignment()); 871 Var->setAlignment(GV->getAlignment());
860 Var->setIsConstant(GV->isConstant()); 872 Var->setIsConstant(GV->isConstant());
861 // Note: We allow external for cross tests. 873 Var->setLinkage(GV->getLinkage());
862 // TODO(kschimpf) Put behind flag AllowUninitializedGlobals.
863 Var->setIsInternal(!GV->isExternallyInitialized());
864 GlobalDeclarationMap[GV] = Var; 874 GlobalDeclarationMap[GV] = Var;
865 } 875 }
866 } 876 }
867 877
868 void Converter::convertGlobals(Module *Mod) { 878 void Converter::convertGlobals(Module *Mod) {
869 LLVM2ICEGlobalsConverter GlobalsConverter(*this); 879 LLVM2ICEGlobalsConverter GlobalsConverter(*this);
870 Translator::VariableDeclarationListType VariableDeclarations; 880 Translator::VariableDeclarationListType VariableDeclarations;
871 GlobalsConverter.convertGlobalsToIce(Mod, VariableDeclarations); 881 GlobalsConverter.convertGlobalsToIce(Mod, VariableDeclarations);
872 lowerGlobals(VariableDeclarations); 882 lowerGlobals(VariableDeclarations);
873 } 883 }
(...skipping 14 matching lines...) Expand all
888 Cfg *Fcn = FunctionConverter.convertFunction(&I); 898 Cfg *Fcn = FunctionConverter.convertFunction(&I);
889 translateFcn(Fcn); 899 translateFcn(Fcn);
890 if (Ctx->getFlags().TimeEachFunction) 900 if (Ctx->getFlags().TimeEachFunction)
891 Ctx->popTimer(TimerID, StackID); 901 Ctx->popTimer(TimerID, StackID);
892 } 902 }
893 903
894 emitConstants(); 904 emitConstants();
895 } 905 }
896 906
897 } // end of namespace Ice 907 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceCfg.cpp ('k') | src/IceGlobalInits.h » ('j') | src/IceGlobalInits.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698