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

Side by Side Diff: src/IceCfg.cpp

Issue 848193003: Subzero: Add locking to prepare for multithreaded translation. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Code review changes Created 5 years, 11 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 | « no previous file | src/IceConverter.cpp » ('j') | src/IceGlobalContext.h » ('J')
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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());
460 OstreamLocker L(Ctx);
457 if (!Ctx->getFlags().UseELFWriter) 461 if (!Ctx->getFlags().UseELFWriter)
jvoung (off chromium) 2015/01/15 18:20:40 Technically, the lock doesn't need to be held this
Jim Stichnoth 2015/01/17 18:44:16 Done.
458 emitTextHeader(MangledName); 462 emitTextHeader(MangledName);
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 {
467 getAssembler<Assembler>()->emitIASBytes(Ctx); 471 getAssembler<Assembler>()->emitIASBytes(Ctx);
468 } 472 }
469 } 473 }
470 474
471 // Dumps the IR with an optional introductory message. 475 // Dumps the IR with an optional introductory message.
472 void Cfg::dump(const IceString &Message) { 476 void Cfg::dump(const IceString &Message) {
473 if (!ALLOW_DUMP) 477 if (!ALLOW_DUMP)
474 return; 478 return;
475 if (!Ctx->isVerbose()) 479 if (!Ctx->isVerbose())
476 return; 480 return;
481 OstreamLocker L(Ctx);
477 Ostream &Str = Ctx->getStrDump(); 482 Ostream &Str = Ctx->getStrDump();
478 if (!Message.empty()) 483 if (!Message.empty())
479 Str << "================ " << Message << " ================\n"; 484 Str << "================ " << Message << " ================\n";
480 setCurrentNode(getEntryNode()); 485 setCurrentNode(getEntryNode());
481 // Print function name+args 486 // Print function name+args
482 if (getContext()->isVerbose(IceV_Instructions)) { 487 if (getContext()->isVerbose(IceV_Instructions)) {
483 Str << "define "; 488 Str << "define ";
484 if (getInternal() && !Ctx->getFlags().DisableInternal) 489 if (getInternal() && !Ctx->getFlags().DisableInternal)
485 Str << "internal "; 490 Str << "internal ";
486 Str << ReturnType << " @" << Ctx->mangleName(getFunctionName()) << "("; 491 Str << ReturnType << " @" << Ctx->mangleName(getFunctionName()) << "(";
(...skipping 20 matching lines...) Expand all
507 } 512 }
508 } 513 }
509 // Print each basic block 514 // Print each basic block
510 for (CfgNode *Node : Nodes) 515 for (CfgNode *Node : Nodes)
511 Node->dump(this); 516 Node->dump(this);
512 if (getContext()->isVerbose(IceV_Instructions)) 517 if (getContext()->isVerbose(IceV_Instructions))
513 Str << "}\n"; 518 Str << "}\n";
514 } 519 }
515 520
516 } // end of namespace Ice 521 } // end of namespace Ice
OLDNEW
« no previous file with comments | « no previous file | src/IceConverter.cpp » ('j') | src/IceGlobalContext.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698