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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 TimerMarker T(TimerStack::TT_doBranchOpt, this); | 383 TimerMarker T(TimerStack::TT_doBranchOpt, this); |
384 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { | 384 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { |
385 auto NextNode = I; | 385 auto NextNode = I; |
386 ++NextNode; | 386 ++NextNode; |
387 (*I)->doBranchOpt(NextNode == E ? NULL : *NextNode); | 387 (*I)->doBranchOpt(NextNode == E ? NULL : *NextNode); |
388 } | 388 } |
389 } | 389 } |
390 | 390 |
391 // ======================== Dump routines ======================== // | 391 // ======================== Dump routines ======================== // |
392 | 392 |
| 393 void Cfg::emitTextHeader(const IceString &MangledName) { |
| 394 Ostream &Str = Ctx->getStrEmit(); |
| 395 Str << "\t.text\n"; |
| 396 if (Ctx->getFlags().FunctionSections) |
| 397 Str << "\t.section\t.text." << MangledName << ",\"ax\",@progbits\n"; |
| 398 if (!getInternal() || Ctx->getFlags().DisableInternal) { |
| 399 Str << "\t.globl\t" << MangledName << "\n"; |
| 400 Str << "\t.type\t" << MangledName << ",@function\n"; |
| 401 } |
| 402 Str << "\t.p2align " << getTarget()->getBundleAlignLog2Bytes() << ",0x"; |
| 403 for (AsmCodeByte I : getTarget()->getNonExecBundlePadding()) |
| 404 Str.write_hex(I); |
| 405 Str << "\n"; |
| 406 Str << MangledName << ":\n"; |
| 407 } |
| 408 |
393 void Cfg::emit() { | 409 void Cfg::emit() { |
394 TimerMarker T(TimerStack::TT_emit, this); | 410 TimerMarker T(TimerStack::TT_emit, this); |
395 if (Ctx->getFlags().DecorateAsm) { | 411 if (Ctx->getFlags().DecorateAsm) { |
396 renumberInstructions(); | 412 renumberInstructions(); |
397 getVMetadata()->init(VMK_Uses); | 413 getVMetadata()->init(VMK_Uses); |
398 liveness(Liveness_Basic); | 414 liveness(Liveness_Basic); |
399 dump("After recomputing liveness for -decorate-asm"); | 415 dump("After recomputing liveness for -decorate-asm"); |
400 } | 416 } |
401 Ostream &Str = Ctx->getStrEmit(); | 417 Ostream &Str = Ctx->getStrEmit(); |
402 if (!Ctx->testAndSetHasEmittedFirstMethod()) { | 418 if (!Ctx->testAndSetHasEmittedFirstMethod()) { |
403 // Print a helpful command for assembling the output. | 419 // Print a helpful command for assembling the output. |
404 // TODO: have the Target emit the header | 420 // TODO: have the Target emit the header |
405 // TODO: need a per-file emit in addition to per-CFG | 421 // TODO: need a per-file emit in addition to per-CFG |
406 Str << "# $LLVM_BIN_PATH/llvm-mc" | 422 Str << "# $LLVM_BIN_PATH/llvm-mc" |
407 << " -arch=x86" | 423 << " -arch=x86" |
408 << " -filetype=obj" | 424 << " -filetype=obj" |
409 << " -o=MyObj.o" | 425 << " -o=MyObj.o" |
410 << "\n\n"; | 426 << "\n\n"; |
411 } | 427 } |
412 Str << "\t.text\n"; | |
413 IceString MangledName = getContext()->mangleName(getFunctionName()); | 428 IceString MangledName = getContext()->mangleName(getFunctionName()); |
414 if (Ctx->getFlags().FunctionSections) | 429 emitTextHeader(MangledName); |
415 Str << "\t.section\t.text." << MangledName << ",\"ax\",@progbits\n"; | |
416 if (!getInternal() || Ctx->getFlags().DisableInternal) { | |
417 Str << "\t.globl\t" << MangledName << "\n"; | |
418 Str << "\t.type\t" << MangledName << ",@function\n"; | |
419 } | |
420 Str << "\t.p2align " << getTarget()->getBundleAlignLog2Bytes() << ",0x"; | |
421 for (AsmCodeByte I : getTarget()->getNonExecBundlePadding()) | |
422 Str.write_hex(I); | |
423 Str << "\n"; | |
424 for (CfgNode *Node : Nodes) | 430 for (CfgNode *Node : Nodes) |
425 Node->emit(this); | 431 Node->emit(this); |
426 Str << "\n"; | 432 Str << "\n"; |
427 } | 433 } |
428 | 434 |
| 435 void Cfg::emitIAS() { |
| 436 TimerMarker T(TimerStack::TT_emit, this); |
| 437 assert(!Ctx->getFlags().DecorateAsm); |
| 438 IceString MangledName = getContext()->mangleName(getFunctionName()); |
| 439 emitTextHeader(MangledName); |
| 440 for (CfgNode *Node : Nodes) |
| 441 Node->emitIAS(this); |
| 442 getAssembler<Assembler>()->emitIASBytes(Ctx); |
| 443 } |
| 444 |
429 // Dumps the IR with an optional introductory message. | 445 // Dumps the IR with an optional introductory message. |
430 void Cfg::dump(const IceString &Message) { | 446 void Cfg::dump(const IceString &Message) { |
431 if (!Ctx->isVerbose()) | 447 if (!Ctx->isVerbose()) |
432 return; | 448 return; |
433 Ostream &Str = Ctx->getStrDump(); | 449 Ostream &Str = Ctx->getStrDump(); |
434 if (!Message.empty()) | 450 if (!Message.empty()) |
435 Str << "================ " << Message << " ================\n"; | 451 Str << "================ " << Message << " ================\n"; |
436 setCurrentNode(getEntryNode()); | 452 setCurrentNode(getEntryNode()); |
437 // Print function name+args | 453 // Print function name+args |
438 if (getContext()->isVerbose(IceV_Instructions)) { | 454 if (getContext()->isVerbose(IceV_Instructions)) { |
(...skipping 24 matching lines...) Expand all Loading... |
463 } | 479 } |
464 } | 480 } |
465 // Print each basic block | 481 // Print each basic block |
466 for (CfgNode *Node : Nodes) | 482 for (CfgNode *Node : Nodes) |
467 Node->dump(this); | 483 Node->dump(this); |
468 if (getContext()->isVerbose(IceV_Instructions)) | 484 if (getContext()->isVerbose(IceV_Instructions)) |
469 Str << "}\n"; | 485 Str << "}\n"; |
470 } | 486 } |
471 | 487 |
472 } // end of namespace Ice | 488 } // end of namespace Ice |
OLD | NEW |