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

Side by Side Diff: src/PNaClTranslator.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/IceTypes.h ('k') | unittest/IceELFSectionTest.cpp » ('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/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 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 if (Ty->getKind() == WantedKind) 466 if (Ty->getKind() == WantedKind)
467 return Ty; 467 return Ty;
468 } 468 }
469 // Generate an error message and set ErrorStatus. 469 // Generate an error message and set ErrorStatus.
470 this->reportBadTypeIDAs(ID, Ty, WantedKind); 470 this->reportBadTypeIDAs(ID, Ty, WantedKind);
471 return nullptr; 471 return nullptr;
472 } 472 }
473 473
474 // Gives Decl a name if it doesn't already have one. Prefix and NameIndex are 474 // Gives Decl a name if it doesn't already have one. Prefix and NameIndex are
475 // used to generate the name. NameIndex is automatically incremented if a new 475 // used to generate the name. NameIndex is automatically incremented if a new
476 // name is created. DeclType is literal text describing the type of name 476 // name is created. DeclType is literal text describing the type of name being
477 // being created. Also generates warning if created names may conflict with 477 // created. Also generates a warning if created names may conflict with named
478 // named declarations. 478 // declarations.
479 void installDeclarationName(Ice::GlobalDeclaration *Decl, 479 void installDeclarationName(Ice::GlobalDeclaration *Decl,
480 const Ice::IceString &Prefix, 480 const std::string &Prefix, const char *DeclType,
481 const char *DeclType,
482 NaClBcIndexSize_t &NameIndex) { 481 NaClBcIndexSize_t &NameIndex) {
483 if (Decl->hasName()) { 482 if (Decl->hasName()) {
484 Translator.checkIfUnnamedNameSafe(Decl->getName(), DeclType, Prefix); 483 Translator.checkIfUnnamedNameSafe(Decl->getName().toString(), DeclType,
484 Prefix);
485 } else { 485 } else {
486 Decl->setName(Translator.createUnnamedName(Prefix, NameIndex)); 486 Ice::GlobalContext *Ctx = Translator.getContext();
487 if (Ice::BuildDefs::dump() || !Decl->isInternal()) {
488 Decl->setName(Ctx, Translator.createUnnamedName(Prefix, NameIndex));
489 } else {
490 Decl->setName(Ctx);
491 }
487 ++NameIndex; 492 ++NameIndex;
488 } 493 }
489 } 494 }
490 495
491 // Installs names for global variables without names. 496 // Installs names for global variables without names.
492 void installGlobalVarNames() { 497 void installGlobalVarNames() {
493 assert(VariableDeclarations); 498 assert(VariableDeclarations);
494 const Ice::IceString &GlobalPrefix = 499 const std::string &GlobalPrefix =
495 getTranslator().getFlags().getDefaultGlobalPrefix(); 500 getTranslator().getFlags().getDefaultGlobalPrefix();
496 if (!GlobalPrefix.empty()) { 501 if (!GlobalPrefix.empty()) {
497 NaClBcIndexSize_t NameIndex = 0; 502 NaClBcIndexSize_t NameIndex = 0;
498 for (Ice::VariableDeclaration *Var : *VariableDeclarations) { 503 for (Ice::VariableDeclaration *Var : *VariableDeclarations) {
499 installDeclarationName(Var, GlobalPrefix, "global", NameIndex); 504 installDeclarationName(Var, GlobalPrefix, "global", NameIndex);
500 } 505 }
501 } 506 }
502 } 507 }
503 508
504 // Installs names for functions without names. 509 // Installs names for functions without names.
505 void installFunctionNames() { 510 void installFunctionNames() {
506 const Ice::IceString &FunctionPrefix = 511 const std::string &FunctionPrefix =
507 getTranslator().getFlags().getDefaultFunctionPrefix(); 512 getTranslator().getFlags().getDefaultFunctionPrefix();
508 if (!FunctionPrefix.empty()) { 513 if (!FunctionPrefix.empty()) {
509 NaClBcIndexSize_t NameIndex = 0; 514 NaClBcIndexSize_t NameIndex = 0;
510 for (Ice::FunctionDeclaration *Func : FunctionDeclarations) { 515 for (Ice::FunctionDeclaration *Func : FunctionDeclarations) {
511 installDeclarationName(Func, FunctionPrefix, "function", NameIndex); 516 installDeclarationName(Func, FunctionPrefix, "function", NameIndex);
512 } 517 }
513 } 518 }
514 } 519 }
515 520
516 // Builds a constant symbol named Name. IsExternal is true iff the symbol is 521 // Builds a constant symbol named Name. IsExternal is true iff the symbol is
517 // external. 522 // external.
518 Ice::Constant *getConstantSym(const Ice::IceString &Name, 523 Ice::Constant *getConstantSym(Ice::GlobalString Name, bool IsExternal) const {
519 bool IsExternal) const { 524 Ice::GlobalContext *Ctx = getTranslator().getContext();
520 if (IsExternal) { 525 if (IsExternal) {
521 return getTranslator().getContext()->getConstantExternSym(Name); 526 return Ctx->getConstantExternSym(Name);
522 } else { 527 } else {
523 const Ice::RelocOffsetT Offset = 0; 528 const Ice::RelocOffsetT Offset = 0;
524 return getTranslator().getContext()->getConstantSym(Offset, Name); 529 return Ctx->getConstantSym(Offset, Name);
525 } 530 }
526 } 531 }
527 532
528 void reportLinkageError(const char *Kind, 533 void reportLinkageError(const char *Kind,
529 const Ice::GlobalDeclaration &Decl) { 534 const Ice::GlobalDeclaration &Decl) {
530 std::string Buffer; 535 std::string Buffer;
531 raw_string_ostream StrBuf(Buffer); 536 raw_string_ostream StrBuf(Buffer);
532 StrBuf << Kind << " " << Decl.getName() 537 StrBuf << Kind << " " << Decl.getName()
533 << " has incorrect linkage: " << Decl.getLinkageName(); 538 << " has incorrect linkage: " << Decl.getLinkageName();
534 if (Decl.isExternal()) 539 if (Decl.isExternal())
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 : BlockParserBaseClass(BlockID, EnclosingParser), 1351 : BlockParserBaseClass(BlockID, EnclosingParser),
1347 Timer(Ice::TimerStack::TT_parseFunctions, getTranslator().getContext()), 1352 Timer(Ice::TimerStack::TT_parseFunctions, getTranslator().getContext()),
1348 Func(nullptr), FcnId(Context->getNextFunctionBlockValueID()), 1353 Func(nullptr), FcnId(Context->getNextFunctionBlockValueID()),
1349 FuncDecl(Context->getFunctionByID(FcnId)), 1354 FuncDecl(Context->getFunctionByID(FcnId)),
1350 CachedNumGlobalValueIDs(Context->getNumGlobalIDs()), 1355 CachedNumGlobalValueIDs(Context->getNumGlobalIDs()),
1351 NextLocalInstIndex(Context->getNumGlobalIDs()) {} 1356 NextLocalInstIndex(Context->getNumGlobalIDs()) {}
1352 1357
1353 bool convertFunction() { 1358 bool convertFunction() {
1354 bool ParserResult; 1359 bool ParserResult;
1355 { 1360 {
1356 Ice::TimerMarker T(getTranslator().getContext(), FuncDecl->getName()); 1361 Ice::TimerMarker T(getTranslator().getContext(),
1362 FuncDecl->getName().toStringOrEmpty());
1357 // Note: The Cfg is created, even when IR generation is disabled. This is 1363 // Note: The Cfg is created, even when IR generation is disabled. This is
1358 // done to install a CfgLocalAllocator for various internal containers. 1364 // done to install a CfgLocalAllocator for various internal containers.
1359 Func = Ice::Cfg::create(getTranslator().getContext(), 1365 Ice::GlobalContext *Ctx = getTranslator().getContext();
1360 getTranslator().getNextSequenceNumber()); 1366 Func = Ice::Cfg::create(Ctx, getTranslator().getNextSequenceNumber());
1361 1367
1362 Ice::CfgLocalAllocatorScope _(Func.get()); 1368 Ice::CfgLocalAllocatorScope _(Func.get());
1363 1369
1364 // TODO(kschimpf) Clean up API to add a function signature to a CFG. 1370 // TODO(kschimpf) Clean up API to add a function signature to a CFG.
1365 const Ice::FuncSigType &Signature = FuncDecl->getSignature(); 1371 const Ice::FuncSigType &Signature = FuncDecl->getSignature();
1366 1372
1367 Func->setFunctionName(FuncDecl->getName()); 1373 Func->setFunctionName(FuncDecl->getName());
1368 Func->setReturnType(Signature.getReturnType()); 1374 Func->setReturnType(Signature.getReturnType());
1369 Func->setInternal(FuncDecl->getLinkage() == GlobalValue::InternalLinkage); 1375 Func->setInternal(FuncDecl->getLinkage() == GlobalValue::InternalLinkage);
1370 CurrentNode = installNextBasicBlock(); 1376 CurrentNode = installNextBasicBlock();
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
2095 Ice::Type ArgType, Ice::Type ParamType) { 2101 Ice::Type ArgType, Ice::Type ParamType) {
2096 if (ArgType != ParamType) { 2102 if (ArgType != ParamType) {
2097 std::string Buffer; 2103 std::string Buffer;
2098 raw_string_ostream StrBuf(Buffer); 2104 raw_string_ostream StrBuf(Buffer);
2099 StrBuf << "Argument " << (Index + 1) << " of " << printName(Fcn) 2105 StrBuf << "Argument " << (Index + 1) << " of " << printName(Fcn)
2100 << " expects " << ParamType << ". Found: " << ArgType; 2106 << " expects " << ParamType << ". Found: " << ArgType;
2101 Error(StrBuf.str()); 2107 Error(StrBuf.str());
2102 } 2108 }
2103 } 2109 }
2104 2110
2105 const Ice::IceString printName(Ice::FunctionDeclaration *Fcn) { 2111 const std::string printName(Ice::FunctionDeclaration *Fcn) {
2106 if (Fcn) 2112 if (Fcn)
2107 return Fcn->getName(); 2113 return Fcn->getName().toString();
2108 return "function"; 2114 return "function";
2109 } 2115 }
2110 }; 2116 };
2111 2117
2112 void FunctionParser::ExitBlock() { 2118 void FunctionParser::ExitBlock() {
2113 // Check if the last instruction in the function was terminating. 2119 // Check if the last instruction in the function was terminating.
2114 if (!InstIsTerminating) { 2120 if (!InstIsTerminating) {
2115 Error("Last instruction in function not terminator"); 2121 Error("Last instruction in function not terminator");
2116 // Recover by inserting an unreachable instruction. 2122 // Recover by inserting an unreachable instruction.
2117 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get())); 2123 CurrentNode->appendInst(Ice::InstUnreachable::create(Func.get()));
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
3045 Ice::GlobalDeclaration *Decl = Context->getGlobalDeclarationByID(Index); 3051 Ice::GlobalDeclaration *Decl = Context->getGlobalDeclarationByID(Index);
3046 if (llvm::isa<Ice::VariableDeclaration>(Decl) && 3052 if (llvm::isa<Ice::VariableDeclaration>(Decl) &&
3047 Decl->isPNaClABIExternalName(Name.str())) { 3053 Decl->isPNaClABIExternalName(Name.str())) {
3048 // Force linkage of (specific) Global Variables be external for the PNaCl 3054 // Force linkage of (specific) Global Variables be external for the PNaCl
3049 // ABI. PNaCl bitcode has a linkage field for Functions, but not for 3055 // ABI. PNaCl bitcode has a linkage field for Functions, but not for
3050 // GlobalVariables (because the latter is not needed for pexes, so it has 3056 // GlobalVariables (because the latter is not needed for pexes, so it has
3051 // been removed). 3057 // been removed).
3052 Decl->setLinkage(llvm::GlobalValue::ExternalLinkage); 3058 Decl->setLinkage(llvm::GlobalValue::ExternalLinkage);
3053 } 3059 }
3054 3060
3055 Decl->setName(StringRef(Name.data(), Name.size())); 3061 // Unconditionally capture the name if it is provided in the input file,
3062 // regardless of whether dump is enabled or whether the symbol is internal vs
3063 // external. This fits in well with the lit tests, and most symbols in a
3064 // conforming pexe are nameless and don't take this path.
3065 Decl->setName(getTranslator().getContext(),
3066 StringRef(Name.data(), Name.size()));
3056 } 3067 }
3057 3068
3058 void ModuleValuesymtabParser::setBbName(NaClBcIndexSize_t Index, 3069 void ModuleValuesymtabParser::setBbName(NaClBcIndexSize_t Index,
3059 StringType &Name) { 3070 StringType &Name) {
3060 reportUnableToAssign("Basic block", Index, Name); 3071 reportUnableToAssign("Basic block", Index, Name);
3061 } 3072 }
3062 3073
3063 bool ModuleParser::ParseBlock(unsigned BlockID) { 3074 bool ModuleParser::ParseBlock(unsigned BlockID) {
3064 switch (BlockID) { 3075 switch (BlockID) {
3065 case naclbitc::BLOCKINFO_BLOCK_ID: 3076 case naclbitc::BLOCKINFO_BLOCK_ID:
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
3210 raw_string_ostream StrBuf(Buffer); 3221 raw_string_ostream StrBuf(Buffer);
3211 StrBuf << IRFilename << ": Does not contain a module!"; 3222 StrBuf << IRFilename << ": Does not contain a module!";
3212 llvm::report_fatal_error(StrBuf.str()); 3223 llvm::report_fatal_error(StrBuf.str());
3213 } 3224 }
3214 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { 3225 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) {
3215 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); 3226 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes");
3216 } 3227 }
3217 } 3228 }
3218 3229
3219 } // end of namespace Ice 3230 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceTypes.h ('k') | unittest/IceELFSectionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698