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

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 codereview 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
« no previous file with comments | « src/IceTargetLowering.h ('k') | src/IceTargetLoweringARM32.h » ('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/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 whether to use SectionSuffix or MangledVarName as
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 return "";
459 }
460
461 if (DataSections) {
462 // With data sections we don't need to use the SectionSuffix.
463 return "." + MangledVarName;
464 }
465
466 assert(!SectionSuffix.empty());
467 return "." + SectionSuffix;
468 }
469
470 } // end of anonymous namespace
471
472 void TargetDataLowering::emitGlobal(const VariableDeclaration &Var,
473 const IceString &SectionSuffix) {
450 if (!ALLOW_DUMP) 474 if (!ALLOW_DUMP)
451 return; 475 return;
452 476
453 // If external and not initialized, this must be a cross test. 477 // If external and not initialized, this must be a cross test.
454 // Don't generate a declaration for such cases. 478 // Don't generate a declaration for such cases.
455 bool IsExternal = Var.isExternal() || Ctx->getFlags().getDisableInternal(); 479 const bool IsExternal =
480 Var.isExternal() || Ctx->getFlags().getDisableInternal();
456 if (IsExternal && !Var.hasInitializer()) 481 if (IsExternal && !Var.hasInitializer())
457 return; 482 return;
458 483
459 Ostream &Str = Ctx->getStrEmit(); 484 Ostream &Str = Ctx->getStrEmit();
460 const VariableDeclaration::InitializerListType &Initializers = 485 const bool HasNonzeroInitializer = Var.hasNonzeroInitializer();
461 Var.getInitializers(); 486 const bool IsConstant = Var.getIsConstant();
462 bool HasNonzeroInitializer = Var.hasNonzeroInitializer(); 487 const SizeT Size = Var.getNumBytes();
463 bool IsConstant = Var.getIsConstant(); 488 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 489
471 Str << "\t.type\t" << MangledName << ",%object\n"; 490 Str << "\t.type\t" << MangledName << ",%object\n";
472 491
492 const bool UseDataSections = Ctx->getFlags().getDataSections();
493 const IceString Suffix =
494 dataSectionSuffix(SectionSuffix, MangledName, UseDataSections);
473 if (IsConstant) 495 if (IsConstant)
474 Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",%progbits\n"; 496 Str << "\t.section\t.rodata" << Suffix << ",\"a\",%progbits\n";
475 else if (HasNonzeroInitializer) 497 else if (HasNonzeroInitializer)
476 Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",%progbits\n"; 498 Str << "\t.section\t.data" << Suffix << ",\"aw\",%progbits\n";
477 else 499 else
478 Str << "\t.section\t.bss" << SectionSuffix << ",\"aw\",%nobits\n"; 500 Str << "\t.section\t.bss" << Suffix << ",\"aw\",%nobits\n";
479 501
480 if (IsExternal) 502 if (IsExternal)
481 Str << "\t.globl\t" << MangledName << "\n"; 503 Str << "\t.globl\t" << MangledName << "\n";
482 504
505 const uint32_t Align = Var.getAlignment();
483 if (Align > 1) { 506 if (Align > 1) {
484 assert(llvm::isPowerOf2_32(Align)); 507 assert(llvm::isPowerOf2_32(Align));
485 // Use the .p2align directive, since the .align N directive can either 508 // 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. 509 // interpret N as bytes, or power of 2 bytes, depending on the target.
487 Str << "\t.p2align\t" << llvm::Log2_32(Align) << "\n"; 510 Str << "\t.p2align\t" << llvm::Log2_32(Align) << "\n";
488 } 511 }
489 512
490 Str << MangledName << ":\n"; 513 Str << MangledName << ":\n";
491 514
492 if (HasNonzeroInitializer) { 515 if (HasNonzeroInitializer) {
493 for (VariableDeclaration::Initializer *Init : Initializers) { 516 for (VariableDeclaration::Initializer *Init : Var.getInitializers()) {
494 switch (Init->getKind()) { 517 switch (Init->getKind()) {
495 case VariableDeclaration::Initializer::DataInitializerKind: { 518 case VariableDeclaration::Initializer::DataInitializerKind: {
496 const auto Data = llvm::cast<VariableDeclaration::DataInitializer>(Init) 519 const auto &Data = llvm::cast<VariableDeclaration::DataInitializer>(
497 ->getContents(); 520 Init)->getContents();
498 for (SizeT i = 0; i < Init->getNumBytes(); ++i) { 521 for (SizeT i = 0; i < Init->getNumBytes(); ++i) {
499 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; 522 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n";
500 } 523 }
501 break; 524 break;
502 } 525 }
503 case VariableDeclaration::Initializer::ZeroInitializerKind: 526 case VariableDeclaration::Initializer::ZeroInitializerKind:
504 Str << "\t.zero\t" << Init->getNumBytes() << "\n"; 527 Str << "\t.zero\t" << Init->getNumBytes() << "\n";
505 break; 528 break;
506 case VariableDeclaration::Initializer::RelocInitializerKind: { 529 case VariableDeclaration::Initializer::RelocInitializerKind: {
507 const auto Reloc = 530 const auto *Reloc =
508 llvm::cast<VariableDeclaration::RelocInitializer>(Init); 531 llvm::cast<VariableDeclaration::RelocInitializer>(Init);
509 Str << "\t" << getEmit32Directive() << "\t"; 532 Str << "\t" << getEmit32Directive() << "\t";
510 Str << Reloc->getDeclaration()->mangleName(Ctx); 533 Str << Reloc->getDeclaration()->mangleName(Ctx);
511 if (RelocOffsetT Offset = Reloc->getOffset()) { 534 if (RelocOffsetT Offset = Reloc->getOffset()) {
512 if (Offset >= 0 || (Offset == INT32_MIN)) 535 if (Offset >= 0 || (Offset == INT32_MIN))
513 Str << " + " << Offset; 536 Str << " + " << Offset;
514 else 537 else
515 Str << " - " << -Offset; 538 Str << " - " << -Offset;
516 } 539 }
517 Str << "\n"; 540 Str << "\n";
518 break; 541 break;
519 } 542 }
520 } 543 }
521 } 544 }
522 } else 545 } else {
523 // NOTE: for non-constant zero initializers, this is BSS (no bits), 546 // 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 547 // 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 548 // virtual offsets, but the .s writer still needs this .zero and
526 // cannot simply use the .size to advance offsets. 549 // cannot simply use the .size to advance offsets.
527 Str << "\t.zero\t" << Size << "\n"; 550 Str << "\t.zero\t" << Size << "\n";
551 }
528 552
529 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; 553 Str << "\t.size\t" << MangledName << ", " << Size << "\n";
530 } 554 }
531 555
532 std::unique_ptr<TargetHeaderLowering> 556 std::unique_ptr<TargetHeaderLowering>
533 TargetHeaderLowering::createLowering(GlobalContext *Ctx) { 557 TargetHeaderLowering::createLowering(GlobalContext *Ctx) {
534 TargetArch Target = Ctx->getFlags().getTargetArch(); 558 TargetArch Target = Ctx->getFlags().getTargetArch();
535 #define SUBZERO_TARGET(X) \ 559 #define SUBZERO_TARGET(X) \
536 if (Target == Target_##X) \ 560 if (Target == Target_##X) \
537 return TargetHeader##X::create(Ctx); 561 return TargetHeader##X::create(Ctx);
538 #include "llvm/Config/SZTargets.def" 562 #include "llvm/Config/SZTargets.def"
539 563
540 llvm::report_fatal_error("Unsupported target header lowering"); 564 llvm::report_fatal_error("Unsupported target header lowering");
541 } 565 }
542 566
543 TargetHeaderLowering::~TargetHeaderLowering() {} 567 TargetHeaderLowering::~TargetHeaderLowering() {}
544 568
545 } // end of namespace Ice 569 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceTargetLowering.h ('k') | src/IceTargetLoweringARM32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698