OLD | NEW |
1 //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===// | 1 //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===// |
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 Cfg class, including constant pool | 10 // This file implements the Cfg class, including constant pool |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 void Cfg::emitTextHeader(const IceString &MangledName) { | 398 void Cfg::emitTextHeader(const IceString &MangledName) { |
399 // Note: Still used by emit IAS. | 399 // Note: Still used by emit IAS. |
400 Ostream &Str = Ctx->getStrEmit(); | 400 Ostream &Str = Ctx->getStrEmit(); |
401 Str << "\t.text\n"; | 401 Str << "\t.text\n"; |
402 if (Ctx->getFlags().FunctionSections) | 402 if (Ctx->getFlags().FunctionSections) |
403 Str << "\t.section\t.text." << MangledName << ",\"ax\",@progbits\n"; | 403 Str << "\t.section\t.text." << MangledName << ",\"ax\",@progbits\n"; |
404 if (!getInternal() || Ctx->getFlags().DisableInternal) { | 404 if (!getInternal() || Ctx->getFlags().DisableInternal) { |
405 Str << "\t.globl\t" << MangledName << "\n"; | 405 Str << "\t.globl\t" << MangledName << "\n"; |
406 Str << "\t.type\t" << MangledName << ",@function\n"; | 406 Str << "\t.type\t" << MangledName << ",@function\n"; |
407 } | 407 } |
408 Str << "\t.p2align " << getTarget()->getBundleAlignLog2Bytes() << ",0x"; | 408 Assembler *Asm = getAssembler<Assembler>(); |
409 for (AsmCodeByte I : getTarget()->getNonExecBundlePadding()) | 409 Str << "\t.p2align " << Asm->getBundleAlignLog2Bytes() << ",0x"; |
| 410 for (uint8_t I : Asm->getNonExecBundlePadding()) |
410 Str.write_hex(I); | 411 Str.write_hex(I); |
411 Str << "\n"; | 412 Str << "\n"; |
412 Str << MangledName << ":\n"; | 413 Str << MangledName << ":\n"; |
413 } | 414 } |
414 | 415 |
415 void Cfg::emit() { | 416 void Cfg::emit() { |
416 if (!ALLOW_DUMP) | 417 if (!ALLOW_DUMP) |
417 return; | 418 return; |
418 TimerMarker T(TimerStack::TT_emit, this); | 419 TimerMarker T(TimerStack::TT_emit, this); |
419 if (Ctx->getFlags().DecorateAsm) { | 420 if (Ctx->getFlags().DecorateAsm) { |
(...skipping 17 matching lines...) Expand all Loading... |
437 emitTextHeader(MangledName); | 438 emitTextHeader(MangledName); |
438 for (CfgNode *Node : Nodes) | 439 for (CfgNode *Node : Nodes) |
439 Node->emit(this); | 440 Node->emit(this); |
440 Str << "\n"; | 441 Str << "\n"; |
441 } | 442 } |
442 | 443 |
443 void Cfg::emitIAS() { | 444 void Cfg::emitIAS() { |
444 TimerMarker T(TimerStack::TT_emit, this); | 445 TimerMarker T(TimerStack::TT_emit, this); |
445 assert(!Ctx->getFlags().DecorateAsm); | 446 assert(!Ctx->getFlags().DecorateAsm); |
446 IceString MangledName = getContext()->mangleName(getFunctionName()); | 447 IceString MangledName = getContext()->mangleName(getFunctionName()); |
447 emitTextHeader(MangledName); | 448 if (!Ctx->getFlags().UseELFWriter) |
| 449 emitTextHeader(MangledName); |
448 for (CfgNode *Node : Nodes) | 450 for (CfgNode *Node : Nodes) |
449 Node->emitIAS(this); | 451 Node->emitIAS(this); |
450 getAssembler<Assembler>()->emitIASBytes(Ctx); | 452 // Now write the function to the file and track. |
| 453 if (Ctx->getFlags().UseELFWriter) { |
| 454 getAssembler<Assembler>()->alignFunction(); |
| 455 // TODO(jvoung): Transfer remaining fixups too. They may need their |
| 456 // offsets adjusted. |
| 457 Ctx->getObjectWriter()->writeFunctionCode( |
| 458 MangledName, getInternal(), getAssembler<Assembler>()->getBufferView()); |
| 459 } else { |
| 460 getAssembler<Assembler>()->emitIASBytes(Ctx); |
| 461 } |
451 } | 462 } |
452 | 463 |
453 // Dumps the IR with an optional introductory message. | 464 // Dumps the IR with an optional introductory message. |
454 void Cfg::dump(const IceString &Message) { | 465 void Cfg::dump(const IceString &Message) { |
455 if (!ALLOW_DUMP) | 466 if (!ALLOW_DUMP) |
456 return; | 467 return; |
457 if (!Ctx->isVerbose()) | 468 if (!Ctx->isVerbose()) |
458 return; | 469 return; |
459 Ostream &Str = Ctx->getStrDump(); | 470 Ostream &Str = Ctx->getStrDump(); |
460 if (!Message.empty()) | 471 if (!Message.empty()) |
(...skipping 28 matching lines...) Expand all Loading... |
489 } | 500 } |
490 } | 501 } |
491 // Print each basic block | 502 // Print each basic block |
492 for (CfgNode *Node : Nodes) | 503 for (CfgNode *Node : Nodes) |
493 Node->dump(this); | 504 Node->dump(this); |
494 if (getContext()->isVerbose(IceV_Instructions)) | 505 if (getContext()->isVerbose(IceV_Instructions)) |
495 Str << "}\n"; | 506 Str << "}\n"; |
496 } | 507 } |
497 | 508 |
498 } // end of namespace Ice | 509 } // end of namespace Ice |
OLD | NEW |