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 4409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4420 Str << "qword ptr [L$" << IceType_f64 << "$" << getPoolEntryID() << "]"; | 4420 Str << "qword ptr [L$" << IceType_f64 << "$" << getPoolEntryID() << "]"; |
4421 } | 4421 } |
4422 | 4422 |
4423 void ConstantUndef::emit(GlobalContext *) const { | 4423 void ConstantUndef::emit(GlobalContext *) const { |
4424 llvm_unreachable("undef value encountered by emitter."); | 4424 llvm_unreachable("undef value encountered by emitter."); |
4425 } | 4425 } |
4426 | 4426 |
4427 TargetGlobalInitX8632::TargetGlobalInitX8632(GlobalContext *Ctx) | 4427 TargetGlobalInitX8632::TargetGlobalInitX8632(GlobalContext *Ctx) |
4428 : TargetGlobalInitLowering(Ctx) {} | 4428 : TargetGlobalInitLowering(Ctx) {} |
4429 | 4429 |
4430 void TargetGlobalInitX8632::lower(const GlobalAddress &Global, | 4430 void TargetGlobalInitX8632::lower(const GlobalVariable &Global, |
4431 bool DisableTranslation) { | 4431 bool DisableTranslation) { |
4432 if (Ctx->isVerbose()) { | 4432 if (Ctx->isVerbose()) { |
4433 Global.dump(Ctx->getStrDump()); | 4433 Global.dump(Ctx->getStrDump()); |
4434 } | 4434 } |
4435 | 4435 |
4436 if (DisableTranslation) | 4436 if (DisableTranslation) |
4437 return; | 4437 return; |
4438 | 4438 |
4439 Ostream &Str = Ctx->getStrEmit(); | 4439 Ostream &Str = Ctx->getStrEmit(); |
4440 | 4440 |
4441 // TODO(kschimpf): Don't mangle name if external and uninitialized. This | 4441 // TODO(kschimpf): Don't mangle name if external and uninitialized. This |
4442 // will allow us to cross test relocations for references to external | 4442 // will allow us to cross test relocations for references to external |
4443 // global variables. | 4443 // global variables. |
4444 | 4444 |
4445 const GlobalAddress::InitializerListType &Initializers = | 4445 const GlobalVariable::InitializerListType &Initializers = |
4446 Global.getInitializers(); | 4446 Global.getInitializers(); |
4447 assert(Initializers.size()); | 4447 assert(Initializers.size()); |
4448 bool HasInitializer = | 4448 bool HasInitializer = Global.hasInitializer(); |
4449 !(Initializers.size() == 1 && | |
4450 llvm::isa<GlobalAddress::ZeroInitializer>(Initializers[0])); | |
4451 bool IsConstant = Global.getIsConstant(); | 4449 bool IsConstant = Global.getIsConstant(); |
4452 bool IsExternal = !Global.getIsInternal(); | 4450 bool IsExternal = Global.getIsExternal(); |
4453 uint32_t Align = Global.getAlignment(); | 4451 uint32_t Align = Global.getAlignment(); |
4454 SizeT Size = Global.getNumBytes(); | 4452 SizeT Size = Global.getNumBytes(); |
4455 IceString MangledName = Ctx->mangleName(Global.getName()); | 4453 IceString MangledName = Global.mangleName(Ctx); |
4456 IceString SectionSuffix = ""; | 4454 IceString SectionSuffix = ""; |
4457 if (Ctx->getFlags().DataSections) | 4455 if (Ctx->getFlags().DataSections) |
4458 SectionSuffix = "." + MangledName; | 4456 SectionSuffix = "." + MangledName; |
4459 | 4457 |
4460 Str << "\t.type\t" << MangledName << ",@object\n"; | 4458 Str << "\t.type\t" << MangledName << ",@object\n"; |
4461 | 4459 |
4462 if (IsConstant) | 4460 if (IsConstant) |
4463 Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",@progbits\n"; | 4461 Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",@progbits\n"; |
4464 else if (HasInitializer) | 4462 else if (HasInitializer) |
4465 Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",@progbits\n"; | 4463 Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",@progbits\n"; |
(...skipping 10 matching lines...) Expand all Loading... |
4476 if ((IsConstant || HasInitializer || IsExternal) && Align > 1) | 4474 if ((IsConstant || HasInitializer || IsExternal) && Align > 1) |
4477 Str << "\t.align\t" << Align << "\n"; | 4475 Str << "\t.align\t" << Align << "\n"; |
4478 // Alignment is part of .comm. | 4476 // Alignment is part of .comm. |
4479 | 4477 |
4480 if (IsConstant || HasInitializer || IsExternal) | 4478 if (IsConstant || HasInitializer || IsExternal) |
4481 Str << MangledName << ":\n"; | 4479 Str << MangledName << ":\n"; |
4482 else | 4480 else |
4483 Str << "\t.comm\t" << MangledName << "," << Size << "," << Align << "\n"; | 4481 Str << "\t.comm\t" << MangledName << "," << Size << "," << Align << "\n"; |
4484 | 4482 |
4485 if (HasInitializer) { | 4483 if (HasInitializer) { |
4486 for (GlobalAddress::Initializer *Init : Initializers) { | 4484 for (GlobalVariable::Initializer *Init : Initializers) { |
4487 switch (Init->getKind()) { | 4485 switch (Init->getKind()) { |
4488 case GlobalAddress::Initializer::DataInitializerKind: { | 4486 case GlobalVariable::Initializer::DataInitializerKind: { |
4489 const auto Data = | 4487 const auto Data = |
4490 llvm::cast<GlobalAddress::DataInitializer>(Init)->getContents(); | 4488 llvm::cast<GlobalVariable::DataInitializer>(Init)->getContents(); |
4491 for (SizeT i = 0; i < Init->getNumBytes(); ++i) { | 4489 for (SizeT i = 0; i < Init->getNumBytes(); ++i) { |
4492 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; | 4490 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; |
4493 } | 4491 } |
4494 break; | 4492 break; |
4495 } | 4493 } |
4496 case GlobalAddress::Initializer::ZeroInitializerKind: | 4494 case GlobalVariable::Initializer::ZeroInitializerKind: |
4497 Str << "\t.zero\t" << Init->getNumBytes() << "\n"; | 4495 Str << "\t.zero\t" << Init->getNumBytes() << "\n"; |
4498 break; | 4496 break; |
4499 case GlobalAddress::Initializer::RelocInitializerKind: { | 4497 case GlobalVariable::Initializer::RelocInitializerKind: { |
4500 const auto Reloc = llvm::cast<GlobalAddress::RelocInitializer>(Init); | 4498 const auto Reloc = llvm::cast<GlobalVariable::RelocInitializer>(Init); |
4501 Str << "\t.long\t"; | 4499 Str << "\t.long\t"; |
4502 // TODO(kschimpf): Once the representation of a relocation has | 4500 const GlobalAddress *RelocAddr = Reloc->getAddress(); |
4503 // been modified to reference the corresponding global | 4501 Str << RelocAddr->mangleName(Ctx); |
4504 // address, modify to not mangle the name if the global is | 4502 if (GlobalVariable::RelocOffsetType Offset = Reloc->getOffset()) { |
4505 // external and uninitialized. This will allow us to better | |
4506 // test cross test relocations. | |
4507 Str << Ctx->mangleName(Reloc->getName()); | |
4508 if (GlobalAddress::RelocOffsetType Offset = Reloc->getOffset()) { | |
4509 Str << " + " << Offset; | 4503 Str << " + " << Offset; |
4510 } | 4504 } |
4511 Str << "\n"; | 4505 Str << "\n"; |
4512 break; | 4506 break; |
4513 } | 4507 } |
4514 default: { | 4508 default: { |
4515 std::string Buffer; | 4509 std::string Buffer; |
4516 llvm::raw_string_ostream StrBuf(Buffer); | 4510 llvm::raw_string_ostream StrBuf(Buffer); |
4517 StrBuf << "Unable to lower initializer: "; | 4511 StrBuf << "Unable to lower initializer: "; |
4518 Init->dump(StrBuf); | 4512 Init->dump(StrBuf); |
4519 llvm::report_fatal_error(StrBuf.str()); | 4513 llvm::report_fatal_error(StrBuf.str()); |
4520 break; | 4514 break; |
4521 } | 4515 } |
4522 } | 4516 } |
4523 } | 4517 } |
4524 } else if (IsConstant || IsExternal) | 4518 } else if (IsConstant || IsExternal) |
4525 Str << "\t.zero\t" << Size << "\n"; | 4519 Str << "\t.zero\t" << Size << "\n"; |
4526 // Size is part of .comm. | 4520 // Size is part of .comm. |
4527 | 4521 |
4528 if (IsConstant || HasInitializer || IsExternal) | 4522 if (IsConstant || HasInitializer || IsExternal) |
4529 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; | 4523 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; |
4530 // Size is part of .comm. | 4524 // Size is part of .comm. |
4531 } | 4525 } |
4532 | 4526 |
4533 } // end of namespace Ice | 4527 } // end of namespace Ice |
OLD | NEW |