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

Side by Side Diff: src/PNaClTranslator.cpp

Issue 1776473007: Subzero. Allocate global initializers from a dedicated arena. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: fixes ther llvm2ice converter; fixes the VariableDeclarationList destructor. Created 4 years, 9 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
« src/IceDefs.h ('K') | « src/IceTargetLoweringARM32.cpp ('k') | no next file » | 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/PNaClTranslator.cpp - ICE from bitcode -----------------===// 1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===//
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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 bool blockError(const std::string &Message); 250 bool blockError(const std::string &Message);
251 251
252 /// Returns the number of errors found while parsing the bitcode file. 252 /// Returns the number of errors found while parsing the bitcode file.
253 unsigned getNumErrors() const { return NumErrors; } 253 unsigned getNumErrors() const { return NumErrors; }
254 254
255 /// Changes the size of the type list to the given size. 255 /// Changes the size of the type list to the given size.
256 void resizeTypeIDValues(size_t NewSize) { TypeIDValues.resize(NewSize); } 256 void resizeTypeIDValues(size_t NewSize) { TypeIDValues.resize(NewSize); }
257 257
258 size_t getNumTypeIDValues() const { return TypeIDValues.size(); } 258 size_t getNumTypeIDValues() const { return TypeIDValues.size(); }
259 259
260 /// Returns a pointer to the pool where globals are allocated.
261 Ice::VariableDeclarationList *getGlobalVariablesPool() {
262 return VariableDeclarations.get();
263 }
264
260 /// Returns the undefined type associated with type ID. Note: Returns extended 265 /// Returns the undefined type associated with type ID. Note: Returns extended
261 /// type ready to be defined. 266 /// type ready to be defined.
262 ExtendedType *getTypeByIDForDefining(NaClBcIndexSize_t ID) { 267 ExtendedType *getTypeByIDForDefining(NaClBcIndexSize_t ID) {
263 // Get corresponding element, verifying the value is still undefined (and 268 // Get corresponding element, verifying the value is still undefined (and
264 // hence allowed to be defined). 269 // hence allowed to be defined).
265 ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Undefined); 270 ExtendedType *Ty = getTypeByIDAsKind(ID, ExtendedType::Undefined);
266 if (Ty) 271 if (Ty)
267 return Ty; 272 return Ty;
268 if (ID >= TypeIDValues.size()) { 273 if (ID >= TypeIDValues.size()) {
269 if (ID >= NaClBcIndexSize_t_Max) { 274 if (ID >= NaClBcIndexSize_t_Max) {
(...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 class GlobalsParser : public BlockParserBaseClass { 1019 class GlobalsParser : public BlockParserBaseClass {
1015 GlobalsParser() = delete; 1020 GlobalsParser() = delete;
1016 GlobalsParser(const GlobalsParser &) = delete; 1021 GlobalsParser(const GlobalsParser &) = delete;
1017 GlobalsParser &operator=(const GlobalsParser &) = delete; 1022 GlobalsParser &operator=(const GlobalsParser &) = delete;
1018 1023
1019 public: 1024 public:
1020 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) 1025 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser)
1021 : BlockParserBaseClass(BlockID, EnclosingParser), 1026 : BlockParserBaseClass(BlockID, EnclosingParser),
1022 Timer(Ice::TimerStack::TT_parseGlobals, getTranslator().getContext()), 1027 Timer(Ice::TimerStack::TT_parseGlobals, getTranslator().getContext()),
1023 NumFunctionIDs(Context->getNumFunctionIDs()), 1028 NumFunctionIDs(Context->getNumFunctionIDs()),
1024 DummyGlobalVar( 1029 DummyGlobalVar(Ice::VariableDeclaration::create(
1025 Ice::VariableDeclaration::create(getTranslator().getContext())), 1030 Context->getGlobalVariablesPool())),
1026 CurGlobalVar(DummyGlobalVar) {} 1031 CurGlobalVar(DummyGlobalVar) {
1032 Context->getGlobalVariablesPool()->willNotBeEmitted(DummyGlobalVar);
1033 }
1027 1034
1028 ~GlobalsParser() final = default; 1035 ~GlobalsParser() final = default;
1029 1036
1030 const char *getBlockName() const override { return "globals"; } 1037 const char *getBlockName() const override { return "globals"; }
1031 1038
1032 private: 1039 private:
1033 using GlobalVarsMapType = 1040 using GlobalVarsMapType =
1034 std::unordered_map<NaClBcIndexSize_t, Ice::VariableDeclaration *>; 1041 std::unordered_map<NaClBcIndexSize_t, Ice::VariableDeclaration *>;
1035 1042
1036 Ice::TimerMarker Timer; 1043 Ice::TimerMarker Timer;
(...skipping 19 matching lines...) Expand all
1056 // defined (allowing code to not need to check if CurGlobalVar is nullptr). 1063 // defined (allowing code to not need to check if CurGlobalVar is nullptr).
1057 Ice::VariableDeclaration *DummyGlobalVar; 1064 Ice::VariableDeclaration *DummyGlobalVar;
1058 1065
1059 // Holds the current global variable declaration being built. 1066 // Holds the current global variable declaration being built.
1060 Ice::VariableDeclaration *CurGlobalVar; 1067 Ice::VariableDeclaration *CurGlobalVar;
1061 1068
1062 // Returns the global variable associated with the given Index. 1069 // Returns the global variable associated with the given Index.
1063 Ice::VariableDeclaration *getGlobalVarByID(NaClBcIndexSize_t Index) { 1070 Ice::VariableDeclaration *getGlobalVarByID(NaClBcIndexSize_t Index) {
1064 Ice::VariableDeclaration *&Decl = GlobalVarsMap[Index]; 1071 Ice::VariableDeclaration *&Decl = GlobalVarsMap[Index];
1065 if (Decl == nullptr) 1072 if (Decl == nullptr)
1066 Decl = Ice::VariableDeclaration::create(getTranslator().getContext()); 1073 Decl =
1074 Ice::VariableDeclaration::create(Context->getGlobalVariablesPool());
1067 return Decl; 1075 return Decl;
1068 } 1076 }
1069 1077
1070 // Returns the global declaration associated with the given index. 1078 // Returns the global declaration associated with the given index.
1071 Ice::GlobalDeclaration *getGlobalDeclByID(NaClBcIndexSize_t Index) { 1079 Ice::GlobalDeclaration *getGlobalDeclByID(NaClBcIndexSize_t Index) {
1072 if (Index < NumFunctionIDs) 1080 if (Index < NumFunctionIDs)
1073 return Context->getFunctionByID(Index); 1081 return Context->getFunctionByID(Index);
1074 return getGlobalVarByID(Index - NumFunctionIDs); 1082 return getGlobalVarByID(Index - NumFunctionIDs);
1075 } 1083 }
1076 1084
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 << " compound record size invalid. Found: " << Values[0]; 1174 << " compound record size invalid. Found: " << Values[0];
1167 Error(StrBuf.str()); 1175 Error(StrBuf.str());
1168 return; 1176 return;
1169 } 1177 }
1170 InitializersNeeded = Values[0]; 1178 InitializersNeeded = Values[0];
1171 return; 1179 return;
1172 case naclbitc::GLOBALVAR_ZEROFILL: { 1180 case naclbitc::GLOBALVAR_ZEROFILL: {
1173 // ZEROFILL: [size] 1181 // ZEROFILL: [size]
1174 if (!isValidRecordSize(1, "zerofill")) 1182 if (!isValidRecordSize(1, "zerofill"))
1175 return; 1183 return;
1184 auto *Pool = Context->getGlobalVariablesPool();
1176 CurGlobalVar->addInitializer( 1185 CurGlobalVar->addInitializer(
1177 Ice::VariableDeclaration::ZeroInitializer::create(Values[0])); 1186 Ice::VariableDeclaration::ZeroInitializer::create(Pool, Values[0]));
1178 return; 1187 return;
1179 } 1188 }
1180 case naclbitc::GLOBALVAR_DATA: { 1189 case naclbitc::GLOBALVAR_DATA: {
1181 // DATA: [b0, b1, ...] 1190 // DATA: [b0, b1, ...]
1182 if (!isValidRecordSizeAtLeast(1, "data")) 1191 if (!isValidRecordSizeAtLeast(1, "data"))
1183 return; 1192 return;
1193 auto *Pool = Context->getGlobalVariablesPool();
1184 CurGlobalVar->addInitializer( 1194 CurGlobalVar->addInitializer(
1185 Ice::VariableDeclaration::DataInitializer::create(Values)); 1195 Ice::VariableDeclaration::DataInitializer::create(Pool, Values));
1186 return; 1196 return;
1187 } 1197 }
1188 case naclbitc::GLOBALVAR_RELOC: { 1198 case naclbitc::GLOBALVAR_RELOC: {
1189 // RELOC: [val, [addend]] 1199 // RELOC: [val, [addend]]
1190 if (!isValidRecordSizeInRange(1, 2, "reloc")) 1200 if (!isValidRecordSizeInRange(1, 2, "reloc"))
1191 return; 1201 return;
1192 NaClBcIndexSize_t Index = Values[0]; 1202 NaClBcIndexSize_t Index = Values[0];
1193 NaClBcIndexSize_t IndexLimit = SpecifiedNumberVars + NumFunctionIDs; 1203 NaClBcIndexSize_t IndexLimit = SpecifiedNumberVars + NumFunctionIDs;
1194 if (Index >= IndexLimit) { 1204 if (Index >= IndexLimit) {
1195 std::string Buffer; 1205 std::string Buffer;
1196 raw_string_ostream StrBuf(Buffer); 1206 raw_string_ostream StrBuf(Buffer);
1197 StrBuf << "Relocation index " << Index << " to big. Expect index < " 1207 StrBuf << "Relocation index " << Index << " to big. Expect index < "
1198 << IndexLimit; 1208 << IndexLimit;
1199 Error(StrBuf.str()); 1209 Error(StrBuf.str());
1200 } 1210 }
1201 uint64_t Offset = 0; 1211 uint64_t Offset = 0;
1202 if (Values.size() == 2) { 1212 if (Values.size() == 2) {
1203 Offset = Values[1]; 1213 Offset = Values[1];
1204 if (Offset > std::numeric_limits<uint32_t>::max()) { 1214 if (Offset > std::numeric_limits<uint32_t>::max()) {
1205 std::string Buffer; 1215 std::string Buffer;
1206 raw_string_ostream StrBuf(Buffer); 1216 raw_string_ostream StrBuf(Buffer);
1207 StrBuf << "Addend of global reloc record too big: " << Offset; 1217 StrBuf << "Addend of global reloc record too big: " << Offset;
1208 Error(StrBuf.str()); 1218 Error(StrBuf.str());
1209 } 1219 }
1210 } 1220 }
1221 auto *Pool = Context->getGlobalVariablesPool();
1211 Ice::GlobalContext *Ctx = getTranslator().getContext(); 1222 Ice::GlobalContext *Ctx = getTranslator().getContext();
1212 CurGlobalVar->addInitializer( 1223 CurGlobalVar->addInitializer(
1213 Ice::VariableDeclaration::RelocInitializer::create( 1224 Ice::VariableDeclaration::RelocInitializer::create(
1214 getGlobalDeclByID(Index), {Ice::RelocOffset::create(Ctx, Offset)})); 1225 Pool, getGlobalDeclByID(Index),
1226 {Ice::RelocOffset::create(Ctx, Offset)}));
1215 return; 1227 return;
1216 } 1228 }
1217 default: 1229 default:
1218 BlockParserBaseClass::ProcessRecord(); 1230 BlockParserBaseClass::ProcessRecord();
1219 return; 1231 return;
1220 } 1232 }
1221 } 1233 }
1222 1234
1223 /// Base class for parsing a valuesymtab block in the bitcode file. 1235 /// Base class for parsing a valuesymtab block in the bitcode file.
1224 class ValuesymtabParser : public BlockParserBaseClass { 1236 class ValuesymtabParser : public BlockParserBaseClass {
(...skipping 1977 matching lines...) Expand 10 before | Expand all | Expand 10 after
3202 raw_string_ostream StrBuf(Buffer); 3214 raw_string_ostream StrBuf(Buffer);
3203 StrBuf << IRFilename << ": Does not contain a module!"; 3215 StrBuf << IRFilename << ": Does not contain a module!";
3204 llvm::report_fatal_error(StrBuf.str()); 3216 llvm::report_fatal_error(StrBuf.str());
3205 } 3217 }
3206 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { 3218 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) {
3207 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); 3219 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes");
3208 } 3220 }
3209 } 3221 }
3210 3222
3211 } // end of namespace Ice 3223 } // end of namespace Ice
OLDNEW
« src/IceDefs.h ('K') | « src/IceTargetLoweringARM32.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698