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

Side by Side Diff: src/IceTargetLoweringX8632.cpp

Issue 641193002: Introduce the notion of function addresses in Subzero. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nit in test. Created 6 years, 2 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/IceTargetLoweringX8632.h ('k') | src/IceTranslator.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/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
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 VariableDeclaration &Var) {
4431 bool DisableTranslation) {
4432 if (Ctx->isVerbose()) {
4433 Global.dump(Ctx->getStrDump());
4434 }
4435
4436 if (DisableTranslation)
4437 return;
4438 4431
4439 Ostream &Str = Ctx->getStrEmit(); 4432 Ostream &Str = Ctx->getStrEmit();
4440 4433
4441 // TODO(kschimpf): Don't mangle name if external and uninitialized. This 4434 const VariableDeclaration::InitializerListType &Initializers =
4442 // will allow us to cross test relocations for references to external 4435 Var.getInitializers();
4443 // global variables.
4444
4445 const GlobalAddress::InitializerListType &Initializers =
4446 Global.getInitializers();
4447 assert(Initializers.size()); 4436 assert(Initializers.size());
4448 bool HasInitializer = 4437 bool HasInitializer = Var.hasInitializer();
4449 !(Initializers.size() == 1 && 4438 bool IsConstant = Var.getIsConstant();
4450 llvm::isa<GlobalAddress::ZeroInitializer>(Initializers[0])); 4439 bool IsExternal = Var.getIsExternal();
4451 bool IsConstant = Global.getIsConstant(); 4440 uint32_t Align = Var.getAlignment();
4452 bool IsExternal = !Global.getIsInternal(); 4441 SizeT Size = Var.getNumBytes();
4453 uint32_t Align = Global.getAlignment(); 4442 IceString MangledName = Var.mangleName(Ctx);
4454 SizeT Size = Global.getNumBytes();
4455 IceString MangledName = Ctx->mangleName(Global.getName());
4456 IceString SectionSuffix = ""; 4443 IceString SectionSuffix = "";
4457 if (Ctx->getFlags().DataSections) 4444 if (Ctx->getFlags().DataSections)
4458 SectionSuffix = "." + MangledName; 4445 SectionSuffix = "." + MangledName;
4459 4446
4460 Str << "\t.type\t" << MangledName << ",@object\n"; 4447 Str << "\t.type\t" << MangledName << ",@object\n";
4461 4448
4462 if (IsConstant) 4449 if (IsConstant)
4463 Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",@progbits\n"; 4450 Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",@progbits\n";
4464 else if (HasInitializer) 4451 else if (HasInitializer)
4465 Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",@progbits\n"; 4452 Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",@progbits\n";
(...skipping 10 matching lines...) Expand all
4476 if ((IsConstant || HasInitializer || IsExternal) && Align > 1) 4463 if ((IsConstant || HasInitializer || IsExternal) && Align > 1)
4477 Str << "\t.align\t" << Align << "\n"; 4464 Str << "\t.align\t" << Align << "\n";
4478 // Alignment is part of .comm. 4465 // Alignment is part of .comm.
4479 4466
4480 if (IsConstant || HasInitializer || IsExternal) 4467 if (IsConstant || HasInitializer || IsExternal)
4481 Str << MangledName << ":\n"; 4468 Str << MangledName << ":\n";
4482 else 4469 else
4483 Str << "\t.comm\t" << MangledName << "," << Size << "," << Align << "\n"; 4470 Str << "\t.comm\t" << MangledName << "," << Size << "," << Align << "\n";
4484 4471
4485 if (HasInitializer) { 4472 if (HasInitializer) {
4486 for (GlobalAddress::Initializer *Init : Initializers) { 4473 for (VariableDeclaration::Initializer *Init : Initializers) {
4487 switch (Init->getKind()) { 4474 switch (Init->getKind()) {
4488 case GlobalAddress::Initializer::DataInitializerKind: { 4475 case VariableDeclaration::Initializer::DataInitializerKind: {
4489 const auto Data = 4476 const auto Data = llvm::cast<VariableDeclaration::DataInitializer>(Init)
4490 llvm::cast<GlobalAddress::DataInitializer>(Init)->getContents(); 4477 ->getContents();
4491 for (SizeT i = 0; i < Init->getNumBytes(); ++i) { 4478 for (SizeT i = 0; i < Init->getNumBytes(); ++i) {
4492 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; 4479 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n";
4493 } 4480 }
4494 break; 4481 break;
4495 } 4482 }
4496 case GlobalAddress::Initializer::ZeroInitializerKind: 4483 case VariableDeclaration::Initializer::ZeroInitializerKind:
4497 Str << "\t.zero\t" << Init->getNumBytes() << "\n"; 4484 Str << "\t.zero\t" << Init->getNumBytes() << "\n";
4498 break; 4485 break;
4499 case GlobalAddress::Initializer::RelocInitializerKind: { 4486 case VariableDeclaration::Initializer::RelocInitializerKind: {
4500 const auto Reloc = llvm::cast<GlobalAddress::RelocInitializer>(Init); 4487 const auto Reloc =
4488 llvm::cast<VariableDeclaration::RelocInitializer>(Init);
4501 Str << "\t.long\t"; 4489 Str << "\t.long\t";
4502 // TODO(kschimpf): Once the representation of a relocation has 4490 Str << Reloc->getDeclaration()->mangleName(Ctx);
4503 // been modified to reference the corresponding global 4491 if (VariableDeclaration::RelocOffsetType Offset = Reloc->getOffset()) {
4504 // address, modify to not mangle the name if the global is 4492 if (Offset >= 0 || (Offset == INT32_MIN))
4505 // external and uninitialized. This will allow us to better 4493 Str << " + " << Offset;
4506 // test cross test relocations. 4494 else
4507 Str << Ctx->mangleName(Reloc->getName()); 4495 Str << " - " << -Offset;
4508 if (GlobalAddress::RelocOffsetType Offset = Reloc->getOffset()) {
4509 Str << " + " << Offset;
4510 } 4496 }
4511 Str << "\n"; 4497 Str << "\n";
4512 break; 4498 break;
4513 } 4499 }
4514 default: { 4500 default: {
4515 std::string Buffer; 4501 std::string Buffer;
4516 llvm::raw_string_ostream StrBuf(Buffer); 4502 llvm::raw_string_ostream StrBuf(Buffer);
4517 StrBuf << "Unable to lower initializer: "; 4503 StrBuf << "Unable to lower initializer: ";
4518 Init->dump(StrBuf); 4504 Init->dump(StrBuf);
4519 llvm::report_fatal_error(StrBuf.str()); 4505 llvm::report_fatal_error(StrBuf.str());
4520 break; 4506 break;
4521 } 4507 }
4522 } 4508 }
4523 } 4509 }
4524 } else if (IsConstant || IsExternal) 4510 } else if (IsConstant || IsExternal)
4525 Str << "\t.zero\t" << Size << "\n"; 4511 Str << "\t.zero\t" << Size << "\n";
4526 // Size is part of .comm. 4512 // Size is part of .comm.
4527 4513
4528 if (IsConstant || HasInitializer || IsExternal) 4514 if (IsConstant || HasInitializer || IsExternal)
4529 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; 4515 Str << "\t.size\t" << MangledName << ", " << Size << "\n";
4530 // Size is part of .comm. 4516 // Size is part of .comm.
4531 } 4517 }
4532 4518
4533 } // end of namespace Ice 4519 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceTargetLoweringX8632.h ('k') | src/IceTranslator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698