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

Side by Side Diff: src/IceTargetLoweringX86Base.h

Issue 1676123002: Subzero: Use a proper RegNumT type instead of int32_t/SizeT. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Revert some method name changes Created 4 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
OLDNEW
1 //===- subzero/src/IceTargetLoweringX86Base.h - x86 lowering ----*- C++ -*-===// 1 //===- subzero/src/IceTargetLoweringX86Base.h - x86 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 bool needSandboxing() const { return NeedSandboxing; } 87 bool needSandboxing() const { return NeedSandboxing; }
88 88
89 void translateOm1() override; 89 void translateOm1() override;
90 void translateO2() override; 90 void translateO2() override;
91 void doLoadOpt(); 91 void doLoadOpt();
92 bool doBranchOpt(Inst *I, const CfgNode *NextNode) override; 92 bool doBranchOpt(Inst *I, const CfgNode *NextNode) override;
93 93
94 SizeT getNumRegisters() const override { 94 SizeT getNumRegisters() const override {
95 return Traits::RegisterSet::Reg_NUM; 95 return Traits::RegisterSet::Reg_NUM;
96 } 96 }
97 Variable *getPhysicalRegister(SizeT RegNum, Type Ty = IceType_void) override; 97 Variable *getPhysicalRegister(RegNumT RegNum,
98 IceString getRegName(SizeT RegNum, Type Ty) const override; 98 Type Ty = IceType_void) override;
99 IceString getRegName(RegNumT RegNum, Type Ty) const override;
99 static IceString getRegClassName(RegClass C) { 100 static IceString getRegClassName(RegClass C) {
100 auto ClassNum = static_cast<RegClassX86>(C); 101 auto ClassNum = static_cast<RegClassX86>(C);
101 assert(ClassNum < RCX86_NUM); 102 assert(ClassNum < RCX86_NUM);
102 switch (ClassNum) { 103 switch (ClassNum) {
103 default: 104 default:
104 assert(C < RC_Target); 105 assert(C < RC_Target);
105 return regClassString(C); 106 return regClassString(C);
106 case RCX86_Is64To8: 107 case RCX86_Is64To8:
107 return "i64to8"; // 64-bit GPR truncable to i8 108 return "i64to8"; // 64-bit GPR truncable to i8
108 case RCX86_Is32To8: 109 case RCX86_Is32To8:
(...skipping 15 matching lines...) Expand all
124 return TypeToRegisterSet[RC]; 125 return TypeToRegisterSet[RC];
125 } 126 }
126 127
127 const llvm::SmallBitVector & 128 const llvm::SmallBitVector &
128 getAllRegistersForVariable(const Variable *Var) const override { 129 getAllRegistersForVariable(const Variable *Var) const override {
129 RegClass RC = Var->getRegClass(); 130 RegClass RC = Var->getRegClass();
130 assert(static_cast<RegClassX86>(RC) < RCX86_NUM); 131 assert(static_cast<RegClassX86>(RC) < RCX86_NUM);
131 return TypeToRegisterSetUnfiltered[RC]; 132 return TypeToRegisterSetUnfiltered[RC];
132 } 133 }
133 134
134 const llvm::SmallBitVector &getAliasesForRegister(SizeT Reg) const override { 135 const llvm::SmallBitVector &
135 assert(Reg < Traits::RegisterSet::Reg_NUM); 136 getAliasesForRegister(RegNumT Reg) const override {
137 Reg.assertIsValid();
136 return RegisterAliases[Reg]; 138 return RegisterAliases[Reg];
137 } 139 }
138 140
139 bool hasFramePointer() const override { return IsEbpBasedFrame; } 141 bool hasFramePointer() const override { return IsEbpBasedFrame; }
140 void setHasFramePointer() override { IsEbpBasedFrame = true; } 142 void setHasFramePointer() override { IsEbpBasedFrame = true; }
141 SizeT getStackReg() const override { return Traits::StackPtr; } 143 RegNumT getStackReg() const override { return Traits::StackPtr; }
142 SizeT getFrameReg() const override { return Traits::FramePtr; } 144 RegNumT getFrameReg() const override { return Traits::FramePtr; }
143 SizeT getFrameOrStackReg() const override { 145 RegNumT getFrameOrStackReg() const override {
144 return IsEbpBasedFrame ? getFrameReg() : getStackReg(); 146 return IsEbpBasedFrame ? getFrameReg() : getStackReg();
145 } 147 }
146 size_t typeWidthInBytesOnStack(Type Ty) const override { 148 size_t typeWidthInBytesOnStack(Type Ty) const override {
147 // Round up to the next multiple of WordType bytes. 149 // Round up to the next multiple of WordType bytes.
148 const uint32_t WordSizeInBytes = typeWidthInBytes(Traits::WordType); 150 const uint32_t WordSizeInBytes = typeWidthInBytes(Traits::WordType);
149 return Utils::applyAlignment(typeWidthInBytes(Ty), WordSizeInBytes); 151 return Utils::applyAlignment(typeWidthInBytes(Ty), WordSizeInBytes);
150 } 152 }
151 uint32_t getStackAlignment() const override { 153 uint32_t getStackAlignment() const override {
152 return Traits::X86_STACK_ALIGNMENT_BYTES; 154 return Traits::X86_STACK_ALIGNMENT_BYTES;
153 } 155 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 213 }
212 214
213 void addProlog(CfgNode *Node) override; 215 void addProlog(CfgNode *Node) override;
214 void finishArgumentLowering(Variable *Arg, Variable *FramePtr, 216 void finishArgumentLowering(Variable *Arg, Variable *FramePtr,
215 size_t BasicFrameOffset, size_t StackAdjBytes, 217 size_t BasicFrameOffset, size_t StackAdjBytes,
216 size_t &InArgsSizeBytes); 218 size_t &InArgsSizeBytes);
217 void addEpilog(CfgNode *Node) override; 219 void addEpilog(CfgNode *Node) override;
218 X86Address stackVarToAsmOperand(const Variable *Var) const; 220 X86Address stackVarToAsmOperand(const Variable *Var) const;
219 221
220 InstructionSetEnum getInstructionSet() const { return InstructionSet; } 222 InstructionSetEnum getInstructionSet() const { return InstructionSet; }
221 Operand *legalizeUndef(Operand *From, int32_t RegNum = Variable::NoRegister); 223 Operand *legalizeUndef(Operand *From, RegNumT RegNum = RegNumT::NoRegister);
222 224
223 protected: 225 protected:
224 const bool NeedSandboxing; 226 const bool NeedSandboxing;
225 227
226 explicit TargetX86Base(Cfg *Func); 228 explicit TargetX86Base(Cfg *Func);
227 229
228 void postLower() override; 230 void postLower() override;
229 231
230 /// Initializes the RebasePtr member variable -- if so required by 232 /// Initializes the RebasePtr member variable -- if so required by
231 /// SandboxingType for the concrete Target. 233 /// SandboxingType for the concrete Target.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 Legal_Reg = 1 << 0, // physical register, not stack location 385 Legal_Reg = 1 << 0, // physical register, not stack location
384 Legal_Imm = 1 << 1, 386 Legal_Imm = 1 << 1,
385 Legal_Mem = 1 << 2, // includes [eax+4*ecx] as well as [esp+12] 387 Legal_Mem = 1 << 2, // includes [eax+4*ecx] as well as [esp+12]
386 Legal_Rematerializable = 1 << 3, 388 Legal_Rematerializable = 1 << 3,
387 Legal_AddrAbs = 1 << 4, // ConstantRelocatable doesn't have to add RebasePtr 389 Legal_AddrAbs = 1 << 4, // ConstantRelocatable doesn't have to add RebasePtr
388 Legal_Default = ~(Legal_Rematerializable | Legal_AddrAbs) 390 Legal_Default = ~(Legal_Rematerializable | Legal_AddrAbs)
389 // TODO(stichnot): Figure out whether this default works for x86-64. 391 // TODO(stichnot): Figure out whether this default works for x86-64.
390 }; 392 };
391 using LegalMask = uint32_t; 393 using LegalMask = uint32_t;
392 Operand *legalize(Operand *From, LegalMask Allowed = Legal_Default, 394 Operand *legalize(Operand *From, LegalMask Allowed = Legal_Default,
393 int32_t RegNum = Variable::NoRegister); 395 RegNumT RegNum = RegNumT::NoRegister);
394 Variable *legalizeToReg(Operand *From, int32_t RegNum = Variable::NoRegister); 396 Variable *legalizeToReg(Operand *From, RegNumT RegNum = RegNumT::NoRegister);
395 /// Legalize the first source operand for use in the cmp instruction. 397 /// Legalize the first source operand for use in the cmp instruction.
396 Operand *legalizeSrc0ForCmp(Operand *Src0, Operand *Src1); 398 Operand *legalizeSrc0ForCmp(Operand *Src0, Operand *Src1);
397 /// Turn a pointer operand into a memory operand that can be used by a real 399 /// Turn a pointer operand into a memory operand that can be used by a real
398 /// load/store operation. Legalizes the operand as well. This is a nop if the 400 /// load/store operation. Legalizes the operand as well. This is a nop if the
399 /// operand is already a legal memory operand. 401 /// operand is already a legal memory operand.
400 X86OperandMem *formMemoryOperand(Operand *Ptr, Type Ty, 402 X86OperandMem *formMemoryOperand(Operand *Ptr, Type Ty,
401 bool DoLegalize = true); 403 bool DoLegalize = true);
402 404
403 Variable *makeReg(Type Ty, int32_t RegNum = Variable::NoRegister); 405 Variable *makeReg(Type Ty, RegNumT RegNum = RegNumT::NoRegister);
404 static Type stackSlotType(); 406 static Type stackSlotType();
405 407
406 static constexpr uint32_t NoSizeLimit = 0; 408 static constexpr uint32_t NoSizeLimit = 0;
407 static const Type TypeForSize[]; 409 static const Type TypeForSize[];
408 /// Returns the largest type which is equal to or larger than Size bytes. The 410 /// Returns the largest type which is equal to or larger than Size bytes. The
409 /// type is suitable for copying memory i.e. a load and store will be a single 411 /// type is suitable for copying memory i.e. a load and store will be a single
410 /// instruction (for example x86 will get f64 not i64). 412 /// instruction (for example x86 will get f64 not i64).
411 static Type largestTypeInSize(uint32_t Size, uint32_t MaxSize = NoSizeLimit); 413 static Type largestTypeInSize(uint32_t Size, uint32_t MaxSize = NoSizeLimit);
412 /// Returns the smallest type which is equal to or larger than Size bytes. If 414 /// Returns the smallest type which is equal to or larger than Size bytes. If
413 /// one doesn't exist then the largest type smaller than Size bytes is 415 /// one doesn't exist then the largest type smaller than Size bytes is
414 /// returned. The type is suitable for memory copies as described at 416 /// returned. The type is suitable for memory copies as described at
415 /// largestTypeInSize. 417 /// largestTypeInSize.
416 static Type firstTypeThatFitsSize(uint32_t Size, 418 static Type firstTypeThatFitsSize(uint32_t Size,
417 uint32_t MaxSize = NoSizeLimit); 419 uint32_t MaxSize = NoSizeLimit);
418 420
419 Variable *copyToReg8(Operand *Src, int32_t RegNum = Variable::NoRegister); 421 Variable *copyToReg8(Operand *Src, RegNumT RegNum = RegNumT::NoRegister);
420 Variable *copyToReg(Operand *Src, int32_t RegNum = Variable::NoRegister); 422 Variable *copyToReg(Operand *Src, RegNumT RegNum = RegNumT::NoRegister);
421 423
422 /// Returns a register containing all zeros, without affecting the FLAGS 424 /// Returns a register containing all zeros, without affecting the FLAGS
423 /// register, using the best instruction for the type. 425 /// register, using the best instruction for the type.
424 Variable *makeZeroedRegister(Type Ty, int32_t RegNum = Variable::NoRegister); 426 Variable *makeZeroedRegister(Type Ty, RegNumT RegNum = RegNumT::NoRegister);
425 427
426 /// \name Returns a vector in a register with the given constant entries. 428 /// \name Returns a vector in a register with the given constant entries.
427 /// @{ 429 /// @{
428 Variable *makeVectorOfZeros(Type Ty, int32_t RegNum = Variable::NoRegister); 430 Variable *makeVectorOfZeros(Type Ty, RegNumT RegNum = RegNumT::NoRegister);
429 Variable *makeVectorOfOnes(Type Ty, int32_t RegNum = Variable::NoRegister); 431 Variable *makeVectorOfOnes(Type Ty, RegNumT RegNum = RegNumT::NoRegister);
430 Variable *makeVectorOfMinusOnes(Type Ty, 432 Variable *makeVectorOfMinusOnes(Type Ty,
431 int32_t RegNum = Variable::NoRegister); 433 RegNumT RegNum = RegNumT::NoRegister);
432 Variable *makeVectorOfHighOrderBits(Type Ty, 434 Variable *makeVectorOfHighOrderBits(Type Ty,
433 int32_t RegNum = Variable::NoRegister); 435 RegNumT RegNum = RegNumT::NoRegister);
434 Variable *makeVectorOfFabsMask(Type Ty, 436 Variable *makeVectorOfFabsMask(Type Ty, RegNumT RegNum = RegNumT::NoRegister);
435 int32_t RegNum = Variable::NoRegister);
436 /// @} 437 /// @}
437 438
438 /// Return a memory operand corresponding to a stack allocated Variable. 439 /// Return a memory operand corresponding to a stack allocated Variable.
439 X86OperandMem *getMemoryOperandForStackSlot(Type Ty, Variable *Slot, 440 X86OperandMem *getMemoryOperandForStackSlot(Type Ty, Variable *Slot,
440 uint32_t Offset = 0); 441 uint32_t Offset = 0);
441 442
442 void 443 void
443 makeRandomRegisterPermutation(llvm::SmallVectorImpl<int32_t> &Permutation, 444 makeRandomRegisterPermutation(llvm::SmallVectorImpl<RegNumT> &Permutation,
444 const llvm::SmallBitVector &ExcludeRegisters, 445 const llvm::SmallBitVector &ExcludeRegisters,
445 uint64_t Salt) const override; 446 uint64_t Salt) const override;
446 447
447 /// AutoMemorySandboxer emits a bundle-lock/bundle-unlock pair if the 448 /// AutoMemorySandboxer emits a bundle-lock/bundle-unlock pair if the
448 /// instruction's operand is a memory reference. This is only needed for 449 /// instruction's operand is a memory reference. This is only needed for
449 /// x86-64 NaCl sandbox. 450 /// x86-64 NaCl sandbox.
450 template <InstBundleLock::Option BundleLockOpt = InstBundleLock::Opt_None> 451 template <InstBundleLock::Option BundleLockOpt = InstBundleLock::Opt_None>
451 class AutoMemorySandboxer { 452 class AutoMemorySandboxer {
452 AutoMemorySandboxer() = delete; 453 AutoMemorySandboxer() = delete;
453 AutoMemorySandboxer(const AutoMemorySandboxer &) = delete; 454 AutoMemorySandboxer(const AutoMemorySandboxer &) = delete;
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 /// Moves can be used to redefine registers, creating "partial kills" for 672 /// Moves can be used to redefine registers, creating "partial kills" for
672 /// liveness. Mark where moves are used in this way. 673 /// liveness. Mark where moves are used in this way.
673 void _redefined(Inst *MovInst, bool IsRedefinition = true) { 674 void _redefined(Inst *MovInst, bool IsRedefinition = true) {
674 if (IsRedefinition) 675 if (IsRedefinition)
675 MovInst->setDestRedefined(); 676 MovInst->setDestRedefined();
676 } 677 }
677 /// If Dest=nullptr is passed in, then a new variable is created, marked as 678 /// If Dest=nullptr is passed in, then a new variable is created, marked as
678 /// infinite register allocation weight, and returned through the in/out Dest 679 /// infinite register allocation weight, and returned through the in/out Dest
679 /// argument. 680 /// argument.
680 typename Traits::Insts::Mov *_mov(Variable *&Dest, Operand *Src0, 681 typename Traits::Insts::Mov *_mov(Variable *&Dest, Operand *Src0,
681 int32_t RegNum = Variable::NoRegister) { 682 RegNumT RegNum = RegNumT::NoRegister) {
682 if (Dest == nullptr) 683 if (Dest == nullptr)
683 Dest = makeReg(Src0->getType(), RegNum); 684 Dest = makeReg(Src0->getType(), RegNum);
684 AutoMemorySandboxer<> _(this, &Dest, &Src0); 685 AutoMemorySandboxer<> _(this, &Dest, &Src0);
685 return Context.insert<typename Traits::Insts::Mov>(Dest, Src0); 686 return Context.insert<typename Traits::Insts::Mov>(Dest, Src0);
686 } 687 }
687 void _mov_sp(Operand *NewValue) { 688 void _mov_sp(Operand *NewValue) {
688 dispatchToConcrete(&Traits::ConcreteTarget::_mov_sp, std::move(NewValue)); 689 dispatchToConcrete(&Traits::ConcreteTarget::_mov_sp, std::move(NewValue));
689 } 690 }
690 typename Traits::Insts::Movp *_movp(Variable *Dest, Operand *Src0) { 691 typename Traits::Insts::Movp *_movp(Variable *Dest, Operand *Src0) {
691 AutoMemorySandboxer<> _(this, &Dest, &Src0); 692 AutoMemorySandboxer<> _(this, &Dest, &Src0);
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 static std::array<llvm::SmallBitVector, Traits::RegisterSet::Reg_NUM> 996 static std::array<llvm::SmallBitVector, Traits::RegisterSet::Reg_NUM>
996 RegisterAliases; 997 RegisterAliases;
997 llvm::SmallBitVector RegsUsed; 998 llvm::SmallBitVector RegsUsed;
998 std::array<VarList, IceType_NUM> PhysicalRegisters; 999 std::array<VarList, IceType_NUM> PhysicalRegisters;
999 // RebasePtr is a Variable that holds the Rebasing pointer (if any) for the 1000 // RebasePtr is a Variable that holds the Rebasing pointer (if any) for the
1000 // current sandboxing type. 1001 // current sandboxing type.
1001 Variable *RebasePtr = nullptr; 1002 Variable *RebasePtr = nullptr;
1002 1003
1003 /// Randomize a given immediate operand 1004 /// Randomize a given immediate operand
1004 Operand *randomizeOrPoolImmediate(Constant *Immediate, 1005 Operand *randomizeOrPoolImmediate(Constant *Immediate,
1005 int32_t RegNum = Variable::NoRegister); 1006 RegNumT RegNum = RegNumT::NoRegister);
1006 X86OperandMem * 1007 X86OperandMem *randomizeOrPoolImmediate(X86OperandMem *MemOperand,
1007 randomizeOrPoolImmediate(X86OperandMem *MemOperand, 1008 RegNumT RegNum = RegNumT::NoRegister);
1008 int32_t RegNum = Variable::NoRegister);
1009 bool RandomizationPoolingPaused = false; 1009 bool RandomizationPoolingPaused = false;
1010 1010
1011 private: 1011 private:
1012 /// dispatchToConcrete is the template voodoo that allows TargetX86Base to 1012 /// dispatchToConcrete is the template voodoo that allows TargetX86Base to
1013 /// invoke methods in Machine (which inherits from TargetX86Base) without 1013 /// invoke methods in Machine (which inherits from TargetX86Base) without
1014 /// having to rely on virtual method calls. There are two overloads, one for 1014 /// having to rely on virtual method calls. There are two overloads, one for
1015 /// non-void types, and one for void types. We need this becase, for non-void 1015 /// non-void types, and one for void types. We need this becase, for non-void
1016 /// types, we need to return the method result, where as for void, we don't. 1016 /// types, we need to return the method result, where as for void, we don't.
1017 /// While it is true that the code compiles without the void "version", there 1017 /// While it is true that the code compiles without the void "version", there
1018 /// used to be a time when compilers would reject such code. 1018 /// used to be a time when compilers would reject such code.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 1128
1129 explicit TargetHeaderX86(GlobalContext *Ctx) : TargetHeaderLowering(Ctx) {} 1129 explicit TargetHeaderX86(GlobalContext *Ctx) : TargetHeaderLowering(Ctx) {}
1130 }; 1130 };
1131 1131
1132 } // end of namespace X86NAMESPACE 1132 } // end of namespace X86NAMESPACE
1133 } // end of namespace Ice 1133 } // end of namespace Ice
1134 1134
1135 #include "IceTargetLoweringX86BaseImpl.h" 1135 #include "IceTargetLoweringX86BaseImpl.h"
1136 1136
1137 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASE_H 1137 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASE_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698