Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 // This file implements the PNaCl bitcode file to Ice, to machine code | 10 // This file implements the PNaCl bitcode file to Ice, to machine code |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 TopLevelParser(const TopLevelParser &) = delete; | 156 TopLevelParser(const TopLevelParser &) = delete; |
| 157 TopLevelParser &operator=(const TopLevelParser &) = delete; | 157 TopLevelParser &operator=(const TopLevelParser &) = delete; |
| 158 | 158 |
| 159 public: | 159 public: |
| 160 typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType; | 160 typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType; |
| 161 | 161 |
| 162 TopLevelParser(Ice::Translator &Translator, NaClBitcodeHeader &Header, | 162 TopLevelParser(Ice::Translator &Translator, NaClBitcodeHeader &Header, |
| 163 NaClBitstreamCursor &Cursor, Ice::ErrorCode &ErrorStatus) | 163 NaClBitstreamCursor &Cursor, Ice::ErrorCode &ErrorStatus) |
| 164 : NaClBitcodeParser(Cursor), Translator(Translator), Header(Header), | 164 : NaClBitcodeParser(Cursor), Translator(Translator), Header(Header), |
| 165 ErrorStatus(ErrorStatus), NumErrors(0), NextDefiningFunctionID(0), | 165 ErrorStatus(ErrorStatus), NumErrors(0), NextDefiningFunctionID(0), |
| 166 VariableDeclarations(new Ice::VariableDeclarationList()), | |
| 166 BlockParser(nullptr), StubbedConstCallValue(nullptr) {} | 167 BlockParser(nullptr), StubbedConstCallValue(nullptr) {} |
| 167 | 168 |
| 168 ~TopLevelParser() override {} | 169 ~TopLevelParser() override {} |
| 169 | 170 |
| 170 Ice::Translator &getTranslator() { return Translator; } | 171 Ice::Translator &getTranslator() { return Translator; } |
| 171 | 172 |
| 172 void setBlockParser(BlockParserBaseClass *NewBlockParser) { | 173 void setBlockParser(BlockParserBaseClass *NewBlockParser) { |
| 173 BlockParser = NewBlockParser; | 174 BlockParser = NewBlockParser; |
| 174 } | 175 } |
| 175 | 176 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 return NextDefiningFunctionID++; | 245 return NextDefiningFunctionID++; |
| 245 } | 246 } |
| 246 | 247 |
| 247 /// Returns the function associated with ID. | 248 /// Returns the function associated with ID. |
| 248 Ice::FunctionDeclaration *getFunctionByID(unsigned ID) { | 249 Ice::FunctionDeclaration *getFunctionByID(unsigned ID) { |
| 249 if (ID < FunctionDeclarationList.size()) | 250 if (ID < FunctionDeclarationList.size()) |
| 250 return FunctionDeclarationList[ID]; | 251 return FunctionDeclarationList[ID]; |
| 251 return reportGetFunctionByIDError(ID); | 252 return reportGetFunctionByIDError(ID); |
| 252 } | 253 } |
| 253 | 254 |
| 254 /// Returns the list of function declarations. | 255 /// Returns the constant associated with the given global value ID. |
| 255 const FunctionDeclarationListType &getFunctionDeclarationList() const { | 256 Ice::Constant *getGlobalConstantByID(unsigned ID) { |
| 256 return FunctionDeclarationList; | 257 assert(ID < ValueIDConstants.size()); |
| 258 return ValueIDConstants[ID]; | |
| 257 } | 259 } |
| 258 | 260 |
| 259 /// Returns the corresponding constant associated with a global declaration. | 261 /// Install names for all global values without names. Called after |
| 260 /// (i.e. relocatable). | 262 /// the global value symbol table is processed, but before any |
| 261 Ice::Constant *getOrCreateGlobalConstantByID(unsigned ID) { | 263 /// function blocks are processed. |
| 262 // TODO(kschimpf): Can this be built when creating global initializers? | 264 void installGlobalNames() { |
| 263 Ice::Constant *C; | 265 assert(VariableDeclarations); |
| 264 if (ID >= ValueIDConstants.size()) { | 266 installGlobalVarNames(); |
| 265 C = nullptr; | 267 installFunctionNames(); |
| 266 unsigned ExpectedSize = | 268 } |
| 267 FunctionDeclarationList.size() + VariableDeclarations.size(); | |
| 268 if (ID >= ExpectedSize) | |
| 269 ExpectedSize = ID; | |
| 270 ValueIDConstants.resize(ExpectedSize); | |
| 271 } else { | |
| 272 C = ValueIDConstants[ID]; | |
| 273 } | |
| 274 if (C != nullptr) | |
| 275 return C; | |
| 276 | 269 |
| 277 if (isIRGenerationDisabled()) { | 270 void createValueIDs() { |
| 278 ValueIDConstants[ID] = nullptr; | 271 assert(VariableDeclarations); |
| 279 return nullptr; | 272 ValueIDConstants.reserve(VariableDeclarations->size() + |
| 280 } | 273 FunctionDeclarationList.size()); |
| 281 | 274 createValueIDsForFunctions(); |
| 282 // If reached, no such constant exists, create one. | 275 createValueIDsForGlobalVars(); |
| 283 // TODO(kschimpf) Don't get addresses of intrinsic function declarations. | |
| 284 Ice::GlobalDeclaration *Decl = nullptr; | |
| 285 unsigned FcnIDSize = FunctionDeclarationList.size(); | |
| 286 bool IsUndefined = false; | |
| 287 if (ID < FcnIDSize) { | |
| 288 Decl = FunctionDeclarationList[ID]; | |
| 289 const auto Func = llvm::cast<Ice::FunctionDeclaration>(Decl); | |
| 290 IsUndefined = Func->isProto(); | |
| 291 } else if ((ID - FcnIDSize) < VariableDeclarations.size()) { | |
| 292 Decl = VariableDeclarations[ID - FcnIDSize]; | |
| 293 const auto Var = llvm::cast<Ice::VariableDeclaration>(Decl); | |
| 294 IsUndefined = !Var->hasInitializer(); | |
| 295 } | |
| 296 Ice::IceString Name; | |
| 297 bool SuppressMangling; | |
| 298 if (Decl) { | |
| 299 Name = Decl->getName(); | |
| 300 SuppressMangling = Decl->getSuppressMangling(); | |
| 301 } else { | |
| 302 std::string Buffer; | |
| 303 raw_string_ostream StrBuf(Buffer); | |
| 304 StrBuf << "Reference to global not defined: " << ID; | |
| 305 BlockError(StrBuf.str()); | |
| 306 // TODO(kschimpf) Remove error recovery once implementation complete. | |
| 307 Name = "??"; | |
| 308 SuppressMangling = false; | |
| 309 } | |
| 310 if (IsUndefined) | |
| 311 C = getTranslator().getContext()->getConstantExternSym(Name); | |
| 312 else { | |
| 313 const Ice::RelocOffsetT Offset = 0; | |
| 314 C = getTranslator().getContext()->getConstantSym(Offset, Name, | |
| 315 SuppressMangling); | |
| 316 } | |
| 317 ValueIDConstants[ID] = C; | |
| 318 return C; | |
| 319 } | 276 } |
| 320 | 277 |
| 321 /// Returns a defined function reference to be used in place of | 278 /// Returns a defined function reference to be used in place of |
| 322 /// called constant addresses. Returns the corresponding operand | 279 /// called constant addresses. Returns the corresponding operand |
| 323 /// to replace the calling address with. Reports an error if | 280 /// to replace the calling address with. Reports an error if |
| 324 /// a stub could not be found, returning the CallValue. | 281 /// a stub could not be found, returning the CallValue. |
| 325 Ice::Operand *getStubbedConstCallValue(Ice::Operand *CallValue) { | 282 Ice::Operand *getStubbedConstCallValue(Ice::Operand *CallValue) { |
| 326 if (StubbedConstCallValue) | 283 if (StubbedConstCallValue) |
| 327 return StubbedConstCallValue; | 284 return StubbedConstCallValue; |
| 328 for (unsigned i = 0; i < getNumFunctionIDs(); ++i) { | 285 for (unsigned i = 0; i < getNumFunctionIDs(); ++i) { |
| 329 Ice::FunctionDeclaration *Func = getFunctionByID(i); | 286 Ice::FunctionDeclaration *Func = getFunctionByID(i); |
| 330 if (!Func->isProto()) { | 287 if (!Func->isProto()) { |
| 331 StubbedConstCallValue = getOrCreateGlobalConstantByID(i); | 288 StubbedConstCallValue = getGlobalConstantByID(i); |
| 332 return StubbedConstCallValue; | 289 return StubbedConstCallValue; |
| 333 } | 290 } |
| 334 } | 291 } |
| 335 Error("Unable to find function definition to stub constant calls with"); | 292 Error("Unable to find function definition to stub constant calls with"); |
| 336 return CallValue; | 293 return CallValue; |
| 337 } | 294 } |
| 338 | 295 |
| 339 /// Returns the number of function declarations in the bitcode file. | 296 /// Returns the number of function declarations in the bitcode file. |
| 340 unsigned getNumFunctionIDs() const { return FunctionDeclarationList.size(); } | 297 unsigned getNumFunctionIDs() const { return FunctionDeclarationList.size(); } |
| 341 | 298 |
| 342 /// Returns the number of global declarations (i.e. IDs) defined in | 299 /// Returns the number of global declarations (i.e. IDs) defined in |
| 343 /// the bitcode file. | 300 /// the bitcode file. |
| 344 unsigned getNumGlobalIDs() const { | 301 unsigned getNumGlobalIDs() const { |
| 345 return FunctionDeclarationList.size() + VariableDeclarations.size(); | 302 if (VariableDeclarations) { |
| 303 return FunctionDeclarationList.size() + VariableDeclarations->size(); | |
| 304 } else { | |
| 305 return ValueIDConstants.size(); | |
| 306 } | |
| 346 } | 307 } |
| 347 | 308 |
| 348 /// Creates Count global variable declarations. | 309 /// Creates Count global variable declarations. |
| 349 void CreateGlobalVariables(size_t Count) { | 310 void CreateGlobalVariables(size_t Count) { |
| 350 assert(VariableDeclarations.empty()); | 311 assert(VariableDeclarations); |
| 312 assert(VariableDeclarations->empty()); | |
| 351 for (size_t i = 0; i < Count; ++i) { | 313 for (size_t i = 0; i < Count; ++i) { |
| 352 VariableDeclarations.push_back(Ice::VariableDeclaration::create()); | 314 VariableDeclarations->push_back(Ice::VariableDeclaration::create()); |
| 353 } | 315 } |
| 354 } | 316 } |
| 355 | 317 |
| 356 /// Returns the number of global variable declarations in the | 318 /// Returns the number of global variable declarations in the |
| 357 /// bitcode file. | 319 /// bitcode file. |
| 358 Ice::SizeT getNumGlobalVariables() const { | 320 Ice::SizeT getNumGlobalVariables() const { |
| 359 return VariableDeclarations.size(); | 321 if (VariableDeclarations) { |
| 322 return VariableDeclarations->size(); | |
| 323 } else { | |
| 324 return ValueIDConstants.size() - FunctionDeclarationList.size(); | |
| 325 } | |
| 360 } | 326 } |
| 361 | 327 |
| 362 /// Returns the global variable declaration with the given index. | 328 /// Returns the global variable declaration with the given index. |
| 363 Ice::VariableDeclaration *getGlobalVariableByID(unsigned Index) { | 329 Ice::VariableDeclaration *getGlobalVariableByID(unsigned Index) { |
| 364 if (Index < VariableDeclarations.size()) | 330 assert(VariableDeclarations); |
| 365 return VariableDeclarations[Index]; | 331 if (Index < VariableDeclarations->size()) |
| 332 return VariableDeclarations->at(Index); | |
| 366 return reportGetGlobalVariableByIDError(Index); | 333 return reportGetGlobalVariableByIDError(Index); |
| 367 } | 334 } |
| 368 | 335 |
| 369 /// Returns the global declaration (variable or function) with the | 336 /// Returns the global declaration (variable or function) with the |
| 370 /// given Index. | 337 /// given Index. |
| 371 Ice::GlobalDeclaration *getGlobalDeclarationByID(size_t Index) { | 338 Ice::GlobalDeclaration *getGlobalDeclarationByID(size_t Index) { |
| 372 size_t NumFunctionIds = FunctionDeclarationList.size(); | 339 size_t NumFunctionIds = FunctionDeclarationList.size(); |
| 373 if (Index < NumFunctionIds) | 340 if (Index < NumFunctionIds) |
| 374 return getFunctionByID(Index); | 341 return getFunctionByID(Index); |
| 375 else | 342 else |
| 376 return getGlobalVariableByID(Index - NumFunctionIds); | 343 return getGlobalVariableByID(Index - NumFunctionIds); |
| 377 } | 344 } |
| 378 | 345 |
| 379 /// Returns the list of parsed global variable declarations. | 346 /// Returns the list of parsed global variable declarations. Releases |
| 380 const Ice::VariableDeclarationList &getGlobalVariables() { | 347 /// ownership of the current list of global variables. |
| 381 return VariableDeclarations; | 348 std::unique_ptr<Ice::VariableDeclarationList> &&getGlobalVariables() { |
|
Jim Stichnoth
2015/02/10 17:47:11
Does this actually have to have "&&"? I thought i
Karl
2015/02/10 19:30:23
I thought that would be more efficient, but I'll r
| |
| 349 // Before returning, check that ValidIDConstants has already been | |
| 350 // build. | |
|
Jim Stichnoth
2015/02/10 17:47:11
built
Karl
2015/02/10 19:30:23
Done.
| |
| 351 assert(!VariableDeclarations || | |
|
jvoung (off chromium)
2015/02/10 18:24:58
Why is it okay for "!VariableDeclarations"?
I ass
Jim Stichnoth
2015/02/10 18:29:01
Hmm, I was under the impression that this could po
Karl
2015/02/10 19:30:23
The code assumes it is only built once. I wanted t
| |
| 352 VariableDeclarations->size() <= ValueIDConstants.size()); | |
| 353 return std::move(VariableDeclarations); | |
| 382 } | 354 } |
| 383 | 355 |
| 384 private: | 356 private: |
| 385 // The translator associated with the parser. | 357 // The translator associated with the parser. |
| 386 Ice::Translator &Translator; | 358 Ice::Translator &Translator; |
| 387 // The bitcode header. | 359 // The bitcode header. |
| 388 NaClBitcodeHeader &Header; | 360 NaClBitcodeHeader &Header; |
| 389 // The exit status that should be set to true if an error occurs. | 361 // The exit status that should be set to true if an error occurs. |
| 390 Ice::ErrorCode &ErrorStatus; | 362 Ice::ErrorCode &ErrorStatus; |
| 391 // The number of errors reported. | 363 // The number of errors reported. |
| 392 unsigned NumErrors; | 364 unsigned NumErrors; |
| 393 // The types associated with each type ID. | 365 // The types associated with each type ID. |
| 394 std::vector<ExtendedType> TypeIDValues; | 366 std::vector<ExtendedType> TypeIDValues; |
| 395 // The set of functions (prototype and defined). | 367 // The set of functions (prototype and defined). |
| 396 FunctionDeclarationListType FunctionDeclarationList; | 368 FunctionDeclarationListType FunctionDeclarationList; |
| 397 // The ID of the next possible defined function ID in | 369 // The ID of the next possible defined function ID in |
| 398 // FunctionDeclarationList. FunctionDeclarationList is filled | 370 // FunctionDeclarationList. FunctionDeclarationList is filled |
| 399 // first. It's the set of functions (either defined or isproto). Then | 371 // first. It's the set of functions (either defined or isproto). Then |
| 400 // function definitions are encountered/parsed and | 372 // function definitions are encountered/parsed and |
| 401 // NextDefiningFunctionID is incremented to track the next | 373 // NextDefiningFunctionID is incremented to track the next |
| 402 // actually-defined function. | 374 // actually-defined function. |
| 403 size_t NextDefiningFunctionID; | 375 size_t NextDefiningFunctionID; |
| 404 // The set of global variables. | 376 // The set of global variables. |
| 405 Ice::VariableDeclarationList VariableDeclarations; | 377 std::unique_ptr<Ice::VariableDeclarationList> VariableDeclarations; |
| 406 // Relocatable constants associated with global declarations. | 378 // Relocatable constants associated with global declarations. |
| 407 std::vector<Ice::Constant *> ValueIDConstants; | 379 std::vector<Ice::Constant *> ValueIDConstants; |
| 408 // Error recovery value to use when getFuncSigTypeByID fails. | 380 // Error recovery value to use when getFuncSigTypeByID fails. |
| 409 Ice::FuncSigType UndefinedFuncSigType; | 381 Ice::FuncSigType UndefinedFuncSigType; |
| 410 // The block parser currently being applied. Used for error | 382 // The block parser currently being applied. Used for error |
| 411 // reporting. | 383 // reporting. |
| 412 BlockParserBaseClass *BlockParser; | 384 BlockParserBaseClass *BlockParser; |
| 413 // Value to use to stub constant calls. | 385 // Value to use to stub constant calls. |
| 414 Ice::Operand *StubbedConstCallValue; | 386 Ice::Operand *StubbedConstCallValue; |
| 415 | 387 |
| 416 bool ParseBlock(unsigned BlockID) override; | 388 bool ParseBlock(unsigned BlockID) override; |
| 417 | 389 |
| 418 // Gets extended type associated with the given index, assuming the | 390 // Gets extended type associated with the given index, assuming the |
| 419 // extended type is of the WantedKind. Generates error message if | 391 // extended type is of the WantedKind. Generates error message if |
| 420 // corresponding extended type of WantedKind can't be found, and | 392 // corresponding extended type of WantedKind can't be found, and |
| 421 // returns nullptr. | 393 // returns nullptr. |
| 422 ExtendedType *getTypeByIDAsKind(unsigned ID, | 394 ExtendedType *getTypeByIDAsKind(unsigned ID, |
| 423 ExtendedType::TypeKind WantedKind) { | 395 ExtendedType::TypeKind WantedKind) { |
| 424 ExtendedType *Ty = nullptr; | 396 ExtendedType *Ty = nullptr; |
| 425 if (ID < TypeIDValues.size()) { | 397 if (ID < TypeIDValues.size()) { |
| 426 Ty = &TypeIDValues[ID]; | 398 Ty = &TypeIDValues[ID]; |
| 427 if (Ty->getKind() == WantedKind) | 399 if (Ty->getKind() == WantedKind) |
| 428 return Ty; | 400 return Ty; |
| 429 } | 401 } |
| 430 // Generate an error message and set ErrorStatus. | 402 // Generate an error message and set ErrorStatus. |
| 431 this->reportBadTypeIDAs(ID, Ty, WantedKind); | 403 this->reportBadTypeIDAs(ID, Ty, WantedKind); |
| 432 return nullptr; | 404 return nullptr; |
| 433 } | 405 } |
| 434 | 406 |
| 407 // Gives Decl a name if it doesn't already have one. Prefix and | |
| 408 // NameIndex is used to generate the name. NameIndex is | |
|
Jim Stichnoth
2015/02/10 17:47:11
are used
Karl
2015/02/10 19:30:23
Done.
| |
| 409 // automatically incremented if a new new is created. | |
|
Jim Stichnoth
2015/02/10 17:47:11
"new new" ==> ???
Karl
2015/02/10 19:30:23
Fixed.
| |
| 410 // DeclType is literal text describing the type of name being | |
| 411 // created. | |
|
Jim Stichnoth
2015/02/10 17:47:11
Mention that it's used just for error reporting?
Karl
2015/02/10 19:30:23
This is not true. As stated in the comment, it cre
| |
| 412 void installDeclarationName(Ice::GlobalDeclaration *Decl, | |
| 413 const Ice::IceString &Prefix, | |
| 414 const char *DeclType, uint32_t &NameIndex) { | |
| 415 if (!Decl->hasName()) { | |
|
Jim Stichnoth
2015/02/10 17:47:11
Rewrite as
if (Decl->hasName()) {
Translator...;
Karl
2015/02/10 19:30:22
Done.
| |
| 416 Decl->setName(Translator.createUnnamedName(Prefix, NameIndex)); | |
| 417 ++NameIndex; | |
| 418 } else { | |
| 419 Translator.checkIfUnnamedNameSafe(Decl->getName(), DeclType, Prefix); | |
| 420 } | |
| 421 } | |
| 422 | |
| 423 // Installs names for global variables without names. | |
| 424 void installGlobalVarNames() { | |
| 425 assert(VariableDeclarations); | |
| 426 const Ice::IceString &GlobalPrefix = | |
| 427 getTranslator().getFlags().getDefaultGlobalPrefix(); | |
| 428 if (!GlobalPrefix.empty()) { | |
| 429 uint32_t NameIndex = 0; | |
| 430 for (Ice::VariableDeclaration *Var : *VariableDeclarations) { | |
| 431 installDeclarationName(Var, GlobalPrefix, "global", NameIndex); | |
| 432 } | |
| 433 } | |
| 434 } | |
| 435 | |
| 436 // Installs names for functions without names. | |
| 437 void installFunctionNames() { | |
| 438 const Ice::IceString &FunctionPrefix = | |
| 439 getTranslator().getFlags().getDefaultFunctionPrefix(); | |
| 440 if (!FunctionPrefix.empty()) { | |
| 441 uint32_t NameIndex = 0; | |
| 442 for (Ice::FunctionDeclaration *Func : FunctionDeclarationList) { | |
| 443 installDeclarationName(Func, FunctionPrefix, "function", NameIndex); | |
| 444 } | |
| 445 } | |
| 446 } | |
| 447 | |
| 448 // Builds a constant symbol named Name, suppressing name mangling if | |
| 449 // SuppressMangling. IsExternal is true iff the symbol is external. | |
| 450 Ice::Constant *getConstantSym(const Ice::IceString &Name, | |
| 451 bool SuppressMangling, bool IsExternal) { | |
| 452 if (IsExternal) { | |
| 453 return getTranslator().getContext()->getConstantExternSym(Name); | |
| 454 } else { | |
| 455 const Ice::RelocOffsetT Offset = 0; | |
| 456 return getTranslator().getContext()->getConstantSym(Offset, Name, | |
| 457 SuppressMangling); | |
| 458 } | |
| 459 } | |
| 460 | |
| 461 // Converts function declarations into constant value IDs. | |
| 462 void createValueIDsForFunctions() { | |
| 463 for (Ice::FunctionDeclaration *Func : FunctionDeclarationList) { | |
|
Jim Stichnoth
2015/02/10 17:47:11
Declare Func as const* if possible.
Karl
2015/02/10 19:30:23
Done.
| |
| 464 Ice::Constant *C = nullptr; | |
| 465 if (!isIRGenerationDisabled()) { | |
| 466 C = getConstantSym(Func->getName(), Func->getSuppressMangling(), | |
| 467 Func->isProto()); | |
| 468 } | |
| 469 ValueIDConstants.push_back(C); | |
| 470 } | |
| 471 } | |
| 472 | |
| 473 // Converts global variable declarations into constant value IDs. | |
| 474 void createValueIDsForGlobalVars() { | |
| 475 for (Ice::VariableDeclaration *Decl : *VariableDeclarations) { | |
|
Jim Stichnoth
2015/02/10 17:47:11
Also declare Decl as const* if possible.
Karl
2015/02/10 19:30:23
Done.
| |
| 476 Ice::Constant *C = nullptr; | |
| 477 if (!isIRGenerationDisabled()) { | |
| 478 C = getConstantSym(Decl->getName(), Decl->getSuppressMangling(), | |
| 479 !Decl->hasInitializer()); | |
| 480 } | |
| 481 ValueIDConstants.push_back(C); | |
| 482 } | |
| 483 } | |
| 484 | |
| 435 // Reports that type ID is undefined, or not of the WantedType. | 485 // Reports that type ID is undefined, or not of the WantedType. |
| 436 void reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty, | 486 void reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty, |
| 437 ExtendedType::TypeKind WantedType); | 487 ExtendedType::TypeKind WantedType); |
| 438 | 488 |
| 439 // Reports that there is no function declaration for ID. Returns an | 489 // Reports that there is no function declaration for ID. Returns an |
| 440 // error recovery value to use. | 490 // error recovery value to use. |
| 441 Ice::FunctionDeclaration *reportGetFunctionByIDError(unsigned ID); | 491 Ice::FunctionDeclaration *reportGetFunctionByIDError(unsigned ID); |
| 442 | 492 |
| 443 // Reports that there is not global variable declaration for | 493 // Reports that there is not global variable declaration for |
| 444 // ID. Returns an error recovery value to use. | 494 // ID. Returns an error recovery value to use. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 487 return FunctionDeclarationList[0]; | 537 return FunctionDeclarationList[0]; |
| 488 report_fatal_error("Unable to continue"); | 538 report_fatal_error("Unable to continue"); |
| 489 } | 539 } |
| 490 | 540 |
| 491 Ice::VariableDeclaration * | 541 Ice::VariableDeclaration * |
| 492 TopLevelParser::reportGetGlobalVariableByIDError(unsigned Index) { | 542 TopLevelParser::reportGetGlobalVariableByIDError(unsigned Index) { |
| 493 std::string Buffer; | 543 std::string Buffer; |
| 494 raw_string_ostream StrBuf(Buffer); | 544 raw_string_ostream StrBuf(Buffer); |
| 495 StrBuf << "Global index " << Index | 545 StrBuf << "Global index " << Index |
| 496 << " not allowed. Out of range. Must be less than " | 546 << " not allowed. Out of range. Must be less than " |
| 497 << VariableDeclarations.size(); | 547 << VariableDeclarations->size(); |
| 498 BlockError(StrBuf.str()); | 548 BlockError(StrBuf.str()); |
| 499 // TODO(kschimpf) Remove error recovery once implementation complete. | 549 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 500 if (!VariableDeclarations.empty()) | 550 if (!VariableDeclarations->empty()) |
| 501 return VariableDeclarations[0]; | 551 return VariableDeclarations->at(0); |
| 502 report_fatal_error("Unable to continue"); | 552 report_fatal_error("Unable to continue"); |
| 503 } | 553 } |
| 504 | 554 |
| 505 Ice::Type TopLevelParser::convertToIceTypeError(Type *LLVMTy) { | 555 Ice::Type TopLevelParser::convertToIceTypeError(Type *LLVMTy) { |
| 506 std::string Buffer; | 556 std::string Buffer; |
| 507 raw_string_ostream StrBuf(Buffer); | 557 raw_string_ostream StrBuf(Buffer); |
| 508 StrBuf << "Invalid LLVM type: " << *LLVMTy; | 558 StrBuf << "Invalid LLVM type: " << *LLVMTy; |
| 509 Error(StrBuf.str()); | 559 Error(StrBuf.str()); |
| 510 return Ice::IceType_void; | 560 return Ice::IceType_void; |
| 511 } | 561 } |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1153 void setNextLocalInstIndex(Ice::Operand *Op) { | 1203 void setNextLocalInstIndex(Ice::Operand *Op) { |
| 1154 setOperand(NextLocalInstIndex++, Op); | 1204 setOperand(NextLocalInstIndex++, Op); |
| 1155 } | 1205 } |
| 1156 | 1206 |
| 1157 // Set the next constant ID to the given constant C. | 1207 // Set the next constant ID to the given constant C. |
| 1158 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); } | 1208 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); } |
| 1159 | 1209 |
| 1160 // Returns the value referenced by the given value Index. | 1210 // Returns the value referenced by the given value Index. |
| 1161 Ice::Operand *getOperand(uint32_t Index) { | 1211 Ice::Operand *getOperand(uint32_t Index) { |
| 1162 if (Index < CachedNumGlobalValueIDs) { | 1212 if (Index < CachedNumGlobalValueIDs) { |
| 1163 return Context->getOrCreateGlobalConstantByID(Index); | 1213 return Context->getGlobalConstantByID(Index); |
| 1164 } | 1214 } |
| 1165 uint32_t LocalIndex = Index - CachedNumGlobalValueIDs; | 1215 uint32_t LocalIndex = Index - CachedNumGlobalValueIDs; |
| 1166 if (LocalIndex >= LocalOperands.size()) { | 1216 if (LocalIndex >= LocalOperands.size()) { |
| 1167 std::string Buffer; | 1217 std::string Buffer; |
| 1168 raw_string_ostream StrBuf(Buffer); | 1218 raw_string_ostream StrBuf(Buffer); |
| 1169 StrBuf << "Value index " << Index << " not defined!"; | 1219 StrBuf << "Value index " << Index << " not defined!"; |
| 1170 Error(StrBuf.str()); | 1220 Error(StrBuf.str()); |
| 1171 report_fatal_error("Unable to continue"); | 1221 report_fatal_error("Unable to continue"); |
| 1172 } | 1222 } |
| 1173 Ice::Operand *Op = LocalOperands[LocalIndex]; | 1223 Ice::Operand *Op = LocalOperands[LocalIndex]; |
| (...skipping 1627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2801 // True if we have already installed names for unnamed global declarations, | 2851 // True if we have already installed names for unnamed global declarations, |
| 2802 // and have generated global constant initializers. | 2852 // and have generated global constant initializers. |
| 2803 bool GlobalDeclarationNamesAndInitializersInstalled; | 2853 bool GlobalDeclarationNamesAndInitializersInstalled; |
| 2804 | 2854 |
| 2805 // Generates names for unnamed global addresses (i.e. functions and | 2855 // Generates names for unnamed global addresses (i.e. functions and |
| 2806 // global variables). Then lowers global variable declaration | 2856 // global variables). Then lowers global variable declaration |
| 2807 // initializers to the target. May be called multiple times. Only | 2857 // initializers to the target. May be called multiple times. Only |
| 2808 // the first call will do the installation. | 2858 // the first call will do the installation. |
| 2809 void InstallGlobalNamesAndGlobalVarInitializers() { | 2859 void InstallGlobalNamesAndGlobalVarInitializers() { |
| 2810 if (!GlobalDeclarationNamesAndInitializersInstalled) { | 2860 if (!GlobalDeclarationNamesAndInitializersInstalled) { |
| 2811 Ice::Translator &Trans = getTranslator(); | 2861 Context->installGlobalNames(); |
| 2812 const Ice::IceString &GlobalPrefix = getFlags().getDefaultGlobalPrefix(); | 2862 Context->createValueIDs(); |
| 2813 if (!GlobalPrefix.empty()) { | 2863 std::unique_ptr<Ice::VariableDeclarationList> DeclsPtr = |
| 2814 uint32_t NameIndex = 0; | 2864 Context->getGlobalVariables(); |
| 2815 for (Ice::VariableDeclaration *Var : Context->getGlobalVariables()) { | 2865 const Ice::VariableDeclarationList &Decls = *DeclsPtr; |
| 2816 installDeclarationName(Trans, Var, GlobalPrefix, "global", NameIndex); | 2866 getTranslator().lowerGlobals(Decls); |
| 2817 } | |
| 2818 } | |
| 2819 const Ice::IceString &FunctionPrefix = | |
| 2820 getFlags().getDefaultFunctionPrefix(); | |
| 2821 if (!FunctionPrefix.empty()) { | |
| 2822 uint32_t NameIndex = 0; | |
| 2823 for (Ice::FunctionDeclaration *Func : | |
| 2824 Context->getFunctionDeclarationList()) { | |
| 2825 installDeclarationName(Trans, Func, FunctionPrefix, "function", | |
| 2826 NameIndex); | |
| 2827 } | |
| 2828 } | |
| 2829 getTranslator().lowerGlobals(Context->getGlobalVariables()); | |
| 2830 GlobalDeclarationNamesAndInitializersInstalled = true; | 2867 GlobalDeclarationNamesAndInitializersInstalled = true; |
| 2831 } | 2868 } |
| 2832 } | 2869 } |
| 2833 | |
| 2834 void installDeclarationName(Ice::Translator &Trans, | |
| 2835 Ice::GlobalDeclaration *Decl, | |
| 2836 const Ice::IceString &Prefix, const char *Context, | |
| 2837 uint32_t &NameIndex) { | |
| 2838 if (!Decl->hasName()) { | |
| 2839 Decl->setName(Trans.createUnnamedName(Prefix, NameIndex)); | |
| 2840 ++NameIndex; | |
| 2841 } else { | |
| 2842 Trans.checkIfUnnamedNameSafe(Decl->getName(), Context, Prefix); | |
| 2843 } | |
| 2844 } | |
| 2845 | |
| 2846 bool ParseBlock(unsigned BlockID) override; | 2870 bool ParseBlock(unsigned BlockID) override; |
| 2847 | 2871 |
| 2848 void ExitBlock() override { InstallGlobalNamesAndGlobalVarInitializers(); } | 2872 void ExitBlock() override { InstallGlobalNamesAndGlobalVarInitializers(); } |
| 2849 | 2873 |
| 2850 void ProcessRecord() override; | 2874 void ProcessRecord() override; |
| 2851 }; | 2875 }; |
| 2852 | 2876 |
| 2853 class ModuleValuesymtabParser : public ValuesymtabParser { | 2877 class ModuleValuesymtabParser : public ValuesymtabParser { |
| 2854 ModuleValuesymtabParser(const ModuleValuesymtabParser &) = delete; | 2878 ModuleValuesymtabParser(const ModuleValuesymtabParser &) = delete; |
| 2855 void operator=(const ModuleValuesymtabParser &) = delete; | 2879 void operator=(const ModuleValuesymtabParser &) = delete; |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3020 | 3044 |
| 3021 if (TopLevelBlocks != 1) { | 3045 if (TopLevelBlocks != 1) { |
| 3022 errs() << IRFilename | 3046 errs() << IRFilename |
| 3023 << ": Contains more than one module. Found: " << TopLevelBlocks | 3047 << ": Contains more than one module. Found: " << TopLevelBlocks |
| 3024 << "\n"; | 3048 << "\n"; |
| 3025 ErrorStatus.assign(EC_Bitcode); | 3049 ErrorStatus.assign(EC_Bitcode); |
| 3026 } | 3050 } |
| 3027 } | 3051 } |
| 3028 | 3052 |
| 3029 } // end of namespace Ice | 3053 } // end of namespace Ice |
| OLD | NEW |