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

Side by Side Diff: src/IceTargetLowering.cpp

Issue 1179313004: Fix a bug that would cause subzero to fail when --threads=0. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Addresses code review comments. Created 5 years, 6 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/IceTargetLowering.cpp - Basic lowering implementation --===// 1 //===- subzero/src/IceTargetLowering.cpp - Basic lowering implementation --===//
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 skeleton of the TargetLowering class, 10 // This file implements the skeleton of the TargetLowering class,
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 #define SUBZERO_TARGET(X) \ 439 #define SUBZERO_TARGET(X) \
440 if (Target == Target_##X) \ 440 if (Target == Target_##X) \
441 return TargetData##X::create(Ctx); 441 return TargetData##X::create(Ctx);
442 #include "llvm/Config/SZTargets.def" 442 #include "llvm/Config/SZTargets.def"
443 443
444 llvm::report_fatal_error("Unsupported target data lowering"); 444 llvm::report_fatal_error("Unsupported target data lowering");
445 } 445 }
446 446
447 TargetDataLowering::~TargetDataLowering() {} 447 TargetDataLowering::~TargetDataLowering() {}
448 448
449 void TargetDataLowering::emitGlobal(const VariableDeclaration &Var) { 449 namespace {
450
451 // dataSectionSuffix decides wether to use SectionSuffix or MangledVarName as
jvoung (off chromium) 2015/06/16 18:23:10 wether -> whether
John 2015/06/16 19:58:02 Done.
452 // data section suffix. Essentially, when using separate data sections for
453 // globals SectionSuffix is not necessary.
454 IceString dataSectionSuffix(const IceString &SectionSuffix,
455 const IceString &MangledVarName,
456 const bool DataSections) {
457 if (SectionSuffix.empty() && !DataSections) {
458 // Early optimizing the simple case. If no suffix is needed then we should
459 // avoid constructing the ostringstream below.
jvoung (off chromium) 2015/06/16 18:23:10 "ostringstream" ?
John 2015/06/16 19:58:01 Done.
460 return "";
461 }
462
463 if (DataSections) {
464 // With data sections we don't need to use the SectionSuffix.
465 return "." + MangledVarName;
466 }
467
468 assert(!SectionSuffix.empty());
469 return "." + SectionSuffix;
470 }
471
472 } // end of anonymous namespace
473
474 void TargetDataLowering::emitGlobal(const VariableDeclaration &Var,
475 const IceString &SectionSuffix) {
450 if (!ALLOW_DUMP) 476 if (!ALLOW_DUMP)
451 return; 477 return;
452 478
453 // If external and not initialized, this must be a cross test. 479 // If external and not initialized, this must be a cross test.
454 // Don't generate a declaration for such cases. 480 // Don't generate a declaration for such cases.
455 bool IsExternal = Var.isExternal() || Ctx->getFlags().getDisableInternal(); 481 const bool IsExternal =
482 Var.isExternal() || Ctx->getFlags().getDisableInternal();
456 if (IsExternal && !Var.hasInitializer()) 483 if (IsExternal && !Var.hasInitializer())
457 return; 484 return;
458 485
459 Ostream &Str = Ctx->getStrEmit(); 486 Ostream &Str = Ctx->getStrEmit();
460 const VariableDeclaration::InitializerListType &Initializers = 487 const bool HasNonzeroInitializer = Var.hasNonzeroInitializer();
461 Var.getInitializers(); 488 const bool IsConstant = Var.getIsConstant();
462 bool HasNonzeroInitializer = Var.hasNonzeroInitializer(); 489 const SizeT Size = Var.getNumBytes();
463 bool IsConstant = Var.getIsConstant(); 490 const IceString MangledName = Var.mangleName(Ctx);
464 uint32_t Align = Var.getAlignment();
465 SizeT Size = Var.getNumBytes();
466 IceString MangledName = Var.mangleName(Ctx);
467 IceString SectionSuffix = "";
468 if (Ctx->getFlags().getDataSections())
469 SectionSuffix = "." + MangledName;
470 491
471 Str << "\t.type\t" << MangledName << ",%object\n"; 492 Str << "\t.type\t" << MangledName << ",%object\n";
472 493
494 const bool UseDataSections = Ctx->getFlags().getDataSections();
495 const IceString Suffix =
496 dataSectionSuffix(SectionSuffix, MangledName, UseDataSections);
473 if (IsConstant) 497 if (IsConstant)
474 Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",%progbits\n"; 498 Str << "\t.section\t.rodata" << Suffix << ",\"a\",%progbits\n";
475 else if (HasNonzeroInitializer) 499 else if (HasNonzeroInitializer)
476 Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",%progbits\n"; 500 Str << "\t.section\t.data" << Suffix << ",\"aw\",%progbits\n";
477 else 501 else
478 Str << "\t.section\t.bss" << SectionSuffix << ",\"aw\",%nobits\n"; 502 Str << "\t.section\t.bss" << Suffix << ",\"aw\",%nobits\n";
479 503
480 if (IsExternal) 504 if (IsExternal)
481 Str << "\t.globl\t" << MangledName << "\n"; 505 Str << "\t.globl\t" << MangledName << "\n";
482 506
507 const uint32_t Align = Var.getAlignment();
483 if (Align > 1) { 508 if (Align > 1) {
484 assert(llvm::isPowerOf2_32(Align)); 509 assert(llvm::isPowerOf2_32(Align));
485 // Use the .p2align directive, since the .align N directive can either 510 // Use the .p2align directive, since the .align N directive can either
486 // interpret N as bytes, or power of 2 bytes, depending on the target. 511 // interpret N as bytes, or power of 2 bytes, depending on the target.
487 Str << "\t.p2align\t" << llvm::Log2_32(Align) << "\n"; 512 Str << "\t.p2align\t" << llvm::Log2_32(Align) << "\n";
488 } 513 }
489 514
490 Str << MangledName << ":\n"; 515 Str << MangledName << ":\n";
491 516
492 if (HasNonzeroInitializer) { 517 if (HasNonzeroInitializer) {
493 for (VariableDeclaration::Initializer *Init : Initializers) { 518 for (VariableDeclaration::Initializer *Init : Var.getInitializers()) {
494 switch (Init->getKind()) { 519 switch (Init->getKind()) {
495 case VariableDeclaration::Initializer::DataInitializerKind: { 520 case VariableDeclaration::Initializer::DataInitializerKind: {
496 const auto Data = llvm::cast<VariableDeclaration::DataInitializer>(Init) 521 const auto &Data = llvm::cast<VariableDeclaration::DataInitializer>(
497 ->getContents(); 522 Init)->getContents();
498 for (SizeT i = 0; i < Init->getNumBytes(); ++i) { 523 for (SizeT i = 0; i < Init->getNumBytes(); ++i) {
499 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; 524 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n";
500 } 525 }
501 break; 526 break;
502 } 527 }
503 case VariableDeclaration::Initializer::ZeroInitializerKind: 528 case VariableDeclaration::Initializer::ZeroInitializerKind:
504 Str << "\t.zero\t" << Init->getNumBytes() << "\n"; 529 Str << "\t.zero\t" << Init->getNumBytes() << "\n";
505 break; 530 break;
506 case VariableDeclaration::Initializer::RelocInitializerKind: { 531 case VariableDeclaration::Initializer::RelocInitializerKind: {
507 const auto Reloc = 532 const auto *Reloc =
508 llvm::cast<VariableDeclaration::RelocInitializer>(Init); 533 llvm::cast<VariableDeclaration::RelocInitializer>(Init);
509 Str << "\t" << getEmit32Directive() << "\t"; 534 Str << "\t" << getEmit32Directive() << "\t";
510 Str << Reloc->getDeclaration()->mangleName(Ctx); 535 Str << Reloc->getDeclaration()->mangleName(Ctx);
511 if (RelocOffsetT Offset = Reloc->getOffset()) { 536 if (RelocOffsetT Offset = Reloc->getOffset()) {
512 if (Offset >= 0 || (Offset == INT32_MIN)) 537 if (Offset >= 0 || (Offset == INT32_MIN))
513 Str << " + " << Offset; 538 Str << " + " << Offset;
514 else 539 else
515 Str << " - " << -Offset; 540 Str << " - " << -Offset;
516 } 541 }
517 Str << "\n"; 542 Str << "\n";
518 break; 543 break;
519 } 544 }
520 } 545 }
521 } 546 }
522 } else 547 } else {
523 // NOTE: for non-constant zero initializers, this is BSS (no bits), 548 // NOTE: for non-constant zero initializers, this is BSS (no bits),
524 // so an ELF writer would not write to the file, and only track 549 // so an ELF writer would not write to the file, and only track
525 // virtual offsets, but the .s writer still needs this .zero and 550 // virtual offsets, but the .s writer still needs this .zero and
526 // cannot simply use the .size to advance offsets. 551 // cannot simply use the .size to advance offsets.
527 Str << "\t.zero\t" << Size << "\n"; 552 Str << "\t.zero\t" << Size << "\n";
553 }
528 554
529 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; 555 Str << "\t.size\t" << MangledName << ", " << Size << "\n";
530 } 556 }
531 557
532 std::unique_ptr<TargetHeaderLowering> 558 std::unique_ptr<TargetHeaderLowering>
533 TargetHeaderLowering::createLowering(GlobalContext *Ctx) { 559 TargetHeaderLowering::createLowering(GlobalContext *Ctx) {
534 TargetArch Target = Ctx->getFlags().getTargetArch(); 560 TargetArch Target = Ctx->getFlags().getTargetArch();
535 #define SUBZERO_TARGET(X) \ 561 #define SUBZERO_TARGET(X) \
536 if (Target == Target_##X) \ 562 if (Target == Target_##X) \
537 return TargetHeader##X::create(Ctx); 563 return TargetHeader##X::create(Ctx);
538 #include "llvm/Config/SZTargets.def" 564 #include "llvm/Config/SZTargets.def"
539 565
540 llvm::report_fatal_error("Unsupported target header lowering"); 566 llvm::report_fatal_error("Unsupported target header lowering");
541 } 567 }
542 568
543 TargetHeaderLowering::~TargetHeaderLowering() {} 569 TargetHeaderLowering::~TargetHeaderLowering() {}
544 570
545 } // end of namespace Ice 571 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698