| OLD | NEW |
| 1 //===- subzero/src/IceCfgNode.cpp - Basic block (node) implementation -----===// | 1 //===- subzero/src/IceCfgNode.cpp - Basic block (node) 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 CfgNode class, including the complexities | 10 // This file implements the CfgNode class, including the complexities |
| 11 // of instruction insertion and in-edge calculation. | 11 // of instruction insertion and in-edge calculation. |
| 12 // | 12 // |
| 13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
| 14 | 14 |
| 15 #include "IceCfgNode.h" | 15 #include "IceCfgNode.h" |
| 16 | 16 |
| 17 #include "IceAssembler.h" | 17 #include "IceAssembler.h" |
| 18 #include "IceCfg.h" | 18 #include "IceCfg.h" |
| 19 #include "IceGlobalInits.h" | 19 #include "IceGlobalInits.h" |
| 20 #include "IceInst.h" | 20 #include "IceInst.h" |
| 21 #include "IceLiveness.h" | 21 #include "IceLiveness.h" |
| 22 #include "IceOperand.h" | 22 #include "IceOperand.h" |
| 23 #include "IceTargetLowering.h" | 23 #include "IceTargetLowering.h" |
| 24 | 24 |
| 25 namespace Ice { | 25 namespace Ice { |
| 26 | 26 |
| 27 CfgNode::CfgNode(Cfg *Func, SizeT LabelNumber) | 27 CfgNode::CfgNode(Cfg *MyFunc, SizeT LabelNumber) |
| 28 : Func(Func), Number(LabelNumber) {} | 28 : Func(MyFunc), Number(LabelNumber) {} |
| 29 | 29 |
| 30 // Returns the name the node was created with. If no name was given, | 30 // Returns the name the node was created with. If no name was given, |
| 31 // it synthesizes a (hopefully) unique name. | 31 // it synthesizes a (hopefully) unique name. |
| 32 IceString CfgNode::getName() const { | 32 IceString CfgNode::getName() const { |
| 33 if (NameIndex >= 0) | 33 if (NameIndex >= 0) |
| 34 return Func->getIdentifierName(NameIndex); | 34 return Func->getIdentifierName(NameIndex); |
| 35 return "__" + std::to_string(getIndex()); | 35 return "__" + std::to_string(getIndex()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Adds an instruction to either the Phi list or the regular | 38 // Adds an instruction to either the Phi list or the regular |
| (...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 if (Variable *Src = llvm::dyn_cast<Variable>(I->getSrc(S))) { | 875 if (Variable *Src = llvm::dyn_cast<Variable>(I->getSrc(S))) { |
| 876 if (!Src->hasReg()) | 876 if (!Src->hasReg()) |
| 877 Func->getContext()->statsUpdateSpills(); | 877 Func->getContext()->statsUpdateSpills(); |
| 878 } | 878 } |
| 879 } | 879 } |
| 880 } | 880 } |
| 881 } | 881 } |
| 882 | 882 |
| 883 } // end of anonymous namespace | 883 } // end of anonymous namespace |
| 884 | 884 |
| 885 void CfgNode::emit(Cfg *Func) const { | 885 void CfgNode::emit() const { |
| 886 if (!BuildDefs::dump()) | 886 if (!BuildDefs::dump()) |
| 887 return; | 887 return; |
| 888 Func->setCurrentNode(this); | 888 Func->setCurrentNode(this); |
| 889 Ostream &Str = Func->getContext()->getStrEmit(); | 889 Ostream &Str = Func->getContext()->getStrEmit(); |
| 890 Liveness *Liveness = Func->getLiveness(); | 890 Liveness *Liveness = Func->getLiveness(); |
| 891 bool DecorateAsm = | 891 bool DecorateAsm = |
| 892 Liveness && Func->getContext()->getFlags().getDecorateAsm(); | 892 Liveness && Func->getContext()->getFlags().getDecorateAsm(); |
| 893 Str << getAsmName() << ":\n"; | 893 Str << getAsmName() << ":\n"; |
| 894 // LiveRegCount keeps track of the number of currently live | 894 // LiveRegCount keeps track of the number of currently live |
| 895 // variables that each register is assigned to. Normally that would | 895 // variables that each register is assigned to. Normally that would |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 } | 938 } |
| 939 | 939 |
| 940 // Helper class for emitIAS(). | 940 // Helper class for emitIAS(). |
| 941 namespace { | 941 namespace { |
| 942 class BundleEmitHelper { | 942 class BundleEmitHelper { |
| 943 BundleEmitHelper() = delete; | 943 BundleEmitHelper() = delete; |
| 944 BundleEmitHelper(const BundleEmitHelper &) = delete; | 944 BundleEmitHelper(const BundleEmitHelper &) = delete; |
| 945 BundleEmitHelper &operator=(const BundleEmitHelper &) = delete; | 945 BundleEmitHelper &operator=(const BundleEmitHelper &) = delete; |
| 946 | 946 |
| 947 public: | 947 public: |
| 948 BundleEmitHelper(Assembler *Asm, TargetLowering *Target, | 948 BundleEmitHelper(Assembler *MyAsm, TargetLowering *MyTarget, |
| 949 const InstList &Insts) | 949 const InstList &Insts) |
| 950 : Asm(Asm), Target(Target), End(Insts.end()), BundleLockStart(End), | 950 : Asm(MyAsm), Target(MyTarget), End(Insts.end()), BundleLockStart(End), |
| 951 BundleSize(1 << Asm->getBundleAlignLog2Bytes()), | 951 BundleSize(1 << Asm->getBundleAlignLog2Bytes()), |
| 952 BundleMaskLo(BundleSize - 1), BundleMaskHi(~BundleMaskLo) {} | 952 BundleMaskLo(BundleSize - 1), BundleMaskHi(~BundleMaskLo) {} |
| 953 // Check whether we're currently within a bundle_lock region. | 953 // Check whether we're currently within a bundle_lock region. |
| 954 bool isInBundleLockRegion() const { return BundleLockStart != End; } | 954 bool isInBundleLockRegion() const { return BundleLockStart != End; } |
| 955 // Check whether the current bundle_lock region has the align_to_end | 955 // Check whether the current bundle_lock region has the align_to_end |
| 956 // option. | 956 // option. |
| 957 bool isAlignToEnd() const { | 957 bool isAlignToEnd() const { |
| 958 assert(isInBundleLockRegion()); | 958 assert(isInBundleLockRegion()); |
| 959 return llvm::cast<InstBundleLock>(getBundleLockStart())->getOption() == | 959 return llvm::cast<InstBundleLock>(getBundleLockStart())->getOption() == |
| 960 InstBundleLock::Opt_AlignToEnd; | 960 InstBundleLock::Opt_AlignToEnd; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 // Masking with BundleMaskLo identifies an address's bundle offset. | 1048 // Masking with BundleMaskLo identifies an address's bundle offset. |
| 1049 const intptr_t BundleMaskLo; | 1049 const intptr_t BundleMaskLo; |
| 1050 // Masking with BundleMaskHi identifies an address's bundle. | 1050 // Masking with BundleMaskHi identifies an address's bundle. |
| 1051 const intptr_t BundleMaskHi; | 1051 const intptr_t BundleMaskHi; |
| 1052 intptr_t SizeSnapshotPre = 0; | 1052 intptr_t SizeSnapshotPre = 0; |
| 1053 intptr_t SizeSnapshotPost = 0; | 1053 intptr_t SizeSnapshotPost = 0; |
| 1054 }; | 1054 }; |
| 1055 | 1055 |
| 1056 } // end of anonymous namespace | 1056 } // end of anonymous namespace |
| 1057 | 1057 |
| 1058 void CfgNode::emitIAS(Cfg *Func) const { | 1058 void CfgNode::emitIAS() const { |
| 1059 Func->setCurrentNode(this); | 1059 Func->setCurrentNode(this); |
| 1060 Assembler *Asm = Func->getAssembler<>(); | 1060 Assembler *Asm = Func->getAssembler<>(); |
| 1061 // TODO(stichnot): When sandboxing, defer binding the node label | 1061 // TODO(stichnot): When sandboxing, defer binding the node label |
| 1062 // until just before the first instruction is emitted, to reduce the | 1062 // until just before the first instruction is emitted, to reduce the |
| 1063 // chance that a padding nop is a branch target. | 1063 // chance that a padding nop is a branch target. |
| 1064 Asm->bindCfgNodeLabel(getIndex()); | 1064 Asm->bindCfgNodeLabel(getIndex()); |
| 1065 for (const Inst &I : Phis) { | 1065 for (const Inst &I : Phis) { |
| 1066 if (I.isDeleted()) | 1066 if (I.isDeleted()) |
| 1067 continue; | 1067 continue; |
| 1068 // Emitting a Phi instruction should cause an error. | 1068 // Emitting a Phi instruction should cause an error. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 Helper.leaveBundleLockRegion(); | 1156 Helper.leaveBundleLockRegion(); |
| 1157 } | 1157 } |
| 1158 } | 1158 } |
| 1159 | 1159 |
| 1160 // Don't allow bundle locking across basic blocks, to keep the | 1160 // Don't allow bundle locking across basic blocks, to keep the |
| 1161 // backtracking mechanism simple. | 1161 // backtracking mechanism simple. |
| 1162 assert(!Helper.isInBundleLockRegion()); | 1162 assert(!Helper.isInBundleLockRegion()); |
| 1163 assert(!Retrying); | 1163 assert(!Retrying); |
| 1164 } | 1164 } |
| 1165 | 1165 |
| 1166 void CfgNode::dump(Cfg *Func) const { | 1166 void CfgNode::dump() const { |
| 1167 if (!BuildDefs::dump()) | 1167 if (!BuildDefs::dump()) |
| 1168 return; | 1168 return; |
| 1169 Func->setCurrentNode(this); | 1169 Func->setCurrentNode(this); |
| 1170 Ostream &Str = Func->getContext()->getStrDump(); | 1170 Ostream &Str = Func->getContext()->getStrDump(); |
| 1171 Liveness *Liveness = Func->getLiveness(); | 1171 Liveness *Liveness = Func->getLiveness(); |
| 1172 if (Func->isVerbose(IceV_Instructions)) { | 1172 if (Func->isVerbose(IceV_Instructions)) { |
| 1173 Str << getName() << ":\n"; | 1173 Str << getName() << ":\n"; |
| 1174 } | 1174 } |
| 1175 // Dump list of predecessor nodes. | 1175 // Dump list of predecessor nodes. |
| 1176 if (Func->isVerbose(IceV_Preds) && !InEdges.empty()) { | 1176 if (Func->isVerbose(IceV_Preds) && !InEdges.empty()) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 InstIntrinsicCall *Inst = InstIntrinsicCall::create( | 1267 InstIntrinsicCall *Inst = InstIntrinsicCall::create( |
| 1268 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info); | 1268 Func, 5, Func->makeVariable(IceType_i64), RMWI64Name, Info->Info); |
| 1269 Inst->addArg(AtomicRMWOp); | 1269 Inst->addArg(AtomicRMWOp); |
| 1270 Inst->addArg(Counter); | 1270 Inst->addArg(Counter); |
| 1271 Inst->addArg(One); | 1271 Inst->addArg(One); |
| 1272 Inst->addArg(OrderAcquireRelease); | 1272 Inst->addArg(OrderAcquireRelease); |
| 1273 Insts.push_front(Inst); | 1273 Insts.push_front(Inst); |
| 1274 } | 1274 } |
| 1275 | 1275 |
| 1276 } // end of namespace Ice | 1276 } // end of namespace Ice |
| OLD | NEW |