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

Side by Side Diff: src/IceTargetLowering.cpp

Issue 1188603002: Move lowerGlobal() from target-specific code to emitGlobal() in generic code. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: .long vs .4byte 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,
11 // specifically invoking the appropriate lowering method for a given 11 // specifically invoking the appropriate lowering method for a given
12 // instruction kind and driving global register allocation. It also 12 // instruction kind and driving global register allocation. It also
13 // implements the non-deleted instruction iteration in 13 // implements the non-deleted instruction iteration in
14 // LoweringContext. 14 // LoweringContext.
15 // 15 //
16 //===----------------------------------------------------------------------===// 16 //===----------------------------------------------------------------------===//
17 17
18 #include "IceAssemblerARM32.h" 18 #include "IceAssemblerARM32.h"
19 #include "IceAssemblerX8632.h" 19 #include "IceAssemblerX8632.h"
20 #include "assembler_mips32.h" 20 #include "assembler_mips32.h"
21 #include "IceCfg.h" // setError() 21 #include "IceCfg.h" // setError()
22 #include "IceCfgNode.h" 22 #include "IceCfgNode.h"
23 #include "IceGlobalInits.h"
23 #include "IceOperand.h" 24 #include "IceOperand.h"
24 #include "IceRegAlloc.h" 25 #include "IceRegAlloc.h"
25 #include "IceTargetLowering.h" 26 #include "IceTargetLowering.h"
26 #include "IceTargetLoweringARM32.h" 27 #include "IceTargetLoweringARM32.h"
27 #include "IceTargetLoweringMIPS32.h" 28 #include "IceTargetLoweringMIPS32.h"
28 #include "IceTargetLoweringX8632.h" 29 #include "IceTargetLoweringX8632.h"
29 30
30 namespace Ice { 31 namespace Ice {
31 32
32 void LoweringContext::init(CfgNode *N) { 33 void LoweringContext::init(CfgNode *N) {
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 #define SUBZERO_TARGET(X) \ 439 #define SUBZERO_TARGET(X) \
439 if (Target == Target_##X) \ 440 if (Target == Target_##X) \
440 return TargetData##X::create(Ctx); 441 return TargetData##X::create(Ctx);
441 #include "llvm/Config/SZTargets.def" 442 #include "llvm/Config/SZTargets.def"
442 443
443 llvm::report_fatal_error("Unsupported target data lowering"); 444 llvm::report_fatal_error("Unsupported target data lowering");
444 } 445 }
445 446
446 TargetDataLowering::~TargetDataLowering() {} 447 TargetDataLowering::~TargetDataLowering() {}
447 448
449 void TargetDataLowering::emitGlobal(const VariableDeclaration &Var) {
450 if (!ALLOW_DUMP)
451 return;
452
453 // If external and not initialized, this must be a cross test.
454 // Don't generate a declaration for such cases.
455 bool IsExternal = Var.isExternal() || Ctx->getFlags().getDisableInternal();
456 if (IsExternal && !Var.hasInitializer())
457 return;
458
459 Ostream &Str = Ctx->getStrEmit();
460 const VariableDeclaration::InitializerListType &Initializers =
461 Var.getInitializers();
462 bool HasNonzeroInitializer = Var.hasNonzeroInitializer();
463 bool IsConstant = Var.getIsConstant();
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
471 Str << "\t.type\t" << MangledName << ",%object\n";
472
473 if (IsConstant)
474 Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",%progbits\n";
475 else if (HasNonzeroInitializer)
476 Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",%progbits\n";
477 else
478 Str << "\t.section\t.bss" << SectionSuffix << ",\"aw\",%nobits\n";
479
480 if (IsExternal)
481 Str << "\t.globl\t" << MangledName << "\n";
482
483 if (Align > 1) {
484 assert(llvm::isPowerOf2_32(Align));
485 // 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.
487 Str << "\t.p2align\t" << llvm::Log2_32(Align) << "\n";
488 }
489
490 Str << MangledName << ":\n";
491
492 if (HasNonzeroInitializer) {
493 for (VariableDeclaration::Initializer *Init : Initializers) {
494 switch (Init->getKind()) {
495 case VariableDeclaration::Initializer::DataInitializerKind: {
496 const auto Data = llvm::cast<VariableDeclaration::DataInitializer>(Init)
497 ->getContents();
498 for (SizeT i = 0; i < Init->getNumBytes(); ++i) {
499 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n";
500 }
501 break;
502 }
503 case VariableDeclaration::Initializer::ZeroInitializerKind:
504 Str << "\t.zero\t" << Init->getNumBytes() << "\n";
505 break;
506 case VariableDeclaration::Initializer::RelocInitializerKind: {
507 const auto Reloc =
508 llvm::cast<VariableDeclaration::RelocInitializer>(Init);
509 Str << "\t" << getEmit32Directive() << "\t";
510 Str << Reloc->getDeclaration()->mangleName(Ctx);
511 if (RelocOffsetT Offset = Reloc->getOffset()) {
512 if (Offset >= 0 || (Offset == INT32_MIN))
513 Str << " + " << Offset;
514 else
515 Str << " - " << -Offset;
516 }
517 Str << "\n";
518 break;
519 }
520 }
521 }
522 } else
523 // 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
525 // virtual offsets, but the .s writer still needs this .zero and
526 // cannot simply use the .size to advance offsets.
527 Str << "\t.zero\t" << Size << "\n";
528
529 Str << "\t.size\t" << MangledName << ", " << Size << "\n";
530 }
531
448 std::unique_ptr<TargetHeaderLowering> 532 std::unique_ptr<TargetHeaderLowering>
449 TargetHeaderLowering::createLowering(GlobalContext *Ctx) { 533 TargetHeaderLowering::createLowering(GlobalContext *Ctx) {
450 TargetArch Target = Ctx->getFlags().getTargetArch(); 534 TargetArch Target = Ctx->getFlags().getTargetArch();
451 #define SUBZERO_TARGET(X) \ 535 #define SUBZERO_TARGET(X) \
452 if (Target == Target_##X) \ 536 if (Target == Target_##X) \
453 return TargetHeader##X::create(Ctx); 537 return TargetHeader##X::create(Ctx);
454 #include "llvm/Config/SZTargets.def" 538 #include "llvm/Config/SZTargets.def"
455 539
456 llvm::report_fatal_error("Unsupported target header lowering"); 540 llvm::report_fatal_error("Unsupported target header lowering");
457 } 541 }
458 542
459 TargetHeaderLowering::~TargetHeaderLowering() {} 543 TargetHeaderLowering::~TargetHeaderLowering() {}
460 544
461 } // end of namespace Ice 545 } // 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