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 |
11 // management. | 11 // management. |
12 // | 12 // |
13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
14 | 14 |
15 #include "IceCfg.h" | 15 #include "IceCfg.h" |
16 #include "IceCfgNode.h" | 16 #include "IceCfgNode.h" |
17 #include "IceClFlags.h" | 17 #include "IceClFlags.h" |
18 #include "IceDefs.h" | 18 #include "IceDefs.h" |
19 #include "IceInst.h" | 19 #include "IceInst.h" |
20 #include "IceLiveness.h" | 20 #include "IceLiveness.h" |
21 #include "IceOperand.h" | 21 #include "IceOperand.h" |
22 #include "IceTargetLowering.h" | 22 #include "IceTargetLowering.h" |
23 | 23 |
24 namespace Ice { | 24 namespace Ice { |
25 | 25 |
26 thread_local const Cfg *Cfg::CurrentCfg = NULL; | 26 thread_local const Cfg *Cfg::CurrentCfg = nullptr; |
27 | 27 |
28 ArenaAllocator *getCurrentCfgAllocator() { | 28 ArenaAllocator *getCurrentCfgAllocator() { |
29 return Cfg::getCurrentCfgAllocator(); | 29 return Cfg::getCurrentCfgAllocator(); |
30 } | 30 } |
31 | 31 |
32 Cfg::Cfg(GlobalContext *Ctx) | 32 Cfg::Cfg(GlobalContext *Ctx) |
33 : Ctx(Ctx), FunctionName(""), ReturnType(IceType_void), | 33 : Ctx(Ctx), FunctionName(""), ReturnType(IceType_void), |
34 IsInternalLinkage(false), HasError(false), FocusedTiming(false), | 34 IsInternalLinkage(false), HasError(false), FocusedTiming(false), |
35 ErrorMessage(""), Entry(NULL), NextInstNumber(Inst::NumberInitial), | 35 ErrorMessage(""), Entry(nullptr), NextInstNumber(Inst::NumberInitial), |
36 Allocator(new ArenaAllocator()), Live(nullptr), | 36 Allocator(new ArenaAllocator()), Live(nullptr), |
37 Target(TargetLowering::createLowering(Ctx->getTargetArch(), this)), | 37 Target(TargetLowering::createLowering(Ctx->getTargetArch(), this)), |
38 VMetadata(new VariablesMetadata(this)), | 38 VMetadata(new VariablesMetadata(this)), |
39 TargetAssembler( | 39 TargetAssembler( |
40 TargetLowering::createAssembler(Ctx->getTargetArch(), this)), | 40 TargetLowering::createAssembler(Ctx->getTargetArch(), this)), |
41 CurrentNode(NULL) { | 41 CurrentNode(nullptr) { |
42 assert(!Ctx->isIRGenerationDisabled() && | 42 assert(!Ctx->isIRGenerationDisabled() && |
43 "Attempt to build cfg when IR generation disabled"); | 43 "Attempt to build cfg when IR generation disabled"); |
44 } | 44 } |
45 | 45 |
46 Cfg::~Cfg() { | 46 Cfg::~Cfg() { |
47 // TODO(stichnot,kschimpf): Set CurrentCfg=NULL in the dtor for | 47 // TODO(stichnot,kschimpf): Set CurrentCfg=nullptr in the dtor for |
48 // safety. This can't be done currently because the translator | 48 // safety. This can't be done currently because the translator |
49 // manages the Cfg by creating a new Cfg (which sets CurrentCfg to | 49 // manages the Cfg by creating a new Cfg (which sets CurrentCfg to |
50 // the new value), then deleting the old Cfg (which would then reset | 50 // the new value), then deleting the old Cfg (which would then reset |
51 // CurrentCfg to NULL). | 51 // CurrentCfg to nullptr). |
52 } | 52 } |
53 | 53 |
54 void Cfg::setError(const IceString &Message) { | 54 void Cfg::setError(const IceString &Message) { |
55 HasError = true; | 55 HasError = true; |
56 ErrorMessage = Message; | 56 ErrorMessage = Message; |
57 Ctx->getStrDump() << "ICE translation error: " << ErrorMessage << "\n"; | 57 Ctx->getStrDump() << "ICE translation error: " << ErrorMessage << "\n"; |
58 } | 58 } |
59 | 59 |
60 CfgNode *Cfg::makeNode() { | 60 CfgNode *Cfg::makeNode() { |
61 SizeT LabelIndex = Nodes.size(); | 61 SizeT LabelIndex = Nodes.size(); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 } | 331 } |
332 } | 332 } |
333 | 333 |
334 // Traverse every Variable of every Inst and verify that it | 334 // Traverse every Variable of every Inst and verify that it |
335 // appears within the Variable's computed live range. | 335 // appears within the Variable's computed live range. |
336 bool Cfg::validateLiveness() const { | 336 bool Cfg::validateLiveness() const { |
337 TimerMarker T(TimerStack::TT_validateLiveness, this); | 337 TimerMarker T(TimerStack::TT_validateLiveness, this); |
338 bool Valid = true; | 338 bool Valid = true; |
339 Ostream &Str = Ctx->getStrDump(); | 339 Ostream &Str = Ctx->getStrDump(); |
340 for (CfgNode *Node : Nodes) { | 340 for (CfgNode *Node : Nodes) { |
341 Inst *FirstInst = NULL; | 341 Inst *FirstInst = nullptr; |
342 for (auto Inst = Node->getInsts().begin(), E = Node->getInsts().end(); | 342 for (auto Inst = Node->getInsts().begin(), E = Node->getInsts().end(); |
343 Inst != E; ++Inst) { | 343 Inst != E; ++Inst) { |
344 if (Inst->isDeleted()) | 344 if (Inst->isDeleted()) |
345 continue; | 345 continue; |
346 if (FirstInst == NULL) | 346 if (FirstInst == nullptr) |
347 FirstInst = Inst; | 347 FirstInst = Inst; |
348 InstNumberT InstNumber = Inst->getNumber(); | 348 InstNumberT InstNumber = Inst->getNumber(); |
349 if (Variable *Dest = Inst->getDest()) { | 349 if (Variable *Dest = Inst->getDest()) { |
350 if (!Dest->getIgnoreLiveness()) { | 350 if (!Dest->getIgnoreLiveness()) { |
351 bool Invalid = false; | 351 bool Invalid = false; |
352 const bool IsDest = true; | 352 const bool IsDest = true; |
353 if (!Dest->getLiveRange().containsValue(InstNumber, IsDest)) | 353 if (!Dest->getLiveRange().containsValue(InstNumber, IsDest)) |
354 Invalid = true; | 354 Invalid = true; |
355 // Check that this instruction actually *begins* Dest's live | 355 // Check that this instruction actually *begins* Dest's live |
356 // range, by checking that Dest is not live in the previous | 356 // range, by checking that Dest is not live in the previous |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 for (CfgNode *Node : Nodes) { | 403 for (CfgNode *Node : Nodes) { |
404 Node->contractIfEmpty(); | 404 Node->contractIfEmpty(); |
405 } | 405 } |
406 } | 406 } |
407 | 407 |
408 void Cfg::doBranchOpt() { | 408 void Cfg::doBranchOpt() { |
409 TimerMarker T(TimerStack::TT_doBranchOpt, this); | 409 TimerMarker T(TimerStack::TT_doBranchOpt, this); |
410 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { | 410 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { |
411 auto NextNode = I; | 411 auto NextNode = I; |
412 ++NextNode; | 412 ++NextNode; |
413 (*I)->doBranchOpt(NextNode == E ? NULL : *NextNode); | 413 (*I)->doBranchOpt(NextNode == E ? nullptr : *NextNode); |
414 } | 414 } |
415 } | 415 } |
416 | 416 |
417 // ======================== Dump routines ======================== // | 417 // ======================== Dump routines ======================== // |
418 | 418 |
419 void Cfg::emitTextHeader(const IceString &MangledName) { | 419 void Cfg::emitTextHeader(const IceString &MangledName) { |
420 // Note: Still used by emit IAS. | 420 // Note: Still used by emit IAS. |
421 Ostream &Str = Ctx->getStrEmit(); | 421 Ostream &Str = Ctx->getStrEmit(); |
422 Str << "\t.text\n"; | 422 Str << "\t.text\n"; |
423 if (Ctx->getFlags().FunctionSections) | 423 if (Ctx->getFlags().FunctionSections) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 } | 521 } |
522 } | 522 } |
523 // Print each basic block | 523 // Print each basic block |
524 for (CfgNode *Node : Nodes) | 524 for (CfgNode *Node : Nodes) |
525 Node->dump(this); | 525 Node->dump(this); |
526 if (getContext()->isVerbose(IceV_Instructions)) | 526 if (getContext()->isVerbose(IceV_Instructions)) |
527 Str << "}\n"; | 527 Str << "}\n"; |
528 } | 528 } |
529 | 529 |
530 } // end of namespace Ice | 530 } // end of namespace Ice |
OLD | NEW |