Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 //===- subzero/src/IceInst.cpp - High-level instruction implementation ----===// | 1 //===- subzero/src/IceInst.cpp - High-level instruction 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 /// \file | 10 /// \file |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 | 297 |
| 298 bool InstAssign::isVarAssign() const { return llvm::isa<Variable>(getSrc(0)); } | 298 bool InstAssign::isVarAssign() const { return llvm::isa<Variable>(getSrc(0)); } |
| 299 | 299 |
| 300 // If TargetTrue==TargetFalse, we turn it into an unconditional branch. This | 300 // If TargetTrue==TargetFalse, we turn it into an unconditional branch. This |
| 301 // ensures that, along with the 'switch' instruction semantics, there is at | 301 // ensures that, along with the 'switch' instruction semantics, there is at |
| 302 // most one edge from one node to another. | 302 // most one edge from one node to another. |
| 303 InstBr::InstBr(Cfg *Func, Operand *Source, CfgNode *TargetTrue_, | 303 InstBr::InstBr(Cfg *Func, Operand *Source, CfgNode *TargetTrue_, |
| 304 CfgNode *TargetFalse_) | 304 CfgNode *TargetFalse_) |
| 305 : InstHighLevel(Func, Inst::Br, 1, nullptr), TargetFalse(TargetFalse_), | 305 : InstHighLevel(Func, Inst::Br, 1, nullptr), TargetFalse(TargetFalse_), |
| 306 TargetTrue(TargetTrue_) { | 306 TargetTrue(TargetTrue_) { |
| 307 if (TargetTrue == TargetFalse) { | 307 |
|
Jim Stichnoth
2016/04/02 01:19:52
remove initial blank line
sehr
2016/04/04 15:38:51
Done.
| |
| 308 if (auto *Constant = llvm::dyn_cast<ConstantInteger32>(Source)) { | |
|
Jim Stichnoth
2016/04/02 01:19:52
I would name it something like "C32", that isn't a
sehr
2016/04/04 15:38:51
Done.
| |
| 309 int32_t Value = Constant->getValue(); | |
| 310 if (Value != 0) { | |
| 311 TargetFalse = TargetTrue; | |
| 312 } | |
| 313 TargetTrue = nullptr; // turn into unconditional version | |
| 314 } else if (TargetTrue == TargetFalse) { | |
| 308 TargetTrue = nullptr; // turn into unconditional version | 315 TargetTrue = nullptr; // turn into unconditional version |
| 309 } else { | 316 } else { |
| 310 addSource(Source); | 317 addSource(Source); |
| 311 } | 318 } |
| 312 } | 319 } |
| 313 | 320 |
| 314 InstBr::InstBr(Cfg *Func, CfgNode *Target) | 321 InstBr::InstBr(Cfg *Func, CfgNode *Target) |
| 315 : InstHighLevel(Func, Inst::Br, 0, nullptr), TargetFalse(Target), | 322 : InstHighLevel(Func, Inst::Br, 0, nullptr), TargetFalse(Target), |
| 316 TargetTrue(nullptr) {} | 323 TargetTrue(nullptr) {} |
| 317 | 324 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 396 // becomes a problem. | 403 // becomes a problem. |
| 397 Operand *InstPhi::getOperandForTarget(CfgNode *Target) const { | 404 Operand *InstPhi::getOperandForTarget(CfgNode *Target) const { |
| 398 for (SizeT I = 0; I < getSrcSize(); ++I) { | 405 for (SizeT I = 0; I < getSrcSize(); ++I) { |
| 399 if (Labels[I] == Target) | 406 if (Labels[I] == Target) |
| 400 return getSrc(I); | 407 return getSrc(I); |
| 401 } | 408 } |
| 402 llvm_unreachable("Phi target not found"); | 409 llvm_unreachable("Phi target not found"); |
| 403 return nullptr; | 410 return nullptr; |
| 404 } | 411 } |
| 405 | 412 |
| 413 // Replace the source operand corresponding to the incoming edge for the given | |
| 414 // node by a zero of the appropriate type. TODO: This uses a linear-time search, | |
|
Jim Stichnoth
2016/04/02 01:19:52
TODO(owner)
Actually, maybe this TODO and the ide
sehr
2016/04/04 15:38:51
Done.
| |
| 415 // which could be improved if it becomes a problem. | |
| 416 void InstPhi::clearOperandForTarget(CfgNode *Target) { | |
| 417 for (SizeT I = 0; I < getSrcSize(); ++I) { | |
| 418 if (getLabel(I) == Target) { | |
| 419 Type Ty = Dest->getType(); | |
| 420 Srcs[I] = Target->getCfg()->getContext()->getConstantZero(Ty); | |
| 421 return; | |
| 422 } | |
| 423 } | |
| 424 llvm_unreachable("Phi target not found"); | |
| 425 } | |
| 426 | |
| 406 // Updates liveness for a particular operand based on the given predecessor | 427 // Updates liveness for a particular operand based on the given predecessor |
| 407 // edge. Doesn't mark the operand as live if the Phi instruction is dead or | 428 // edge. Doesn't mark the operand as live if the Phi instruction is dead or |
| 408 // deleted. | 429 // deleted. |
| 409 void InstPhi::livenessPhiOperand(LivenessBV &Live, CfgNode *Target, | 430 void InstPhi::livenessPhiOperand(LivenessBV &Live, CfgNode *Target, |
| 410 Liveness *Liveness) { | 431 Liveness *Liveness) { |
| 411 if (isDeleted() || Dead) | 432 if (isDeleted() || Dead) |
| 412 return; | 433 return; |
| 413 for (SizeT I = 0; I < getSrcSize(); ++I) { | 434 for (SizeT I = 0; I < getSrcSize(); ++I) { |
| 414 if (Labels[I] == Target) { | 435 if (Labels[I] == Target) { |
| 415 if (auto *Var = llvm::dyn_cast<Variable>(getSrc(I))) { | 436 if (auto *Var = llvm::dyn_cast<Variable>(getSrc(I))) { |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1015 // upper 32 bits of rax. We need to recognize and preserve these. | 1036 // upper 32 bits of rax. We need to recognize and preserve these. |
| 1016 return true; | 1037 return true; |
| 1017 } | 1038 } |
| 1018 if (!Dest->hasReg() && !SrcVar->hasReg() && | 1039 if (!Dest->hasReg() && !SrcVar->hasReg() && |
| 1019 Dest->getStackOffset() == SrcVar->getStackOffset()) | 1040 Dest->getStackOffset() == SrcVar->getStackOffset()) |
| 1020 return true; | 1041 return true; |
| 1021 return false; | 1042 return false; |
| 1022 } | 1043 } |
| 1023 | 1044 |
| 1024 } // end of namespace Ice | 1045 } // end of namespace Ice |
| OLD | NEW |