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 14 matching lines...) Expand all Loading... |
25 | 25 |
26 namespace Ice { | 26 namespace Ice { |
27 | 27 |
28 ICE_TLS_DEFINE_FIELD(const Cfg *, Cfg, CurrentCfg); | 28 ICE_TLS_DEFINE_FIELD(const Cfg *, Cfg, CurrentCfg); |
29 | 29 |
30 ArenaAllocator<> *getCurrentCfgAllocator() { | 30 ArenaAllocator<> *getCurrentCfgAllocator() { |
31 return Cfg::getCurrentCfgAllocator(); | 31 return Cfg::getCurrentCfgAllocator(); |
32 } | 32 } |
33 | 33 |
34 Cfg::Cfg(GlobalContext *Ctx) | 34 Cfg::Cfg(GlobalContext *Ctx) |
35 : Ctx(Ctx), FunctionName(""), ReturnType(IceType_void), | 35 : Ctx(Ctx), VMask(Ctx->getVerbose()), FunctionName(""), |
36 IsInternalLinkage(false), HasError(false), FocusedTiming(false), | 36 ReturnType(IceType_void), IsInternalLinkage(false), HasError(false), |
37 ErrorMessage(""), Entry(nullptr), NextInstNumber(Inst::NumberInitial), | 37 FocusedTiming(false), ErrorMessage(""), Entry(nullptr), |
38 Allocator(new ArenaAllocator<>()), Live(nullptr), | 38 NextInstNumber(Inst::NumberInitial), Allocator(new ArenaAllocator<>()), |
| 39 Live(nullptr), |
39 Target(TargetLowering::createLowering(Ctx->getTargetArch(), this)), | 40 Target(TargetLowering::createLowering(Ctx->getTargetArch(), this)), |
40 VMetadata(new VariablesMetadata(this)), | 41 VMetadata(new VariablesMetadata(this)), |
41 TargetAssembler( | 42 TargetAssembler( |
42 TargetLowering::createAssembler(Ctx->getTargetArch(), this)), | 43 TargetLowering::createAssembler(Ctx->getTargetArch(), this)), |
43 CurrentNode(nullptr) { | 44 CurrentNode(nullptr) { |
44 assert(!Ctx->isIRGenerationDisabled() && | 45 assert(!Ctx->isIRGenerationDisabled() && |
45 "Attempt to build cfg when IR generation disabled"); | 46 "Attempt to build cfg when IR generation disabled"); |
46 } | 47 } |
47 | 48 |
48 Cfg::~Cfg() { | 49 Cfg::~Cfg() { |
49 // TODO(stichnot,kschimpf): Set CurrentCfg=nullptr in the dtor for | 50 assert(ICE_TLS_GET_FIELD(CurrentCfg) == this); |
50 // safety. This can't be done currently because the translator | 51 // Reset the thread-local CurrentCfg pointer. |
51 // manages the Cfg by creating a new Cfg (which sets CurrentCfg to | 52 ICE_TLS_SET_FIELD(CurrentCfg, nullptr); |
52 // the new value), then deleting the old Cfg (which would then reset | |
53 // CurrentCfg to nullptr). | |
54 } | 53 } |
55 | 54 |
56 void Cfg::setError(const IceString &Message) { | 55 void Cfg::setError(const IceString &Message) { |
57 HasError = true; | 56 HasError = true; |
58 ErrorMessage = Message; | 57 ErrorMessage = Message; |
59 OstreamLocker L(Ctx); | |
60 Ctx->getStrDump() << "ICE translation error: " << ErrorMessage << "\n"; | |
61 } | 58 } |
62 | 59 |
63 CfgNode *Cfg::makeNode() { | 60 CfgNode *Cfg::makeNode() { |
64 SizeT LabelIndex = Nodes.size(); | 61 SizeT LabelIndex = Nodes.size(); |
65 CfgNode *Node = CfgNode::create(this, LabelIndex); | 62 CfgNode *Node = CfgNode::create(this, LabelIndex); |
66 Nodes.push_back(Node); | 63 Nodes.push_back(Node); |
67 return Node; | 64 return Node; |
68 } | 65 } |
69 | 66 |
70 void Cfg::addArg(Variable *Arg) { | 67 void Cfg::addArg(Variable *Arg) { |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 OstreamLocker L(Ctx); | 468 OstreamLocker L(Ctx); |
472 emitTextHeader(MangledName); | 469 emitTextHeader(MangledName); |
473 getAssembler<Assembler>()->emitIASBytes(Ctx); | 470 getAssembler<Assembler>()->emitIASBytes(Ctx); |
474 } | 471 } |
475 } | 472 } |
476 | 473 |
477 // Dumps the IR with an optional introductory message. | 474 // Dumps the IR with an optional introductory message. |
478 void Cfg::dump(const IceString &Message) { | 475 void Cfg::dump(const IceString &Message) { |
479 if (!ALLOW_DUMP) | 476 if (!ALLOW_DUMP) |
480 return; | 477 return; |
481 if (!Ctx->isVerbose()) | 478 if (!isVerbose()) |
482 return; | 479 return; |
483 OstreamLocker L(Ctx); | 480 OstreamLocker L(Ctx); |
484 Ostream &Str = Ctx->getStrDump(); | 481 Ostream &Str = Ctx->getStrDump(); |
485 if (!Message.empty()) | 482 if (!Message.empty()) |
486 Str << "================ " << Message << " ================\n"; | 483 Str << "================ " << Message << " ================\n"; |
487 setCurrentNode(getEntryNode()); | 484 setCurrentNode(getEntryNode()); |
488 // Print function name+args | 485 // Print function name+args |
489 if (getContext()->isVerbose(IceV_Instructions)) { | 486 if (isVerbose(IceV_Instructions)) { |
490 Str << "define "; | 487 Str << "define "; |
491 if (getInternal() && !Ctx->getFlags().DisableInternal) | 488 if (getInternal() && !Ctx->getFlags().DisableInternal) |
492 Str << "internal "; | 489 Str << "internal "; |
493 Str << ReturnType << " @" << Ctx->mangleName(getFunctionName()) << "("; | 490 Str << ReturnType << " @" << Ctx->mangleName(getFunctionName()) << "("; |
494 for (SizeT i = 0; i < Args.size(); ++i) { | 491 for (SizeT i = 0; i < Args.size(); ++i) { |
495 if (i > 0) | 492 if (i > 0) |
496 Str << ", "; | 493 Str << ", "; |
497 Str << Args[i]->getType() << " "; | 494 Str << Args[i]->getType() << " "; |
498 Args[i]->dump(this); | 495 Args[i]->dump(this); |
499 } | 496 } |
500 Str << ") {\n"; | 497 Str << ") {\n"; |
501 } | 498 } |
502 resetCurrentNode(); | 499 resetCurrentNode(); |
503 if (getContext()->isVerbose(IceV_Liveness)) { | 500 if (isVerbose(IceV_Liveness)) { |
504 // Print summary info about variables | 501 // Print summary info about variables |
505 for (Variable *Var : Variables) { | 502 for (Variable *Var : Variables) { |
506 Str << "// multiblock="; | 503 Str << "// multiblock="; |
507 if (getVMetadata()->isTracked(Var)) | 504 if (getVMetadata()->isTracked(Var)) |
508 Str << getVMetadata()->isMultiBlock(Var); | 505 Str << getVMetadata()->isMultiBlock(Var); |
509 else | 506 else |
510 Str << "?"; | 507 Str << "?"; |
511 Str << " weight=" << Var->getWeight() << " "; | 508 Str << " weight=" << Var->getWeight() << " "; |
512 Var->dump(this); | 509 Var->dump(this); |
513 Str << " LIVE=" << Var->getLiveRange() << "\n"; | 510 Str << " LIVE=" << Var->getLiveRange() << "\n"; |
514 } | 511 } |
515 } | 512 } |
516 // Print each basic block | 513 // Print each basic block |
517 for (CfgNode *Node : Nodes) | 514 for (CfgNode *Node : Nodes) |
518 Node->dump(this); | 515 Node->dump(this); |
519 if (getContext()->isVerbose(IceV_Instructions)) | 516 if (isVerbose(IceV_Instructions)) |
520 Str << "}\n"; | 517 Str << "}\n"; |
521 } | 518 } |
522 | 519 |
523 } // end of namespace Ice | 520 } // end of namespace Ice |
OLD | NEW |