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