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

Side by Side Diff: src/IceOperand.h

Issue 650613003: Subzero: Speed up VariablesMetadata initialization. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
1 //===- subzero/src/IceOperand.h - High-level operands -----------*- C++ -*-===// 1 //===- subzero/src/IceOperand.h - High-level operands -----------*- C++ -*-===//
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 declares the Operand class and its target-independent 10 // This file declares the Operand class and its target-independent
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 // portion. TODO: It's wasteful to penalize all variables on all 492 // portion. TODO: It's wasteful to penalize all variables on all
493 // targets this way; use a sparser representation. It's also 493 // targets this way; use a sparser representation. It's also
494 // wasteful for a 64-bit target. 494 // wasteful for a 64-bit target.
495 Variable *LoVar; 495 Variable *LoVar;
496 Variable *HiVar; 496 Variable *HiVar;
497 // VarsReal (and Operand::Vars) are set up such that Vars[0] == 497 // VarsReal (and Operand::Vars) are set up such that Vars[0] ==
498 // this. 498 // this.
499 Variable *VarsReal[1]; 499 Variable *VarsReal[1];
500 }; 500 };
501 501
502 enum MetadataKind {
503 VMK_Uses, // Track only uses, not defs
504 VMK_SingleDefs, // Track uses+defs, but only record single def
505 VMK_All // Track uses+defs, including full def list
506 };
502 typedef std::vector<const Inst *> InstDefList; 507 typedef std::vector<const Inst *> InstDefList;
503 508
504 // VariableTracking tracks the metadata for a single variable. It is 509 // VariableTracking tracks the metadata for a single variable. It is
505 // only meant to be used internally by VariablesMetadata. 510 // only meant to be used internally by VariablesMetadata.
506 class VariableTracking { 511 class VariableTracking {
507 public: 512 public:
508 enum MultiDefState { 513 enum MultiDefState {
509 // TODO(stichnot): Consider using just a simple counter. 514 // TODO(stichnot): Consider using just a simple counter.
510 MDS_Unknown, 515 MDS_Unknown,
511 MDS_SingleDef, 516 MDS_SingleDef,
512 MDS_MultiDefSingleBlock, 517 MDS_MultiDefSingleBlock,
513 MDS_MultiDefMultiBlock 518 MDS_MultiDefMultiBlock
514 }; 519 };
515 enum MultiBlockState { 520 enum MultiBlockState {
516 MBS_Unknown, 521 MBS_Unknown,
517 MBS_SingleBlock, 522 MBS_SingleBlock,
518 MBS_MultiBlock 523 MBS_MultiBlock
519 }; 524 };
520 VariableTracking() 525 VariableTracking()
521 : MultiDef(MDS_Unknown), MultiBlock(MBS_Unknown), SingleUseNode(NULL), 526 : MultiDef(MDS_Unknown), MultiBlock(MBS_Unknown), SingleUseNode(NULL),
522 SingleDefNode(NULL) {} 527 SingleDefNode(NULL), FirstDefinition(NULL) {}
523 MultiDefState getMultiDef() const { return MultiDef; } 528 MultiDefState getMultiDef() const { return MultiDef; }
524 MultiBlockState getMultiBlock() const { return MultiBlock; } 529 MultiBlockState getMultiBlock() const { return MultiBlock; }
525 const Inst *getFirstDefinition() const; 530 const Inst *getFirstDefinition() const;
526 const Inst *getSingleDefinition() const; 531 const Inst *getSingleDefinition() const;
527 const InstDefList &getDefinitions() const { return Definitions; } 532 const InstDefList &getDefinitions() const { return Definitions; }
528 const CfgNode *getNode() const { return SingleUseNode; } 533 const CfgNode *getNode() const { return SingleUseNode; }
529 void markUse(const Inst *Instr, const CfgNode *Node, bool IsFromDef, 534 void markUse(MetadataKind TrackingKind, const Inst *Instr,
530 bool IsImplicit); 535 const CfgNode *Node, bool IsFromDef, bool IsImplicit);
531 void markDef(const Inst *Instr, const CfgNode *Node); 536 void markDef(MetadataKind TrackingKind, const Inst *Instr,
537 const CfgNode *Node);
532 538
533 private: 539 private:
534 VariableTracking &operator=(const VariableTracking &) = delete; 540 VariableTracking &operator=(const VariableTracking &) = delete;
535 MultiDefState MultiDef; 541 MultiDefState MultiDef;
536 MultiBlockState MultiBlock; 542 MultiBlockState MultiBlock;
537 const CfgNode *SingleUseNode; 543 const CfgNode *SingleUseNode;
538 const CfgNode *SingleDefNode; 544 const CfgNode *SingleDefNode;
539 // All definitions of the variable are collected here, in increasing 545 // All definitions of the variable are collected here, in increasing
540 // order of instruction number. 546 // order of instruction number.
541 InstDefList Definitions; 547 InstDefList Definitions; // Only used if Kind==VMK_All
548 const Inst *FirstDefinition; // A copy of Definitions[0] if Kind==VMK_All
542 }; 549 };
543 550
544 // VariablesMetadata analyzes and summarizes the metadata for the 551 // VariablesMetadata analyzes and summarizes the metadata for the
545 // complete set of Variables. 552 // complete set of Variables.
546 class VariablesMetadata { 553 class VariablesMetadata {
547 public: 554 public:
548 VariablesMetadata(const Cfg *Func) : Func(Func) {} 555 VariablesMetadata(const Cfg *Func) : Func(Func) {}
549 // Initialize the state by traversing all instructions/variables in 556 // Initialize the state by traversing all instructions/variables in
550 // the CFG. 557 // the CFG.
551 void init(); 558 void init(MetadataKind TrackingKind);
552 // Returns whether the given Variable is tracked in this object. It 559 // Returns whether the given Variable is tracked in this object. It
553 // should only return false if changes were made to the CFG after 560 // should only return false if changes were made to the CFG after
554 // running init(), in which case the state is stale and the results 561 // running init(), in which case the state is stale and the results
555 // shouldn't be trusted (but it may be OK e.g. for dumping). 562 // shouldn't be trusted (but it may be OK e.g. for dumping).
556 bool isTracked(const Variable *Var) const { 563 bool isTracked(const Variable *Var) const {
557 return Var->getIndex() < Metadata.size(); 564 return Var->getIndex() < Metadata.size();
558 } 565 }
559 566
560 // Returns whether the given Variable has multiple definitions. 567 // Returns whether the given Variable has multiple definitions.
561 bool isMultiDef(const Variable *Var) const; 568 bool isMultiDef(const Variable *Var) const;
(...skipping 19 matching lines...) Expand all
581 // coalescing. As a special case, function arguments are always 588 // coalescing. As a special case, function arguments are always
582 // considered multi-block because they are live coming into the 589 // considered multi-block because they are live coming into the
583 // entry block. 590 // entry block.
584 bool isMultiBlock(const Variable *Var) const; 591 bool isMultiBlock(const Variable *Var) const;
585 // Returns the node that the given Variable is used in, assuming 592 // Returns the node that the given Variable is used in, assuming
586 // isMultiBlock() returns false. Otherwise, NULL is returned. 593 // isMultiBlock() returns false. Otherwise, NULL is returned.
587 const CfgNode *getLocalUseNode(const Variable *Var) const; 594 const CfgNode *getLocalUseNode(const Variable *Var) const;
588 595
589 private: 596 private:
590 const Cfg *Func; 597 const Cfg *Func;
598 MetadataKind Kind;
591 std::vector<VariableTracking> Metadata; 599 std::vector<VariableTracking> Metadata;
592 const static InstDefList NoDefinitions; 600 const static InstDefList NoDefinitions;
593 VariablesMetadata(const VariablesMetadata &) = delete; 601 VariablesMetadata(const VariablesMetadata &) = delete;
594 VariablesMetadata &operator=(const VariablesMetadata &) = delete; 602 VariablesMetadata &operator=(const VariablesMetadata &) = delete;
595 }; 603 };
596 604
597 } // end of namespace Ice 605 } // end of namespace Ice
598 606
599 #endif // SUBZERO_SRC_ICEOPERAND_H 607 #endif // SUBZERO_SRC_ICEOPERAND_H
OLDNEW
« no previous file with comments | « src/IceCfg.cpp ('k') | src/IceOperand.cpp » ('j') | src/IceOperand.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698