| 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 4430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4441 | 4441 |
| 4442 TargetGlobalInitX8632::TargetGlobalInitX8632(GlobalContext *Ctx) | 4442 TargetGlobalInitX8632::TargetGlobalInitX8632(GlobalContext *Ctx) |
| 4443 : TargetGlobalInitLowering(Ctx) {} | 4443 : TargetGlobalInitLowering(Ctx) {} |
| 4444 | 4444 |
| 4445 void TargetGlobalInitX8632::lower(const VariableDeclaration &Var) { | 4445 void TargetGlobalInitX8632::lower(const VariableDeclaration &Var) { |
| 4446 | 4446 |
| 4447 Ostream &Str = Ctx->getStrEmit(); | 4447 Ostream &Str = Ctx->getStrEmit(); |
| 4448 | 4448 |
| 4449 const VariableDeclaration::InitializerListType &Initializers = | 4449 const VariableDeclaration::InitializerListType &Initializers = |
| 4450 Var.getInitializers(); | 4450 Var.getInitializers(); |
| 4451 assert(Initializers.size()); | 4451 |
| 4452 bool HasInitializer = Var.hasInitializer(); | 4452 // If external and not initialized, this must be a cross test. |
| 4453 // Don't generate a declaration for such cases. |
| 4454 bool IsExternal = Var.isExternal(); |
| 4455 if (IsExternal && !Var.hasInitializer()) return; |
| 4456 |
| 4457 bool HasNonzeroInitializer = Var.hasNonzeroInitializer(); |
| 4453 bool IsConstant = Var.getIsConstant(); | 4458 bool IsConstant = Var.getIsConstant(); |
| 4454 bool IsExternal = Var.getIsExternal(); | |
| 4455 uint32_t Align = Var.getAlignment(); | 4459 uint32_t Align = Var.getAlignment(); |
| 4456 SizeT Size = Var.getNumBytes(); | 4460 SizeT Size = Var.getNumBytes(); |
| 4457 IceString MangledName = Var.mangleName(Ctx); | 4461 IceString MangledName = Var.mangleName(Ctx); |
| 4458 IceString SectionSuffix = ""; | 4462 IceString SectionSuffix = ""; |
| 4459 if (Ctx->getFlags().DataSections) | 4463 if (Ctx->getFlags().DataSections) |
| 4460 SectionSuffix = "." + MangledName; | 4464 SectionSuffix = "." + MangledName; |
| 4461 | 4465 |
| 4462 Str << "\t.type\t" << MangledName << ",@object\n"; | 4466 Str << "\t.type\t" << MangledName << ",@object\n"; |
| 4463 | 4467 |
| 4464 if (IsConstant) | 4468 if (IsConstant) |
| 4465 Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",@progbits\n"; | 4469 Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",@progbits\n"; |
| 4466 else if (HasInitializer) | 4470 else if (HasNonzeroInitializer) |
| 4467 Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",@progbits\n"; | 4471 Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",@progbits\n"; |
| 4468 else if (IsExternal) | 4472 else if (IsExternal) |
| 4469 Str << "\t.section\t.bss" << SectionSuffix << ",\"aw\",@nobits\n"; | 4473 Str << "\t.section\t.bss" << SectionSuffix << ",\"aw\",@nobits\n"; |
| 4470 // No .section for non-constant + zeroinitializer + internal | 4474 // No .section for non-constant + zeroinitializer + internal |
| 4471 | 4475 |
| 4472 if (IsExternal) | 4476 if (IsExternal) |
| 4473 Str << "\t.globl\t" << MangledName << "\n"; | 4477 Str << "\t.globl\t" << MangledName << "\n"; |
| 4474 else if (!IsConstant && !HasInitializer) | 4478 else if (!IsConstant && !HasNonzeroInitializer) |
| 4475 Str << "\t.local\t" << MangledName << "\n"; | 4479 Str << "\t.local\t" << MangledName << "\n"; |
| 4476 // Internal symbols only get .local when using .comm. | 4480 // Internal symbols only get .local when using .comm. |
| 4477 | 4481 |
| 4478 if ((IsConstant || HasInitializer || IsExternal) && Align > 1) | 4482 if ((IsConstant || HasNonzeroInitializer || IsExternal) && Align > 1) |
| 4479 Str << "\t.align\t" << Align << "\n"; | 4483 Str << "\t.align\t" << Align << "\n"; |
| 4480 // Alignment is part of .comm. | 4484 // Alignment is part of .comm. |
| 4481 | 4485 |
| 4482 if (IsConstant || HasInitializer || IsExternal) | 4486 if (IsConstant || HasNonzeroInitializer || IsExternal) |
| 4483 Str << MangledName << ":\n"; | 4487 Str << MangledName << ":\n"; |
| 4484 else | 4488 else |
| 4485 Str << "\t.comm\t" << MangledName << "," << Size << "," << Align << "\n"; | 4489 Str << "\t.comm\t" << MangledName << "," << Size << "," << Align << "\n"; |
| 4486 | 4490 |
| 4487 if (HasInitializer) { | 4491 if (HasNonzeroInitializer) { |
| 4488 for (VariableDeclaration::Initializer *Init : Initializers) { | 4492 for (VariableDeclaration::Initializer *Init : Initializers) { |
| 4489 switch (Init->getKind()) { | 4493 switch (Init->getKind()) { |
| 4490 case VariableDeclaration::Initializer::DataInitializerKind: { | 4494 case VariableDeclaration::Initializer::DataInitializerKind: { |
| 4491 const auto Data = llvm::cast<VariableDeclaration::DataInitializer>(Init) | 4495 const auto Data = llvm::cast<VariableDeclaration::DataInitializer>(Init) |
| 4492 ->getContents(); | 4496 ->getContents(); |
| 4493 for (SizeT i = 0; i < Init->getNumBytes(); ++i) { | 4497 for (SizeT i = 0; i < Init->getNumBytes(); ++i) { |
| 4494 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; | 4498 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; |
| 4495 } | 4499 } |
| 4496 break; | 4500 break; |
| 4497 } | 4501 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 4519 Init->dump(StrBuf); | 4523 Init->dump(StrBuf); |
| 4520 llvm::report_fatal_error(StrBuf.str()); | 4524 llvm::report_fatal_error(StrBuf.str()); |
| 4521 break; | 4525 break; |
| 4522 } | 4526 } |
| 4523 } | 4527 } |
| 4524 } | 4528 } |
| 4525 } else if (IsConstant || IsExternal) | 4529 } else if (IsConstant || IsExternal) |
| 4526 Str << "\t.zero\t" << Size << "\n"; | 4530 Str << "\t.zero\t" << Size << "\n"; |
| 4527 // Size is part of .comm. | 4531 // Size is part of .comm. |
| 4528 | 4532 |
| 4529 if (IsConstant || HasInitializer || IsExternal) | 4533 if (IsConstant || HasNonzeroInitializer || IsExternal) |
| 4530 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; | 4534 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; |
| 4531 // Size is part of .comm. | 4535 // Size is part of .comm. |
| 4532 } | 4536 } |
| 4533 | 4537 |
| 4534 } // end of namespace Ice | 4538 } // end of namespace Ice |
| OLD | NEW |