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

Unified Diff: src/IceTargetLoweringX8632.cpp

Issue 358013003: Subzero: Partial implementation of global initializers. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Run "make format" on the new cross tests Created 6 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: src/IceTargetLoweringX8632.cpp
diff --git a/src/IceTargetLoweringX8632.cpp b/src/IceTargetLoweringX8632.cpp
index ef9bc22f525087d8ac85bd66b4824871ba58fbab..987a59669430e1fed3b153fdb5d16873750bc6af 100644
--- a/src/IceTargetLoweringX8632.cpp
+++ b/src/IceTargetLoweringX8632.cpp
@@ -1319,7 +1319,9 @@ void TargetX8632::lowerCall(const InstCall *Instr) {
break;
}
}
- Operand *CallTarget = legalize(Instr->getCallTarget());
+ // TODO(stichnot): LEAHACK: remove Legal_All (and use default) once
+ // a proper emitter is used.
+ Operand *CallTarget = legalize(Instr->getCallTarget(), Legal_All);
Inst *NewCall = InstX8632Call::create(Func, eax, CallTarget);
Context.insert(NewCall);
if (edx)
@@ -2447,6 +2449,9 @@ Operand *TargetX8632::legalize(Operand *From, LegalMask Allowed,
}
bool NeedsReg =
!(Allowed & Legal_Imm) ||
+ // TODO(stichnot): LEAHACK: remove Legal_Reloc once a proper
+ // emitter is used.
wala 2014/06/27 21:35:25 The condition logic for NeedsReg is starting to ge
Jim Stichnoth 2014/06/28 00:28:13 I made at least a slight improvement by breaking i
+ (!(Allowed & Legal_Reloc) && llvm::isa<ConstantRelocatable>(From)) ||
// ConstantFloat and ConstantDouble are actually memory operands.
(!(Allowed & Legal_Mem) &&
(From->getType() == IceType_f32 || From->getType() == IceType_f64));
@@ -2581,4 +2586,87 @@ template <> void ConstantDouble::emit(GlobalContext *Ctx) const {
Str << "qword ptr [L$" << IceType_f64 << "$" << getPoolEntryID() << "]";
}
+TargetGlobalInitX8632::TargetGlobalInitX8632(GlobalContext *Ctx)
+ : TargetGlobalInitLowering(Ctx) {}
+
+namespace {
+char hexdigit(unsigned X) { return X < 10 ? '0' + X : 'A' + X - 10; }
+}
+
+void TargetGlobalInitX8632::lower(const IceString &Name, SizeT Align,
+ bool IsInternal, bool IsConst,
+ bool IsZeroInitializer, SizeT Size,
+ const char *Data, bool DisableTranslation) {
+ if (Ctx->isVerbose()) {
+ // TODO: Consider moving the dump output into the driver to be
+ // reused for all targets.
+ Ostream &Str = Ctx->getStrDump();
+ Str << "@" << Name << " =" << (IsInternal ? " internal" : "");
+ if (IsConst)
+ Str << " constant";
+ else
+ Str << " global";
wala 2014/06/27 21:35:25 Maybe Str << (IsConst ? " constant" : " global");
Jim Stichnoth 2014/06/28 00:28:13 Done.
+ Str << " [" << Size << " x i8] ";
+ if (IsZeroInitializer) {
+ Str << "zeroinitializer";
+ } else {
+ Str << "c\"";
+ // Code taken from PrintEscapedString() in AsmWriter.cpp. Keep
+ // the strings in the same format as the .ll file for practical
+ // diffing.
+ for (uint64_t i = 0; i < Size; ++i) {
+ unsigned char C = Data[i];
+ if (isprint(C) && C != '\\' && C != '"')
+ Str << C;
+ else
+ Str << '\\' << hexdigit(C >> 4) << hexdigit(C & 0x0F);
+ }
+ Str << "\"";
+ }
+ Str << ", align " << Align << "\n";
+ }
+
+ if (DisableTranslation)
+ return;
+
+ Ostream &Str = Ctx->getStrEmit();
+ // constant:
+ // .section .rodata,"a",@progbits
+ // .align ALIGN
+ // .byte ...
+ // .size NAME, SIZE
+
+ // non-constant:
+ // .data
+ // .align ALIGN
+ // .byte ...
+ // .size NAME, SIZE
+
+ // zeroinitializer:
+ // (.section or .data as above)
+ // .comm NAME, SIZE, ALIGN
jvoung (off chromium) 2014/06/27 19:29:27 Should this be in a .bss instead? Then it can take
Jim Stichnoth 2014/06/28 00:28:13 You may be right, but I haven't yet been able to p
jvoung (off chromium) 2014/06/28 17:00:32 Okay, what you had is right. The difference betwee
Jim Stichnoth 2014/06/29 14:33:46 Added a TODO for now about using a .bss section.
+ // .local NAME
+
+ IceString MangledName = Ctx->mangleName(Name);
+ // Start a new section.
+ if (IsConst) {
+ Str << "\t.section\t.rodata,\"a\",@progbits\n";
+ } else {
+ // Str << "\t.globl\t" << MangledName << "\n";
jvoung (off chromium) 2014/06/28 17:00:32 If we want to support "external" for cross-testing
Jim Stichnoth 2014/06/29 14:33:46 Changed the emission to unconditionally emit .loca
+ Str << "\t.type\t" << MangledName << ",@object\n";
+ Str << "\t.data\n";
+ }
+ if (IsZeroInitializer) {
+ Str << "\t.comm\t" << MangledName << ", " << Size << ", " << Align << "\n";
+ Str << "\t.local\t" << MangledName << "\n";
+ } else {
+ Str << "\t.align\t" << Align << "\n";
+ Str << MangledName << ":\n";
+ for (SizeT i = 0; i < Size; ++i) {
+ Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n";
+ }
+ Str << "\t.size\t" << MangledName << ", " << Size << "\n";
+ }
+}
+
} // end of namespace Ice
« no previous file with comments | « src/IceTargetLoweringX8632.h ('k') | src/llvm2ice.cpp » ('j') | src/llvm2ice.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698