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

Side by Side Diff: src/IceTargetLoweringARM32.h

Issue 1491473002: Subzero. ARM32. Initial sandboxing code. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Renames run-pnacl-sz argument. Created 5 years 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 | « pydir/targets.py ('k') | src/IceTargetLoweringARM32.cpp » ('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/IceTargetLoweringARM32.h - ARM32 lowering ----*- C++ -*-===// 1 //===- subzero/src/IceTargetLoweringARM32.h - ARM32 lowering ----*- 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 /// \file 10 /// \file
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 int32_t RegNum = Variable::NoRegister); 155 int32_t RegNum = Variable::NoRegister);
156 Variable *legalizeToReg(Operand *From, int32_t RegNum = Variable::NoRegister); 156 Variable *legalizeToReg(Operand *From, int32_t RegNum = Variable::NoRegister);
157 157
158 OperandARM32ShAmtImm *shAmtImm(uint32_t ShAmtImm) const { 158 OperandARM32ShAmtImm *shAmtImm(uint32_t ShAmtImm) const {
159 assert(ShAmtImm < 32); 159 assert(ShAmtImm < 32);
160 return OperandARM32ShAmtImm::create( 160 return OperandARM32ShAmtImm::create(
161 Func, 161 Func,
162 llvm::cast<ConstantInteger32>(Ctx->getConstantInt32(ShAmtImm & 0x1F))); 162 llvm::cast<ConstantInteger32>(Ctx->getConstantInt32(ShAmtImm & 0x1F)));
163 } 163 }
164 164
165 OperandARM32FlexImm *indirectBranchBicMask() const {
166 constexpr uint32_t Imm8 = 0xFC; // 0xC000000F
167 constexpr uint32_t RotateAmt = 2;
168 return OperandARM32FlexImm::create(Func, IceType_i32, Imm8, RotateAmt);
169 }
170
171 OperandARM32FlexImm *memOpBicMask() const {
172 constexpr uint32_t Imm8 = 0x0C; // 0xC0000000
173 constexpr uint32_t RotateAmt = 2;
174 return OperandARM32FlexImm::create(Func, IceType_i32, Imm8, RotateAmt);
175 }
176
165 GlobalContext *getCtx() const { return Ctx; } 177 GlobalContext *getCtx() const { return Ctx; }
166 178
167 protected: 179 protected:
168 explicit TargetARM32(Cfg *Func); 180 explicit TargetARM32(Cfg *Func);
169 181
170 void postLower() override; 182 void postLower() override;
171 183
172 enum SafeBoolChain { 184 enum SafeBoolChain {
173 SBC_No, 185 SBC_No,
174 SBC_Yes, 186 SBC_Yes,
(...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 // TODO(jpp): This could live in the Parser, if we provided a Target-specific 827 // TODO(jpp): This could live in the Parser, if we provided a Target-specific
816 // method that the Parser could call. 828 // method that the Parser could call.
817 void findMaxStackOutArgsSize(); 829 void findMaxStackOutArgsSize();
818 830
819 /// Returns true if the given Offset can be represented in a Load/Store Mem 831 /// Returns true if the given Offset can be represented in a Load/Store Mem
820 /// Operand. 832 /// Operand.
821 bool isLegalMemOffset(Type Ty, int32_t Offset) const; 833 bool isLegalMemOffset(Type Ty, int32_t Offset) const;
822 834
823 void postLowerLegalization(); 835 void postLowerLegalization();
824 836
837 class AutoSandboxer {
838 public:
839 explicit AutoSandboxer(
840 TargetARM32 *Target,
841 InstBundleLock::Option BundleOption = InstBundleLock::Opt_None)
842 : Target(Target) {
843 if (Target->NeedSandboxing) {
844 Target->_bundle_lock(BundleOption);
845 }
846 }
847
848 void add_sp(Operand *AddAmount) {
849 Variable *SP = Target->getPhysicalRegister(RegARM32::Reg_sp);
850 Target->_add(SP, SP, AddAmount);
851 if (Target->NeedSandboxing) {
852 Target->_bic(SP, SP, Target->memOpBicMask());
853 }
854 }
855
856 void align_sp(size_t Alignment) {
857 Variable *SP = Target->getPhysicalRegister(RegARM32::Reg_sp);
858 Target->alignRegisterPow2(SP, Alignment);
859 if (Target->NeedSandboxing) {
860 Target->_bic(SP, SP, Target->memOpBicMask());
861 }
862 }
863
864 InstARM32Call *bl(Variable *ReturnReg, Operand *CallTarget) {
865 if (Target->NeedSandboxing) {
866 if (auto *CallTargetR = llvm::dyn_cast<Variable>(CallTarget)) {
867 Target->_bic(CallTargetR, CallTargetR,
868 Target->indirectBranchBicMask());
869 }
870 }
871 auto *Call = InstARM32Call::create(Target->Func, ReturnReg, CallTarget);
872 Target->Context.insert(Call);
873 return Call;
874 }
875
876 void ldr(Variable *Dest, OperandARM32Mem *Mem, CondARM32::Cond Pred) {
877 if (Target->NeedSandboxing) {
878 assert(!Mem->isRegReg());
879 Variable *MemBase = Mem->getBase();
880 Target->_bic(MemBase, MemBase, Target->memOpBicMask(), Pred);
881 }
882 Target->_ldr(Dest, Mem, Pred);
883 }
884
885 void ldrex(Variable *Dest, OperandARM32Mem *Mem, CondARM32::Cond Pred) {
886 if (Target->NeedSandboxing) {
887 assert(!Mem->isRegReg());
888 Variable *MemBase = Mem->getBase();
889 Target->_bic(MemBase, MemBase, Target->memOpBicMask(), Pred);
890 }
891 Target->_ldrex(Dest, Mem, Pred);
892 }
893
894 void reset_sp(Variable *Src) {
895 Variable *SP = Target->getPhysicalRegister(RegARM32::Reg_sp);
896 Target->_mov_redefined(SP, Src);
897 if (Target->NeedSandboxing) {
898 Target->_bic(SP, SP, Target->memOpBicMask());
899 }
900 }
901
902 void ret(Variable *RetAddr, Variable *RetValue) {
903 if (Target->NeedSandboxing) {
904 Target->_bic(RetAddr, RetAddr, Target->indirectBranchBicMask());
905 }
906 Target->_ret(RetAddr, RetValue);
907 }
908
909 void str(Variable *Src, OperandARM32Mem *Mem, CondARM32::Cond Pred) {
910 if (Target->NeedSandboxing) {
911 assert(!Mem->isRegReg());
912 Variable *MemBase = Mem->getBase();
913 Target->_bic(MemBase, MemBase, Target->memOpBicMask(), Pred);
914 }
915 Target->_str(Src, Mem, Pred);
916 }
917
918 void strex(Variable *Dest, Variable *Src, OperandARM32Mem *Mem,
919 CondARM32::Cond Pred) {
920 if (Target->NeedSandboxing) {
921 assert(!Mem->isRegReg());
922 Variable *MemBase = Mem->getBase();
923 Target->_bic(MemBase, MemBase, Target->memOpBicMask(), Pred);
924 }
925 Target->_strex(Dest, Src, Mem, Pred);
926 }
927
928 void sub_sp(Operand *SubAmount) {
929 Variable *SP = Target->getPhysicalRegister(RegARM32::Reg_sp);
930 Target->_sub(SP, SP, SubAmount);
931 if (Target->NeedSandboxing) {
932 Target->_bic(SP, SP, Target->memOpBicMask());
933 }
934 }
935
936 ~AutoSandboxer() {
937 if (Target->NeedSandboxing) {
938 Target->_bundle_unlock();
939 }
940 }
941
942 private:
943 TargetARM32 *Target;
944 };
945
825 class PostLoweringLegalizer { 946 class PostLoweringLegalizer {
826 PostLoweringLegalizer() = delete; 947 PostLoweringLegalizer() = delete;
827 PostLoweringLegalizer(const PostLoweringLegalizer &) = delete; 948 PostLoweringLegalizer(const PostLoweringLegalizer &) = delete;
828 PostLoweringLegalizer &operator=(const PostLoweringLegalizer &) = delete; 949 PostLoweringLegalizer &operator=(const PostLoweringLegalizer &) = delete;
829 950
830 public: 951 public:
831 explicit PostLoweringLegalizer(TargetARM32 *Target) 952 explicit PostLoweringLegalizer(TargetARM32 *Target)
832 : Target(Target), StackOrFrameReg(Target->getPhysicalRegister( 953 : Target(Target), StackOrFrameReg(Target->getPhysicalRegister(
833 Target->getFrameOrStackReg())) {} 954 Target->getFrameOrStackReg())) {}
834 955
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 /// a new base register ip=Base+Offset is created, and the method returns a 992 /// a new base register ip=Base+Offset is created, and the method returns a
872 /// memory operand expressing [ip, #0]. 993 /// memory operand expressing [ip, #0].
873 OperandARM32Mem *createMemOperand(Type Ty, Variable *Base, int32_t Offset, 994 OperandARM32Mem *createMemOperand(Type Ty, Variable *Base, int32_t Offset,
874 bool AllowOffsets = true); 995 bool AllowOffsets = true);
875 TargetARM32 *const Target; 996 TargetARM32 *const Target;
876 Variable *const StackOrFrameReg; 997 Variable *const StackOrFrameReg;
877 Variable *TempBaseReg = nullptr; 998 Variable *TempBaseReg = nullptr;
878 int32_t TempBaseOffset = 0; 999 int32_t TempBaseOffset = 0;
879 }; 1000 };
880 1001
1002 const bool NeedSandboxing;
881 TargetARM32Features CPUFeatures; 1003 TargetARM32Features CPUFeatures;
882 bool UsesFramePointer = false; 1004 bool UsesFramePointer = false;
883 bool NeedsStackAlignment = false; 1005 bool NeedsStackAlignment = false;
884 bool MaybeLeafFunc = true; 1006 bool MaybeLeafFunc = true;
885 size_t SpillAreaSizeBytes = 0; 1007 size_t SpillAreaSizeBytes = 0;
886 size_t FixedAllocaSizeBytes = 0; 1008 size_t FixedAllocaSizeBytes = 0;
887 size_t FixedAllocaAlignBytes = 0; 1009 size_t FixedAllocaAlignBytes = 0;
888 bool PrologEmitsFixedAllocas = false; 1010 bool PrologEmitsFixedAllocas = false;
889 uint32_t MaxOutArgsSizeBytes = 0; 1011 uint32_t MaxOutArgsSizeBytes = 0;
890 // TODO(jpp): std::array instead of array. 1012 // TODO(jpp): std::array instead of array.
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 1198
1077 private: 1199 private:
1078 ~TargetHeaderARM32() = default; 1200 ~TargetHeaderARM32() = default;
1079 1201
1080 TargetARM32Features CPUFeatures; 1202 TargetARM32Features CPUFeatures;
1081 }; 1203 };
1082 1204
1083 } // end of namespace Ice 1205 } // end of namespace Ice
1084 1206
1085 #endif // SUBZERO_SRC_ICETARGETLOWERINGARM32_H 1207 #endif // SUBZERO_SRC_ICETARGETLOWERINGARM32_H
OLDNEW
« no previous file with comments | « pydir/targets.py ('k') | src/IceTargetLoweringARM32.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698