OLD | NEW |
---|---|
1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// | 1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// |
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 TargetLoweringX8632 class, which | 10 // This file implements the TargetLoweringX8632 class, which |
(...skipping 4422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4433 Str << "qword ptr [L$" << IceType_f64 << "$" << getPoolEntryID() << "]"; | 4433 Str << "qword ptr [L$" << IceType_f64 << "$" << getPoolEntryID() << "]"; |
4434 } | 4434 } |
4435 | 4435 |
4436 void ConstantUndef::emit(GlobalContext *) const { | 4436 void ConstantUndef::emit(GlobalContext *) const { |
4437 llvm_unreachable("undef value encountered by emitter."); | 4437 llvm_unreachable("undef value encountered by emitter."); |
4438 } | 4438 } |
4439 | 4439 |
4440 TargetGlobalInitX8632::TargetGlobalInitX8632(GlobalContext *Ctx) | 4440 TargetGlobalInitX8632::TargetGlobalInitX8632(GlobalContext *Ctx) |
4441 : TargetGlobalInitLowering(Ctx) {} | 4441 : TargetGlobalInitLowering(Ctx) {} |
4442 | 4442 |
4443 namespace { | 4443 void TargetGlobalInitX8632::lower(const GlobalAddress &Global, |
Jim Stichnoth
2014/10/03 01:28:08
Could you also implement a -fdata-sections option?
Karl
2014/10/04 16:28:34
Done.
| |
4444 char hexdigit(unsigned X) { return X < 10 ? '0' + X : 'A' + X - 10; } | 4444 bool DisableTranslation) { |
4445 } | |
4446 | |
4447 void TargetGlobalInitX8632::lower(const IceString &Name, SizeT Align, | |
4448 bool IsInternal, bool IsConst, | |
4449 bool IsZeroInitializer, SizeT Size, | |
4450 const char *Data, bool DisableTranslation) { | |
4451 if (Ctx->isVerbose()) { | 4445 if (Ctx->isVerbose()) { |
4452 // TODO: Consider moving the dump output into the driver to be | 4446 // TODO: Consider moving the dump output into the driver to be |
jvoung (off chromium)
2014/10/03 16:15:30
Is this TODO TODONE?
Karl
2014/10/04 16:28:34
Done.
| |
4453 // reused for all targets. | 4447 // reused for all targets. |
4454 Ostream &Str = Ctx->getStrDump(); | 4448 Global.dump(Ctx->getStrDump()); |
4455 Str << "@" << Name << " = " << (IsInternal ? "internal" : "external"); | |
4456 Str << (IsConst ? " constant" : " global"); | |
4457 Str << " [" << Size << " x i8] "; | |
4458 if (IsZeroInitializer) { | |
4459 Str << "zeroinitializer"; | |
4460 } else { | |
4461 Str << "c\""; | |
4462 // Code taken from PrintEscapedString() in AsmWriter.cpp. Keep | |
4463 // the strings in the same format as the .ll file for practical | |
4464 // diffing. | |
4465 for (uint64_t i = 0; i < Size; ++i) { | |
4466 unsigned char C = Data[i]; | |
4467 if (isprint(C) && C != '\\' && C != '"') | |
4468 Str << C; | |
4469 else | |
4470 Str << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F); | |
4471 } | |
4472 Str << "\""; | |
4473 } | |
4474 Str << ", align " << Align << "\n"; | |
4475 } | 4449 } |
4476 | 4450 |
4477 if (DisableTranslation) | 4451 if (DisableTranslation) |
4478 return; | 4452 return; |
4479 | 4453 |
4480 Ostream &Str = Ctx->getStrEmit(); | 4454 Ostream &Str = Ctx->getStrEmit(); |
4481 // constant: | 4455 // constant: |
4482 // .section .rodata,"a",@progbits | 4456 // .section .rodata,"a",@progbits |
4483 // .align ALIGN | 4457 // .align ALIGN |
4484 // .byte ... | 4458 // .byte ... |
4485 // .size NAME, SIZE | 4459 // .size NAME, SIZE |
4486 | 4460 |
4487 // non-constant: | 4461 // non-constant: |
4488 // .data | 4462 // .data |
4489 // .align ALIGN | 4463 // .align ALIGN |
4490 // .byte ... | 4464 // .byte ... |
4491 // .size NAME, SIZE | 4465 // .size NAME, SIZE |
4492 | 4466 |
4493 // zeroinitializer (constant): | 4467 // zeroinitializer (constant): |
4494 // (.section or .data as above) | 4468 // (.section or .data as above) |
4495 // .align ALIGN | 4469 // .align ALIGN |
4496 // .zero SIZE | 4470 // .zero SIZE |
4497 // .size NAME, SIZE | 4471 // .size NAME, SIZE |
4498 | 4472 |
4499 // zeroinitializer (non-constant): | 4473 // zeroinitializer (non-constant): |
4500 // (.section or .data as above) | 4474 // (.section or .data as above) |
4501 // .local NAME | 4475 // .local NAME |
4502 // .comm NAME, SIZE, ALIGN | 4476 // .comm NAME, SIZE, ALIGN |
4503 | 4477 |
4504 IceString MangledName = Ctx->mangleName(Name); | 4478 IceString MangledName = Ctx->mangleName(Global.getName()); |
4505 // Start a new section. | 4479 // Start a new section. |
4506 if (IsConst) { | 4480 if (Global.getIsConstant()) { |
4507 Str << "\t.section\t.rodata,\"a\",@progbits\n"; | 4481 Str << "\t.section\t.rodata,\"a\",@progbits\n"; |
4508 } else { | 4482 } else { |
4509 Str << "\t.type\t" << MangledName << ",@object\n"; | 4483 Str << "\t.type\t" << MangledName << ",@object\n"; |
4510 Str << "\t.data\n"; | 4484 Str << "\t.data\n"; |
4511 } | 4485 } |
4512 Str << "\t" << (IsInternal ? ".local" : ".global") << "\t" << MangledName | 4486 |
4513 << "\n"; | 4487 Str << "\t" << (Global.getIsInternal() ? ".local" : ".global") << "\t" |
4514 if (IsZeroInitializer) { | 4488 << MangledName << "\n"; |
4515 if (IsConst) { | 4489 |
4516 Str << "\t.align\t" << Align << "\n"; | 4490 const GlobalAddress::InitializerListType &Initializers = |
4517 Str << MangledName << ":\n"; | 4491 Global.getInitializers(); |
4518 Str << "\t.zero\t" << Size << "\n"; | 4492 |
4519 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; | 4493 // Note: Handle zero initializations specially when lowering, since |
4520 } else { | 4494 // we may be able to reduce object size. |
4521 // TODO(stichnot): Put the appropriate non-constant | 4495 GlobalAddress::ZeroInitializer *SimpleZeroInit = nullptr; |
4522 // zeroinitializers in a .bss section to reduce object size. | 4496 if (Initializers.size() == 1) { |
4523 Str << "\t.comm\t" << MangledName << ", " << Size << ", " << Align | 4497 GlobalAddress::Initializer *Init = Initializers[0]; |
4524 << "\n"; | 4498 if (GlobalAddress::ZeroInitializer *ZeroInit = |
4499 llvm::dyn_cast<GlobalAddress::ZeroInitializer>(Init)) { | |
4500 SimpleZeroInit = ZeroInit; | |
4525 } | 4501 } |
4502 } | |
4503 | |
4504 if (SimpleZeroInit && !Global.getIsConstant()) { | |
4505 // TODO(stichnot): Put the appropriate non-constant | |
4506 // zeroinitializers in a .bss section to reduce object size. | |
4507 Str << "\t.comm\t" << MangledName << ", " << Global.getNumBytes() << ", " | |
4508 << Global.getAlignment() << "\n"; | |
4509 // } | |
4526 } else { | 4510 } else { |
4527 Str << "\t.align\t" << Align << "\n"; | 4511 Str << "\t.align\t" << Global.getAlignment() << "\n"; |
4528 Str << MangledName << ":\n"; | 4512 Str << MangledName << ":\n"; |
4529 for (SizeT i = 0; i < Size; ++i) { | 4513 for (GlobalAddress::Initializer *Init : Initializers) { |
4530 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; | 4514 switch (Init->getKind()) { |
4515 case GlobalAddress::Initializer::DataInitializerKind: { | |
4516 const GlobalAddress::DataVecType Data = | |
4517 llvm::cast<GlobalAddress::DataInitializer>(Init)->getContents(); | |
4518 for (SizeT i = 0; i < Init->getNumBytes(); ++i) { | |
4519 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; | |
4520 } | |
4521 break; | |
4522 } | |
4523 case GlobalAddress::Initializer::ZeroInitializerKind: | |
4524 Str << "\t.zero\t" << Init->getNumBytes() << "\n"; | |
4525 break; | |
4526 case GlobalAddress::Initializer::RelocInitializerKind: { | |
4527 const GlobalAddress::RelocInitializer *Reloc = | |
4528 llvm::cast<GlobalAddress::RelocInitializer>(Init); | |
4529 Str << "\t.word\t" << Reloc->getName(); | |
Jim Stichnoth
2014/10/03 01:28:08
.long
Karl
2014/10/04 16:28:34
Done.
| |
4530 if (GlobalAddress::RelocOffsetType Offset = Reloc->getOffset()) { | |
4531 Str << " + " << Offset; | |
4532 } | |
4533 Str << "\n"; | |
4534 break; | |
4535 } | |
4536 default: { | |
4537 std::string Buffer; | |
4538 llvm::raw_string_ostream StrBuf(Buffer); | |
4539 StrBuf << "Unable to lower initializer: "; | |
4540 Init->dump(StrBuf); | |
4541 llvm::report_fatal_error(StrBuf.str()); | |
4542 break; | |
4543 } | |
4544 } | |
4531 } | 4545 } |
4532 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; | 4546 Str << "\t.size\t" << MangledName << ", " << Global.getNumBytes() << "\n"; |
4533 } | 4547 } |
4534 } | 4548 } |
4535 | 4549 |
4536 } // end of namespace Ice | 4550 } // end of namespace Ice |
OLD | NEW |