Chromium Code Reviews| Index: src/IceOperand.cpp |
| diff --git a/src/IceOperand.cpp b/src/IceOperand.cpp |
| index 3f7d0bff8d05027e7607a4e4817a167dbd3b1159..bad683e27687c8388ea8cc78c9e1905fe9126464 100644 |
| --- a/src/IceOperand.cpp |
| +++ b/src/IceOperand.cpp |
| @@ -185,8 +185,10 @@ Variable Variable::asType(Type Ty) { |
| return V; |
| } |
| -void VariableTracking::markUse(const Inst *Instr, const CfgNode *Node, |
| - bool IsFromDef, bool IsImplicit) { |
| +void VariableTracking::markUse(MetadataKind TrackingKind, const Inst *Instr, |
| + const CfgNode *Node, bool IsFromDef, |
| + bool IsImplicit) { |
| + (void)TrackingKind; |
| if (MultiBlock == MBS_MultiBlock) |
| return; |
| // TODO(stichnot): If the use occurs as a source operand in the |
| @@ -227,19 +229,27 @@ void VariableTracking::markUse(const Inst *Instr, const CfgNode *Node, |
| } |
| } |
| -void VariableTracking::markDef(const Inst *Instr, const CfgNode *Node) { |
| +void VariableTracking::markDef(MetadataKind TrackingKind, const Inst *Instr, |
| + const CfgNode *Node) { |
| // TODO(stichnot): If the definition occurs in the last instruction |
| // of the block, consider not marking this as a separate use. But |
| // be careful not to omit all uses of the variable if markDef() and |
| // markUse() both use this optimization. |
| assert(Node); |
| // Verify that instructions are added in increasing order. |
| - assert(Definitions.empty() || |
| - Instr->getNumber() >= Definitions.back()->getNumber()); |
| - Definitions.push_back(Instr); |
| + if (TrackingKind == VMK_All) { |
| + assert(Definitions.empty() || |
| + Instr->getNumber() >= Definitions.back()->getNumber()); |
| + } |
| const bool IsFromDef = true; |
| const bool IsImplicit = false; |
| - markUse(Instr, Node, IsFromDef, IsImplicit); |
| + markUse(TrackingKind, Instr, Node, IsFromDef, IsImplicit); |
| + if (TrackingKind == VMK_Uses) |
| + return; |
| + if (FirstDefinition == NULL) |
|
jvoung (off chromium)
2014/10/15 17:44:54
Looks like this could be put under "if (TrackingKi
Jim Stichnoth
2014/10/15 21:29:43
Renamed the field to FirstOrSingleDefinition to cl
|
| + FirstDefinition = Instr; |
| + if (TrackingKind == VMK_All) |
| + Definitions.push_back(Instr); |
| switch (MultiDef) { |
| case MDS_Unknown: |
| assert(SingleDefNode == NULL); |
| @@ -275,8 +285,8 @@ const Inst *VariableTracking::getFirstDefinition() const { |
| return NULL; |
| case MDS_SingleDef: |
| case MDS_MultiDefSingleBlock: |
| - assert(!Definitions.empty()); |
| - return Definitions[0]; |
| + assert(FirstDefinition); |
| + return FirstDefinition; |
| } |
| } |
| @@ -287,13 +297,14 @@ const Inst *VariableTracking::getSingleDefinition() const { |
| case MDS_MultiDefSingleBlock: |
| return NULL; |
| case MDS_SingleDef: |
| - assert(!Definitions.empty()); |
| - return Definitions[0]; |
| + assert(FirstDefinition); |
| + return FirstDefinition; |
| } |
| } |
| -void VariablesMetadata::init() { |
| +void VariablesMetadata::init(MetadataKind TrackingKind) { |
| TimerMarker T(TimerStack::TT_vmetadata, Func); |
| + Kind = TrackingKind; |
| Metadata.clear(); |
| Metadata.resize(Func->getNumVariables()); |
| @@ -303,7 +314,8 @@ void VariablesMetadata::init() { |
| const CfgNode *EntryNode = Func->getEntryNode(); |
| const bool IsFromDef = false; |
| const bool IsImplicit = true; |
| - Metadata[Var->getIndex()].markUse(NoInst, EntryNode, IsFromDef, IsImplicit); |
| + Metadata[Var->getIndex()] |
| + .markUse(Kind, NoInst, EntryNode, IsFromDef, IsImplicit); |
| } |
| for (CfgNode *Node : Func->getNodes()) { |
| @@ -318,14 +330,14 @@ void VariablesMetadata::init() { |
| Variable *Var = llvm::cast<Variable>(I->getSrc(SrcNum)); |
| SizeT VarNum = Var->getIndex(); |
| assert(VarNum < Metadata.size()); |
| - Metadata[VarNum].markDef(Kill, Node); |
| + Metadata[VarNum].markDef(Kind, Kill, Node); |
| } |
| continue; // no point in executing the rest |
| } |
| if (Variable *Dest = I->getDest()) { |
| SizeT DestNum = Dest->getIndex(); |
| assert(DestNum < Metadata.size()); |
| - Metadata[DestNum].markDef(I, Node); |
| + Metadata[DestNum].markDef(Kind, I, Node); |
| } |
| for (SizeT SrcNum = 0; SrcNum < I->getSrcSize(); ++SrcNum) { |
| Operand *Src = I->getSrc(SrcNum); |
| @@ -336,7 +348,7 @@ void VariablesMetadata::init() { |
| assert(VarNum < Metadata.size()); |
| const bool IsFromDef = false; |
| const bool IsImplicit = false; |
| - Metadata[VarNum].markUse(I, Node, IsFromDef, IsImplicit); |
| + Metadata[VarNum].markUse(Kind, I, Node, IsFromDef, IsImplicit); |
| } |
| } |
| } |
| @@ -344,6 +356,7 @@ void VariablesMetadata::init() { |
| } |
| bool VariablesMetadata::isMultiDef(const Variable *Var) const { |
| + assert(Kind != VMK_Uses); |
| if (Var->getIsArg()) |
| return false; |
| if (!isTracked(Var)) |
| @@ -364,6 +377,7 @@ bool VariablesMetadata::isMultiBlock(const Variable *Var) const { |
| } |
| const Inst *VariablesMetadata::getFirstDefinition(const Variable *Var) const { |
| + assert(Kind == VMK_All); |
| if (!isTracked(Var)) |
| return NULL; // conservative answer |
| SizeT VarNum = Var->getIndex(); |
| @@ -371,6 +385,7 @@ const Inst *VariablesMetadata::getFirstDefinition(const Variable *Var) const { |
| } |
| const Inst *VariablesMetadata::getSingleDefinition(const Variable *Var) const { |
| + assert(Kind != VMK_Uses); |
| if (!isTracked(Var)) |
| return NULL; // conservative answer |
| SizeT VarNum = Var->getIndex(); |
| @@ -379,6 +394,7 @@ const Inst *VariablesMetadata::getSingleDefinition(const Variable *Var) const { |
| const InstDefList & |
| VariablesMetadata::getDefinitions(const Variable *Var) const { |
| + assert(Kind == VMK_All); |
| if (!isTracked(Var)) |
| return NoDefinitions; |
| SizeT VarNum = Var->getIndex(); |