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

Side by Side Diff: src/IceCfgNode.cpp

Issue 930733002: Subzero: Add sandboxing for x86-32. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Add bundle alignment to the instruction emission loop Created 5 years, 10 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 | « src/IceCfg.cpp ('k') | src/IceInst.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 Str << ","; 827 Str << ",";
828 Var->emit(Func); 828 Var->emit(Func);
829 First = false; 829 First = false;
830 } 830 }
831 } 831 }
832 } 832 }
833 } 833 }
834 } 834 }
835 835
836 void updateStats(Cfg *Func, const Inst *I) { 836 void updateStats(Cfg *Func, const Inst *I) {
837 if (!ALLOW_DUMP)
838 return;
837 // Update emitted instruction count, plus fill/spill count for 839 // Update emitted instruction count, plus fill/spill count for
838 // Variable operands without a physical register. 840 // Variable operands without a physical register.
839 if (uint32_t Count = I->getEmitInstCount()) { 841 if (uint32_t Count = I->getEmitInstCount()) {
840 Func->getContext()->statsUpdateEmitted(Count); 842 Func->getContext()->statsUpdateEmitted(Count);
841 if (Variable *Dest = I->getDest()) { 843 if (Variable *Dest = I->getDest()) {
842 if (!Dest->hasReg()) 844 if (!Dest->hasReg())
843 Func->getContext()->statsUpdateFills(); 845 Func->getContext()->statsUpdateFills();
844 } 846 }
845 for (SizeT S = 0; S < I->getSrcSize(); ++S) { 847 for (SizeT S = 0; S < I->getSrcSize(); ++S) {
846 if (Variable *Src = llvm::dyn_cast<Variable>(I->getSrc(S))) { 848 if (Variable *Src = llvm::dyn_cast<Variable>(I->getSrc(S))) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 void CfgNode::emitIAS(Cfg *Func) const { 896 void CfgNode::emitIAS(Cfg *Func) const {
895 Func->setCurrentNode(this); 897 Func->setCurrentNode(this);
896 Assembler *Asm = Func->getAssembler<>(); 898 Assembler *Asm = Func->getAssembler<>();
897 Asm->BindCfgNodeLabel(getIndex()); 899 Asm->BindCfgNodeLabel(getIndex());
898 for (const Inst &I : Phis) { 900 for (const Inst &I : Phis) {
899 if (I.isDeleted()) 901 if (I.isDeleted())
900 continue; 902 continue;
901 // Emitting a Phi instruction should cause an error. 903 // Emitting a Phi instruction should cause an error.
902 I.emitIAS(Func); 904 I.emitIAS(Func);
903 } 905 }
904 for (const Inst &I : Insts) { 906
905 if (I.isDeleted()) 907 // Do the simple emission if not sandboxed.
908 if (!Func->getContext()->getFlags().getUseSandboxing()) {
909 for (const Inst &I : Insts) {
910 if (!I.isDeleted() && !I.isRedundantAssign()) {
911 I.emitIAS(Func);
912 updateStats(Func, &I);
913 }
914 }
915 return;
916 }
917 // The remainder of the function handles emission with sandboxing.
918
919 // BundleMask is used for testing whether emission has crossed a
920 // bundle boundary.
921 const intptr_t BundleSize = 1 << Asm->getBundleAlignLog2Bytes();
922 const intptr_t BundleMask = ~(BundleSize - 1);
923 InstList::const_iterator End = Insts.end();
924 // BundleLockStart points to the BundleLock instruction for the
925 // current BundleLock region, or the sentinel value End if we're not
926 // within a BundleLock region.
927 InstList::const_iterator BundleLockStart = End;
928 // Retrying indicates that we had to roll back to BundleLockStart in
929 // order to apply padding before the BundleLock sequence.
930 bool Retrying = false;
931 intptr_t SizeSnaphotPre = 0;
932 for (InstList::const_iterator I = Insts.begin(); I != End; ++I) {
933 if (I->isDeleted() || I->isRedundantAssign())
906 continue; 934 continue;
907 if (I.isRedundantAssign()) 935 if (llvm::isa<InstBundleLock>(I)) {
936 // Set up the initial BundleLock state. This should not happen
937 // while retrying, because the retry rolls back to the
938 // instruction following the BundleLock instruction.
939 assert(!Retrying);
940 assert(BundleLockStart == End);
941 BundleLockStart = I;
942 SizeSnaphotPre = Asm->getBufferSize();
908 continue; 943 continue;
909 I.emitIAS(Func); 944 }
910 updateStats(Func, &I); 945 if (llvm::isa<InstBundleUnlock>(I)) {
946 assert(BundleLockStart != End);
947 intptr_t SizeSnaphotPost = Asm->getBufferSize();
948 switch (llvm::cast<InstBundleLock>(BundleLockStart)->getOption()) {
949 case InstBundleLock::Opt_None:
950 // If this is the first pass, check whether a bundle boundary
951 // was crossed, and if so, roll back, add padding, and retry.
952 // If this is the retry pass, just validate that the bundle
953 // boundary was not crossed.
954 if (Retrying) {
955 assert((SizeSnaphotPre & BundleMask) ==
956 (SizeSnaphotPost & BundleMask));
957 // The fallthrough will reset the BundleLock status and
958 // continue.
959 } else {
960 if ((SizeSnaphotPre & BundleMask) != (SizeSnaphotPost & BundleMask)) {
961 Asm->setBufferSize(SizeSnaphotPre);
962 Asm->padWithNop(BundleSize - (SizeSnaphotPre & (BundleSize - 1)));
963 assert((Asm->getBufferSize() & ~BundleMask) == 0);
964 SizeSnaphotPre = Asm->getBufferSize();
965 Retrying = true;
966 I = BundleLockStart;
967 continue;
968 }
969 }
970 break;
971 case InstBundleLock::Opt_AlignToEnd: {
972 // If we are already aligned at a bundle boundary, then just
973 // continue. Otherwise, make sure we are not already
974 // retrying, then roll back, pad to the next bundle boundary
975 // if the instructions won't fit, then pad for alignment, then
976 // retry.
977 if (SizeSnaphotPost & (BundleSize - 1)) {
978 assert(!Retrying);
979 Asm->setBufferSize(SizeSnaphotPre);
980 Asm->padWithNop(BundleSize - (SizeSnaphotPre & (BundleSize - 1)));
981 assert((Asm->getBufferSize() & ~BundleMask) == 0);
982 Asm->padWithNop(BundleSize - (SizeSnaphotPost - SizeSnaphotPre));
983 Retrying = true;
984 I = BundleLockStart;
985 continue;
986 }
987 } break;
988 }
989 // Not retrying, so reset the bundling state.
990 BundleLockStart = End;
991 Retrying = false;
992 continue;
993 }
994 // At this point, I points to a non-bundling instruction.
995 intptr_t BufSizePre = Asm->getBufferSize();
996 I->emitIAS(Func);
997 if (!Retrying)
998 updateStats(Func, I);
999 intptr_t BufSizePost = Asm->getBufferSize();
1000 if (BundleLockStart == End) {
1001 // Not within a BundleLock region, so do a mini-retry if the
1002 // instruction crosses a bundle boundary. Note that if we are
1003 // within a BundleLock region, we explicitly don't want to add
1004 // inter-instruction padding because it would mess up the
1005 // align_to_end calculation.
1006 if ((BufSizePre & BundleMask) != (BufSizePost & BundleMask)) {
jvoung (off chromium) 2015/02/17 22:57:45 Maybe put this into an inlined helper function.
Jim Stichnoth 2015/02/18 07:06:14 Yeah, this started getting out of control and so I
1007 Asm->setBufferSize(BufSizePre);
1008 Asm->padWithNop((BufSizePost & BundleMask) - BufSizePre);
1009 assert((Asm->getBufferSize() & ~BundleMask) == 0);
1010 I->emitIAS(Func);
jvoung (off chromium) 2015/02/17 22:57:45 Besides labels being bound twice, I think the othe
Jim Stichnoth 2015/02/18 07:06:14 IIUC, binding labels twice isn't fundamentally muc
1011 }
1012 }
911 } 1013 }
1014
1015 // Don't allow bundle locking across basic blocks, to keep the
1016 // backtracking mechanism simple.
1017 assert(BundleLockStart == End);
1018 assert(!Retrying);
912 } 1019 }
913 1020
914 void CfgNode::dump(Cfg *Func) const { 1021 void CfgNode::dump(Cfg *Func) const {
915 if (!ALLOW_DUMP) 1022 if (!ALLOW_DUMP)
916 return; 1023 return;
917 Func->setCurrentNode(this); 1024 Func->setCurrentNode(this);
918 Ostream &Str = Func->getContext()->getStrDump(); 1025 Ostream &Str = Func->getContext()->getStrDump();
919 Liveness *Liveness = Func->getLiveness(); 1026 Liveness *Liveness = Func->getLiveness();
920 if (Func->isVerbose(IceV_Instructions)) { 1027 if (Func->isVerbose(IceV_Instructions)) {
921 Str << getName() << ":\n"; 1028 Str << getName() << ":\n";
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 if (!First) 1092 if (!First)
986 Str << ", "; 1093 Str << ", ";
987 First = false; 1094 First = false;
988 Str << "%" << I->getName(); 1095 Str << "%" << I->getName();
989 } 1096 }
990 Str << "\n"; 1097 Str << "\n";
991 } 1098 }
992 } 1099 }
993 1100
994 } // end of namespace Ice 1101 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceCfg.cpp ('k') | src/IceInst.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698