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

Side by Side Diff: src/IceCfg.cpp

Issue 905463003: Adds accessor methods to class ClFlags. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix nits in patchset 2. Created 5 years, 10 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 | « Makefile.standalone ('k') | src/IceCfgNode.cpp » ('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/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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // is used for dumping the stack frame location of Variables. 74 // is used for dumping the stack frame location of Variables.
75 bool Cfg::hasComputedFrame() const { return getTarget()->hasComputedFrame(); } 75 bool Cfg::hasComputedFrame() const { return getTarget()->hasComputedFrame(); }
76 76
77 void Cfg::translate() { 77 void Cfg::translate() {
78 if (hasError()) 78 if (hasError())
79 return; 79 return;
80 // FunctionTimer conditionally pushes/pops a TimerMarker if 80 // FunctionTimer conditionally pushes/pops a TimerMarker if
81 // TimeEachFunction is enabled. 81 // TimeEachFunction is enabled.
82 std::unique_ptr<TimerMarker> FunctionTimer; 82 std::unique_ptr<TimerMarker> FunctionTimer;
83 if (ALLOW_DUMP) { 83 if (ALLOW_DUMP) {
84 const IceString &TimingFocusOn = getContext()->getFlags().TimingFocusOn; 84 const IceString &TimingFocusOn =
85 getContext()->getFlags().getTimingFocusOn();
85 const IceString &Name = getFunctionName(); 86 const IceString &Name = getFunctionName();
86 if (TimingFocusOn == "*" || TimingFocusOn == Name) { 87 if (TimingFocusOn == "*" || TimingFocusOn == Name) {
87 setFocusedTiming(); 88 setFocusedTiming();
88 getContext()->resetTimer(GlobalContext::TSK_Default); 89 getContext()->resetTimer(GlobalContext::TSK_Default);
89 getContext()->setTimerName(GlobalContext::TSK_Default, Name); 90 getContext()->setTimerName(GlobalContext::TSK_Default, Name);
90 } 91 }
91 if (getContext()->getFlags().TimeEachFunction) 92 if (getContext()->getFlags().getTimeEachFunction())
92 FunctionTimer.reset(new TimerMarker( 93 FunctionTimer.reset(new TimerMarker(
93 getContext()->getTimerID(GlobalContext::TSK_Funcs, Name), 94 getContext()->getTimerID(GlobalContext::TSK_Funcs, Name),
94 getContext(), GlobalContext::TSK_Funcs)); 95 getContext(), GlobalContext::TSK_Funcs));
95 } 96 }
96 TimerMarker T(TimerStack::TT_translate, this); 97 TimerMarker T(TimerStack::TT_translate, this);
97 98
98 dump("Initial CFG"); 99 dump("Initial CFG");
99 100
100 // The set of translation passes and their order are determined by 101 // The set of translation passes and their order are determined by
101 // the target. 102 // the target.
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 return Valid; 393 return Valid;
393 } 394 }
394 395
395 void Cfg::contractEmptyNodes() { 396 void Cfg::contractEmptyNodes() {
396 // If we're decorating the asm output with register liveness info, 397 // If we're decorating the asm output with register liveness info,
397 // this information may become corrupted or incorrect after 398 // this information may become corrupted or incorrect after
398 // contracting nodes that contain only redundant assignments. As 399 // contracting nodes that contain only redundant assignments. As
399 // such, we disable this pass when DecorateAsm is specified. This 400 // such, we disable this pass when DecorateAsm is specified. This
400 // may make the resulting code look more branchy, but it should have 401 // may make the resulting code look more branchy, but it should have
401 // no effect on the register assignments. 402 // no effect on the register assignments.
402 if (Ctx->getFlags().DecorateAsm) 403 if (Ctx->getFlags().getDecorateAsm())
403 return; 404 return;
404 for (CfgNode *Node : Nodes) { 405 for (CfgNode *Node : Nodes) {
405 Node->contractIfEmpty(); 406 Node->contractIfEmpty();
406 } 407 }
407 } 408 }
408 409
409 void Cfg::doBranchOpt() { 410 void Cfg::doBranchOpt() {
410 TimerMarker T(TimerStack::TT_doBranchOpt, this); 411 TimerMarker T(TimerStack::TT_doBranchOpt, this);
411 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { 412 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) {
412 auto NextNode = I; 413 auto NextNode = I;
413 ++NextNode; 414 ++NextNode;
414 (*I)->doBranchOpt(NextNode == E ? nullptr : *NextNode); 415 (*I)->doBranchOpt(NextNode == E ? nullptr : *NextNode);
415 } 416 }
416 } 417 }
417 418
418 // ======================== Dump routines ======================== // 419 // ======================== Dump routines ======================== //
419 420
420 void Cfg::emitTextHeader(const IceString &MangledName) { 421 void Cfg::emitTextHeader(const IceString &MangledName) {
421 // Note: Still used by emit IAS. 422 // Note: Still used by emit IAS.
422 Ostream &Str = Ctx->getStrEmit(); 423 Ostream &Str = Ctx->getStrEmit();
423 Str << "\t.text\n"; 424 Str << "\t.text\n";
424 if (Ctx->getFlags().FunctionSections) 425 if (Ctx->getFlags().getFunctionSections())
425 Str << "\t.section\t.text." << MangledName << ",\"ax\",@progbits\n"; 426 Str << "\t.section\t.text." << MangledName << ",\"ax\",@progbits\n";
426 if (!getInternal() || Ctx->getFlags().DisableInternal) { 427 if (!getInternal() || Ctx->getFlags().getDisableInternal()) {
427 Str << "\t.globl\t" << MangledName << "\n"; 428 Str << "\t.globl\t" << MangledName << "\n";
428 Str << "\t.type\t" << MangledName << ",@function\n"; 429 Str << "\t.type\t" << MangledName << ",@function\n";
429 } 430 }
430 Assembler *Asm = getAssembler<Assembler>(); 431 Assembler *Asm = getAssembler<Assembler>();
431 Str << "\t.p2align " << Asm->getBundleAlignLog2Bytes() << ",0x"; 432 Str << "\t.p2align " << Asm->getBundleAlignLog2Bytes() << ",0x";
432 for (uint8_t I : Asm->getNonExecBundlePadding()) 433 for (uint8_t I : Asm->getNonExecBundlePadding())
433 Str.write_hex(I); 434 Str.write_hex(I);
434 Str << "\n"; 435 Str << "\n";
435 Str << MangledName << ":\n"; 436 Str << MangledName << ":\n";
436 } 437 }
437 438
438 void Cfg::emit() { 439 void Cfg::emit() {
439 if (!ALLOW_DUMP) 440 if (!ALLOW_DUMP)
440 return; 441 return;
441 TimerMarker T(TimerStack::TT_emit, this); 442 TimerMarker T(TimerStack::TT_emit, this);
442 if (Ctx->getFlags().DecorateAsm) { 443 if (Ctx->getFlags().getDecorateAsm()) {
443 renumberInstructions(); 444 renumberInstructions();
444 getVMetadata()->init(VMK_Uses); 445 getVMetadata()->init(VMK_Uses);
445 liveness(Liveness_Basic); 446 liveness(Liveness_Basic);
446 dump("After recomputing liveness for -decorate-asm"); 447 dump("After recomputing liveness for -decorate-asm");
447 } 448 }
448 OstreamLocker L(Ctx); 449 OstreamLocker L(Ctx);
449 Ostream &Str = Ctx->getStrEmit(); 450 Ostream &Str = Ctx->getStrEmit();
450 IceString MangledName = getContext()->mangleName(getFunctionName()); 451 IceString MangledName = getContext()->mangleName(getFunctionName());
451 emitTextHeader(MangledName); 452 emitTextHeader(MangledName);
452 for (CfgNode *Node : Nodes) 453 for (CfgNode *Node : Nodes)
453 Node->emit(this); 454 Node->emit(this);
454 Str << "\n"; 455 Str << "\n";
455 } 456 }
456 457
457 void Cfg::emitIAS() { 458 void Cfg::emitIAS() {
458 TimerMarker T(TimerStack::TT_emit, this); 459 TimerMarker T(TimerStack::TT_emit, this);
459 assert(!Ctx->getFlags().DecorateAsm); 460 assert(!Ctx->getFlags().getDecorateAsm());
460 IceString MangledName = getContext()->mangleName(getFunctionName()); 461 IceString MangledName = getContext()->mangleName(getFunctionName());
461 // The emitIAS() routines emit into the internal assembler buffer, 462 // The emitIAS() routines emit into the internal assembler buffer,
462 // so there's no need to lock the streams until we're ready to call 463 // so there's no need to lock the streams until we're ready to call
463 // emitIASBytes(). 464 // emitIASBytes().
464 for (CfgNode *Node : Nodes) 465 for (CfgNode *Node : Nodes)
465 Node->emitIAS(this); 466 Node->emitIAS(this);
466 // Now write the function to the file and track. 467 // Now write the function to the file and track.
467 if (Ctx->getFlags().UseELFWriter) { 468 if (Ctx->getFlags().getUseELFWriter()) {
468 getAssembler<Assembler>()->alignFunction(); 469 getAssembler<Assembler>()->alignFunction();
469 Ctx->getObjectWriter()->writeFunctionCode(MangledName, getInternal(), 470 Ctx->getObjectWriter()->writeFunctionCode(MangledName, getInternal(),
470 getAssembler<Assembler>()); 471 getAssembler<Assembler>());
471 } else { 472 } else {
472 OstreamLocker L(Ctx); 473 OstreamLocker L(Ctx);
473 emitTextHeader(MangledName); 474 emitTextHeader(MangledName);
474 getAssembler<Assembler>()->emitIASBytes(Ctx); 475 getAssembler<Assembler>()->emitIASBytes(Ctx);
475 } 476 }
476 } 477 }
477 478
478 // Dumps the IR with an optional introductory message. 479 // Dumps the IR with an optional introductory message.
479 void Cfg::dump(const IceString &Message) { 480 void Cfg::dump(const IceString &Message) {
480 if (!ALLOW_DUMP) 481 if (!ALLOW_DUMP)
481 return; 482 return;
482 if (!isVerbose()) 483 if (!isVerbose())
483 return; 484 return;
484 OstreamLocker L(Ctx); 485 OstreamLocker L(Ctx);
485 Ostream &Str = Ctx->getStrDump(); 486 Ostream &Str = Ctx->getStrDump();
486 if (!Message.empty()) 487 if (!Message.empty())
487 Str << "================ " << Message << " ================\n"; 488 Str << "================ " << Message << " ================\n";
488 setCurrentNode(getEntryNode()); 489 setCurrentNode(getEntryNode());
489 // Print function name+args 490 // Print function name+args
490 if (isVerbose(IceV_Instructions)) { 491 if (isVerbose(IceV_Instructions)) {
491 Str << "define "; 492 Str << "define ";
492 if (getInternal() && !Ctx->getFlags().DisableInternal) 493 if (getInternal() && !Ctx->getFlags().getDisableInternal())
493 Str << "internal "; 494 Str << "internal ";
494 Str << ReturnType << " @" << Ctx->mangleName(getFunctionName()) << "("; 495 Str << ReturnType << " @" << Ctx->mangleName(getFunctionName()) << "(";
495 for (SizeT i = 0; i < Args.size(); ++i) { 496 for (SizeT i = 0; i < Args.size(); ++i) {
496 if (i > 0) 497 if (i > 0)
497 Str << ", "; 498 Str << ", ";
498 Str << Args[i]->getType() << " "; 499 Str << Args[i]->getType() << " ";
499 Args[i]->dump(this); 500 Args[i]->dump(this);
500 } 501 }
501 Str << ") {\n"; 502 Str << ") {\n";
502 } 503 }
(...skipping 12 matching lines...) Expand all
515 } 516 }
516 } 517 }
517 // Print each basic block 518 // Print each basic block
518 for (CfgNode *Node : Nodes) 519 for (CfgNode *Node : Nodes)
519 Node->dump(this); 520 Node->dump(this);
520 if (isVerbose(IceV_Instructions)) 521 if (isVerbose(IceV_Instructions))
521 Str << "}\n"; 522 Str << "}\n";
522 } 523 }
523 524
524 } // end of namespace Ice 525 } // end of namespace Ice
OLDNEW
« no previous file with comments | « Makefile.standalone ('k') | src/IceCfgNode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698