diff options
author | Justin Lebar <jlebar@google.com> | 2016-07-14 17:07:44 +0000 |
---|---|---|
committer | Justin Lebar <jlebar@google.com> | 2016-07-14 17:07:44 +0000 |
commit | f66cee6be56c642bc55cab34b8feab4dc480f6d4 (patch) | |
tree | 80318daadce7399dd4316f4e19b3ea8d43729195 /include | |
parent | 5591e3d51d57d3a7dd2a50d5f5ddc540072586d0 (diff) |
[CodeGen] Refactor MachineMemOperand's Flags enum.
Summary:
- Give it a shorter name (because we're going to refer to it often from
SelectionDAG and friends).
- Split the flags and alignment into separate variables.
- Specialize FlagsEnumTraits for it, so we can do bitwise ops on it
without losing type information.
- Make some enum values constants in MachineMemOperand instead.
MOMaxBits should not be a valid Flag.
- Simplify some of the bitwise ops for dealing with Flags.
Reviewers: chandlerc
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D22281
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275438 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/CodeGen/MachineMemOperand.h | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/include/llvm/CodeGen/MachineMemOperand.h b/include/llvm/CodeGen/MachineMemOperand.h index 9e7b3b9b8cb..b2d76734fa4 100644 --- a/include/llvm/CodeGen/MachineMemOperand.h +++ b/include/llvm/CodeGen/MachineMemOperand.h @@ -16,6 +16,7 @@ #ifndef LLVM_CODEGEN_MACHINEMEMOPERAND_H #define LLVM_CODEGEN_MACHINEMEMOPERAND_H +#include "llvm/ADT/BitmaskEnum.h" #include "llvm/ADT/PointerUnion.h" #include "llvm/CodeGen/PseudoSourceValue.h" #include "llvm/IR/Metadata.h" @@ -87,15 +88,18 @@ struct MachinePointerInfo { /// that aren't explicit in the regular LLVM IR. /// class MachineMemOperand { - MachinePointerInfo PtrInfo; - uint64_t Size; - unsigned Flags; - AAMDNodes AAInfo; - const MDNode *Ranges; - public: + // This is the number of bits we need to represent flags. + static constexpr unsigned MOMaxBits = 8; + + // Target hints allow target passes to annotate memory operations. + static constexpr unsigned MOTargetStartBit = 5; + static constexpr unsigned MOTargetNumBits = 3; + /// Flags values. These may be or'd together. - enum MemOperandFlags { + enum Flags : uint16_t { + // No flags set. + MONone = 0, /// The memory access reads data. MOLoad = 1, /// The memory access writes data. @@ -106,16 +110,25 @@ public: MONonTemporal = 8, /// The memory access is invariant. MOInvariant = 16, - // Target hints allow target passes to annotate memory operations. - MOTargetStartBit = 5, - MOTargetNumBits = 3, - // This is the number of bits we need to represent flags. - MOMaxBits = 8 + + // Maximum MemOperandFlag value (inclusive). + MOMaxFlag = (1 << MOMaxBits) - 1, + + LLVM_MARK_AS_BITMASK_ENUM(MOMaxFlag) }; +private: + MachinePointerInfo PtrInfo; + uint64_t Size; + Flags FlagVals; + uint16_t BaseAlignLog2; // log_2(base_alignment) + 1 + AAMDNodes AAInfo; + const MDNode *Ranges; + +public: /// Construct a MachineMemOperand object with the specified PtrInfo, flags, /// size, and base alignment. - MachineMemOperand(MachinePointerInfo PtrInfo, unsigned flags, uint64_t s, + MachineMemOperand(MachinePointerInfo PtrInfo, Flags flags, uint64_t s, unsigned base_alignment, const AAMDNodes &AAInfo = AAMDNodes(), const MDNode *Ranges = nullptr); @@ -137,11 +150,11 @@ public: const void *getOpaqueValue() const { return PtrInfo.V.getOpaqueValue(); } - /// Return the raw flags of the source value, \see MemOperandFlags. - unsigned int getFlags() const { return Flags & ((1 << MOMaxBits) - 1); } + /// Return the raw flags of the source value, \see Flags. + Flags getFlags() const { return FlagVals; } /// Bitwise OR the current flags with the given flags. - void setFlags(unsigned f) { Flags |= (f & ((1 << MOMaxBits) - 1)); } + void setFlags(Flags f) { FlagVals |= f; } /// For normal values, this is a byte offset added to the base address. /// For PseudoSourceValue::FPRel values, this is the FrameIndex number. @@ -158,7 +171,7 @@ public: /// Return the minimum known alignment in bytes of the base address, without /// the offset. - uint64_t getBaseAlignment() const { return (1u << (Flags >> MOMaxBits)) >> 1; } + uint64_t getBaseAlignment() const { return (1u << BaseAlignLog2) >> 1; } /// Return the AA tags for the memory reference. AAMDNodes getAAInfo() const { return AAInfo; } @@ -166,11 +179,11 @@ public: /// Return the range tag for the memory reference. const MDNode *getRanges() const { return Ranges; } - bool isLoad() const { return Flags & MOLoad; } - bool isStore() const { return Flags & MOStore; } - bool isVolatile() const { return Flags & MOVolatile; } - bool isNonTemporal() const { return Flags & MONonTemporal; } - bool isInvariant() const { return Flags & MOInvariant; } + bool isLoad() const { return FlagVals & MOLoad; } + bool isStore() const { return FlagVals & MOStore; } + bool isVolatile() const { return FlagVals & MOVolatile; } + bool isNonTemporal() const { return FlagVals & MONonTemporal; } + bool isInvariant() const { return FlagVals & MOInvariant; } /// Returns true if this memory operation doesn't have any ordering /// constraints other than normal aliasing. Volatile and atomic memory |