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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // TODO(stichnot,kschimpf): Set CurrentCfg=nullptr in the dtor for | 49 // TODO(stichnot,kschimpf): Set CurrentCfg=nullptr in the dtor for |
50 // safety. This can't be done currently because the translator | 50 // safety. This can't be done currently because the translator |
51 // manages the Cfg by creating a new Cfg (which sets CurrentCfg to | 51 // manages the Cfg by creating a new Cfg (which sets CurrentCfg to |
52 // the new value), then deleting the old Cfg (which would then reset | 52 // the new value), then deleting the old Cfg (which would then reset |
53 // CurrentCfg to nullptr). | 53 // CurrentCfg to nullptr). |
54 } | 54 } |
55 | 55 |
56 void Cfg::setError(const IceString &Message) { | 56 void Cfg::setError(const IceString &Message) { |
57 HasError = true; | 57 HasError = true; |
58 ErrorMessage = Message; | 58 ErrorMessage = Message; |
| 59 OstreamLocker L(Ctx); |
59 Ctx->getStrDump() << "ICE translation error: " << ErrorMessage << "\n"; | 60 Ctx->getStrDump() << "ICE translation error: " << ErrorMessage << "\n"; |
60 } | 61 } |
61 | 62 |
62 CfgNode *Cfg::makeNode() { | 63 CfgNode *Cfg::makeNode() { |
63 SizeT LabelIndex = Nodes.size(); | 64 SizeT LabelIndex = Nodes.size(); |
64 CfgNode *Node = CfgNode::create(this, LabelIndex); | 65 CfgNode *Node = CfgNode::create(this, LabelIndex); |
65 Nodes.push_back(Node); | 66 Nodes.push_back(Node); |
66 return Node; | 67 return Node; |
67 } | 68 } |
68 | 69 |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 Node->livenessAddIntervals(getLiveness(), FirstInstNum, LastInstNum); | 329 Node->livenessAddIntervals(getLiveness(), FirstInstNum, LastInstNum); |
329 } | 330 } |
330 } | 331 } |
331 } | 332 } |
332 | 333 |
333 // Traverse every Variable of every Inst and verify that it | 334 // Traverse every Variable of every Inst and verify that it |
334 // appears within the Variable's computed live range. | 335 // appears within the Variable's computed live range. |
335 bool Cfg::validateLiveness() const { | 336 bool Cfg::validateLiveness() const { |
336 TimerMarker T(TimerStack::TT_validateLiveness, this); | 337 TimerMarker T(TimerStack::TT_validateLiveness, this); |
337 bool Valid = true; | 338 bool Valid = true; |
| 339 OstreamLocker L(Ctx); |
338 Ostream &Str = Ctx->getStrDump(); | 340 Ostream &Str = Ctx->getStrDump(); |
339 for (CfgNode *Node : Nodes) { | 341 for (CfgNode *Node : Nodes) { |
340 Inst *FirstInst = nullptr; | 342 Inst *FirstInst = nullptr; |
341 for (Inst &Inst : Node->getInsts()) { | 343 for (Inst &Inst : Node->getInsts()) { |
342 if (Inst.isDeleted()) | 344 if (Inst.isDeleted()) |
343 continue; | 345 continue; |
344 if (FirstInst == nullptr) | 346 if (FirstInst == nullptr) |
345 FirstInst = &Inst; | 347 FirstInst = &Inst; |
346 InstNumberT InstNumber = Inst.getNumber(); | 348 InstNumberT InstNumber = Inst.getNumber(); |
347 if (Variable *Dest = Inst.getDest()) { | 349 if (Variable *Dest = Inst.getDest()) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 void Cfg::emit() { | 437 void Cfg::emit() { |
436 if (!ALLOW_DUMP) | 438 if (!ALLOW_DUMP) |
437 return; | 439 return; |
438 TimerMarker T(TimerStack::TT_emit, this); | 440 TimerMarker T(TimerStack::TT_emit, this); |
439 if (Ctx->getFlags().DecorateAsm) { | 441 if (Ctx->getFlags().DecorateAsm) { |
440 renumberInstructions(); | 442 renumberInstructions(); |
441 getVMetadata()->init(VMK_Uses); | 443 getVMetadata()->init(VMK_Uses); |
442 liveness(Liveness_Basic); | 444 liveness(Liveness_Basic); |
443 dump("After recomputing liveness for -decorate-asm"); | 445 dump("After recomputing liveness for -decorate-asm"); |
444 } | 446 } |
| 447 OstreamLocker L(Ctx); |
445 Ostream &Str = Ctx->getStrEmit(); | 448 Ostream &Str = Ctx->getStrEmit(); |
446 IceString MangledName = getContext()->mangleName(getFunctionName()); | 449 IceString MangledName = getContext()->mangleName(getFunctionName()); |
447 emitTextHeader(MangledName); | 450 emitTextHeader(MangledName); |
448 for (CfgNode *Node : Nodes) | 451 for (CfgNode *Node : Nodes) |
449 Node->emit(this); | 452 Node->emit(this); |
450 Str << "\n"; | 453 Str << "\n"; |
451 } | 454 } |
452 | 455 |
453 void Cfg::emitIAS() { | 456 void Cfg::emitIAS() { |
454 TimerMarker T(TimerStack::TT_emit, this); | 457 TimerMarker T(TimerStack::TT_emit, this); |
455 assert(!Ctx->getFlags().DecorateAsm); | 458 assert(!Ctx->getFlags().DecorateAsm); |
456 IceString MangledName = getContext()->mangleName(getFunctionName()); | 459 IceString MangledName = getContext()->mangleName(getFunctionName()); |
457 if (!Ctx->getFlags().UseELFWriter) | 460 // The emitIAS() routines emit into the internal assembler buffer, |
458 emitTextHeader(MangledName); | 461 // so there's no need to lock the streams until we're ready to call |
| 462 // emitIASBytes(). |
459 for (CfgNode *Node : Nodes) | 463 for (CfgNode *Node : Nodes) |
460 Node->emitIAS(this); | 464 Node->emitIAS(this); |
461 // Now write the function to the file and track. | 465 // Now write the function to the file and track. |
462 if (Ctx->getFlags().UseELFWriter) { | 466 if (Ctx->getFlags().UseELFWriter) { |
463 getAssembler<Assembler>()->alignFunction(); | 467 getAssembler<Assembler>()->alignFunction(); |
464 Ctx->getObjectWriter()->writeFunctionCode(MangledName, getInternal(), | 468 Ctx->getObjectWriter()->writeFunctionCode(MangledName, getInternal(), |
465 getAssembler<Assembler>()); | 469 getAssembler<Assembler>()); |
466 } else { | 470 } else { |
| 471 OstreamLocker L(Ctx); |
| 472 emitTextHeader(MangledName); |
467 getAssembler<Assembler>()->emitIASBytes(Ctx); | 473 getAssembler<Assembler>()->emitIASBytes(Ctx); |
468 } | 474 } |
469 } | 475 } |
470 | 476 |
471 // Dumps the IR with an optional introductory message. | 477 // Dumps the IR with an optional introductory message. |
472 void Cfg::dump(const IceString &Message) { | 478 void Cfg::dump(const IceString &Message) { |
473 if (!ALLOW_DUMP) | 479 if (!ALLOW_DUMP) |
474 return; | 480 return; |
475 if (!Ctx->isVerbose()) | 481 if (!Ctx->isVerbose()) |
476 return; | 482 return; |
| 483 OstreamLocker L(Ctx); |
477 Ostream &Str = Ctx->getStrDump(); | 484 Ostream &Str = Ctx->getStrDump(); |
478 if (!Message.empty()) | 485 if (!Message.empty()) |
479 Str << "================ " << Message << " ================\n"; | 486 Str << "================ " << Message << " ================\n"; |
480 setCurrentNode(getEntryNode()); | 487 setCurrentNode(getEntryNode()); |
481 // Print function name+args | 488 // Print function name+args |
482 if (getContext()->isVerbose(IceV_Instructions)) { | 489 if (getContext()->isVerbose(IceV_Instructions)) { |
483 Str << "define "; | 490 Str << "define "; |
484 if (getInternal() && !Ctx->getFlags().DisableInternal) | 491 if (getInternal() && !Ctx->getFlags().DisableInternal) |
485 Str << "internal "; | 492 Str << "internal "; |
486 Str << ReturnType << " @" << Ctx->mangleName(getFunctionName()) << "("; | 493 Str << ReturnType << " @" << Ctx->mangleName(getFunctionName()) << "("; |
(...skipping 20 matching lines...) Expand all Loading... |
507 } | 514 } |
508 } | 515 } |
509 // Print each basic block | 516 // Print each basic block |
510 for (CfgNode *Node : Nodes) | 517 for (CfgNode *Node : Nodes) |
511 Node->dump(this); | 518 Node->dump(this); |
512 if (getContext()->isVerbose(IceV_Instructions)) | 519 if (getContext()->isVerbose(IceV_Instructions)) |
513 Str << "}\n"; | 520 Str << "}\n"; |
514 } | 521 } |
515 | 522 |
516 } // end of namespace Ice | 523 } // end of namespace Ice |
OLD | NEW |