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

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 nits. 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
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
11 // consists almost entirely of the lowering sequence for each 11 // consists almost entirely of the lowering sequence for each
12 // high-level instruction. It also implements 12 // high-level instruction. It also implements
13 // TargetX8632Fast::postLower() which does the simplest possible 13 // TargetX8632Fast::postLower() which does the simplest possible
14 // register allocation for the "fast" target. 14 // register allocation for the "fast" target.
15 // 15 //
16 //===----------------------------------------------------------------------===// 16 //===----------------------------------------------------------------------===//
17 17
18 #include <stdint.h>
jvoung (off chromium) 2014/10/10 23:01:16 <cstdint> This should come from IceDefs already?
Karl 2014/10/13 17:43:02 Removed.
19
18 #include "llvm/ADT/DenseMap.h" 20 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/Support/CommandLine.h" 21 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Support/MathExtras.h" 22 #include "llvm/Support/MathExtras.h"
21 23
22 #include "IceCfg.h" 24 #include "IceCfg.h"
23 #include "IceCfgNode.h" 25 #include "IceCfgNode.h"
24 #include "IceClFlags.h" 26 #include "IceClFlags.h"
25 #include "IceDefs.h" 27 #include "IceDefs.h"
26 #include "IceGlobalInits.h" 28 #include "IceGlobalInits.h"
27 #include "IceInstX8632.h" 29 #include "IceInstX8632.h"
(...skipping 4392 matching lines...) Expand 10 before | Expand all | Expand 10 after
4420 Str << "qword ptr [L$" << IceType_f64 << "$" << getPoolEntryID() << "]"; 4422 Str << "qword ptr [L$" << IceType_f64 << "$" << getPoolEntryID() << "]";
4421 } 4423 }
4422 4424
4423 void ConstantUndef::emit(GlobalContext *) const { 4425 void ConstantUndef::emit(GlobalContext *) const {
4424 llvm_unreachable("undef value encountered by emitter."); 4426 llvm_unreachable("undef value encountered by emitter.");
4425 } 4427 }
4426 4428
4427 TargetGlobalInitX8632::TargetGlobalInitX8632(GlobalContext *Ctx) 4429 TargetGlobalInitX8632::TargetGlobalInitX8632(GlobalContext *Ctx)
4428 : TargetGlobalInitLowering(Ctx) {} 4430 : TargetGlobalInitLowering(Ctx) {}
4429 4431
4430 void TargetGlobalInitX8632::lower(const GlobalAddress &Global, 4432 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 4433
4439 Ostream &Str = Ctx->getStrEmit(); 4434 Ostream &Str = Ctx->getStrEmit();
4440 4435
4441 // TODO(kschimpf): Don't mangle name if external and uninitialized. This 4436 const VariableDeclaration::InitializerListType &Initializers =
4442 // will allow us to cross test relocations for references to external 4437 Var.getInitializers();
4443 // global variables.
4444
4445 const GlobalAddress::InitializerListType &Initializers =
4446 Global.getInitializers();
4447 assert(Initializers.size()); 4438 assert(Initializers.size());
4448 bool HasInitializer = 4439 bool HasInitializer = Var.hasInitializer();
4449 !(Initializers.size() == 1 && 4440 bool IsConstant = Var.getIsConstant();
4450 llvm::isa<GlobalAddress::ZeroInitializer>(Initializers[0])); 4441 bool IsExternal = Var.getIsExternal();
4451 bool IsConstant = Global.getIsConstant(); 4442 uint32_t Align = Var.getAlignment();
4452 bool IsExternal = !Global.getIsInternal(); 4443 SizeT Size = Var.getNumBytes();
4453 uint32_t Align = Global.getAlignment(); 4444 IceString MangledName = Var.mangleName(Ctx);
4454 SizeT Size = Global.getNumBytes();
4455 IceString MangledName = Ctx->mangleName(Global.getName());
4456 IceString SectionSuffix = ""; 4445 IceString SectionSuffix = "";
4457 if (Ctx->getFlags().DataSections) 4446 if (Ctx->getFlags().DataSections)
4458 SectionSuffix = "." + MangledName; 4447 SectionSuffix = "." + MangledName;
4459 4448
4460 Str << "\t.type\t" << MangledName << ",@object\n"; 4449 Str << "\t.type\t" << MangledName << ",@object\n";
4461 4450
4462 if (IsConstant) 4451 if (IsConstant)
4463 Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",@progbits\n"; 4452 Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",@progbits\n";
4464 else if (HasInitializer) 4453 else if (HasInitializer)
4465 Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",@progbits\n"; 4454 Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",@progbits\n";
(...skipping 10 matching lines...) Expand all
4476 if ((IsConstant || HasInitializer || IsExternal) && Align > 1) 4465 if ((IsConstant || HasInitializer || IsExternal) && Align > 1)
4477 Str << "\t.align\t" << Align << "\n"; 4466 Str << "\t.align\t" << Align << "\n";
4478 // Alignment is part of .comm. 4467 // Alignment is part of .comm.
4479 4468
4480 if (IsConstant || HasInitializer || IsExternal) 4469 if (IsConstant || HasInitializer || IsExternal)
4481 Str << MangledName << ":\n"; 4470 Str << MangledName << ":\n";
4482 else 4471 else
4483 Str << "\t.comm\t" << MangledName << "," << Size << "," << Align << "\n"; 4472 Str << "\t.comm\t" << MangledName << "," << Size << "," << Align << "\n";
4484 4473
4485 if (HasInitializer) { 4474 if (HasInitializer) {
4486 for (GlobalAddress::Initializer *Init : Initializers) { 4475 for (VariableDeclaration::Initializer *Init : Initializers) {
4487 switch (Init->getKind()) { 4476 switch (Init->getKind()) {
4488 case GlobalAddress::Initializer::DataInitializerKind: { 4477 case VariableDeclaration::Initializer::DataInitializerKind: {
4489 const auto Data = 4478 const auto Data = llvm::cast<VariableDeclaration::DataInitializer>(Init)
4490 llvm::cast<GlobalAddress::DataInitializer>(Init)->getContents(); 4479 ->getContents();
4491 for (SizeT i = 0; i < Init->getNumBytes(); ++i) { 4480 for (SizeT i = 0; i < Init->getNumBytes(); ++i) {
4492 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; 4481 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n";
4493 } 4482 }
4494 break; 4483 break;
4495 } 4484 }
4496 case GlobalAddress::Initializer::ZeroInitializerKind: 4485 case VariableDeclaration::Initializer::ZeroInitializerKind:
4497 Str << "\t.zero\t" << Init->getNumBytes() << "\n"; 4486 Str << "\t.zero\t" << Init->getNumBytes() << "\n";
4498 break; 4487 break;
4499 case GlobalAddress::Initializer::RelocInitializerKind: { 4488 case VariableDeclaration::Initializer::RelocInitializerKind: {
4500 const auto Reloc = llvm::cast<GlobalAddress::RelocInitializer>(Init); 4489 const auto Reloc =
4490 llvm::cast<VariableDeclaration::RelocInitializer>(Init);
4501 Str << "\t.long\t"; 4491 Str << "\t.long\t";
4502 // TODO(kschimpf): Once the representation of a relocation has 4492 Str << Reloc->getDeclaration()->mangleName(Ctx);
4503 // been modified to reference the corresponding global 4493 if (VariableDeclaration::RelocOffsetType Offset = Reloc->getOffset()) {
4504 // address, modify to not mangle the name if the global is 4494 if (Offset >= 0 || (Offset == INT32_MIN))
4505 // external and uninitialized. This will allow us to better 4495 Str << " + " << Offset;
4506 // test cross test relocations. 4496 else
4507 Str << Ctx->mangleName(Reloc->getName()); 4497 Str << " - " << -Offset;
4508 if (GlobalAddress::RelocOffsetType Offset = Reloc->getOffset()) {
4509 Str << " + " << Offset;
4510 } 4498 }
4511 Str << "\n"; 4499 Str << "\n";
4512 break; 4500 break;
4513 } 4501 }
4514 default: { 4502 default: {
4515 std::string Buffer; 4503 std::string Buffer;
4516 llvm::raw_string_ostream StrBuf(Buffer); 4504 llvm::raw_string_ostream StrBuf(Buffer);
4517 StrBuf << "Unable to lower initializer: "; 4505 StrBuf << "Unable to lower initializer: ";
4518 Init->dump(StrBuf); 4506 Init->dump(StrBuf);
4519 llvm::report_fatal_error(StrBuf.str()); 4507 llvm::report_fatal_error(StrBuf.str());
4520 break; 4508 break;
4521 } 4509 }
4522 } 4510 }
4523 } 4511 }
4524 } else if (IsConstant || IsExternal) 4512 } else if (IsConstant || IsExternal)
4525 Str << "\t.zero\t" << Size << "\n"; 4513 Str << "\t.zero\t" << Size << "\n";
4526 // Size is part of .comm. 4514 // Size is part of .comm.
4527 4515
4528 if (IsConstant || HasInitializer || IsExternal) 4516 if (IsConstant || HasInitializer || IsExternal)
4529 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; 4517 Str << "\t.size\t" << MangledName << ", " << Size << "\n";
4530 // Size is part of .comm. 4518 // Size is part of .comm.
4531 } 4519 }
4532 4520
4533 } // end of namespace Ice 4521 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698