diff --git a/llvm/include/llvm/IR/Instruction.h b/llvm/include/llvm/IR/Instruction.h --- a/llvm/include/llvm/IR/Instruction.h +++ b/llvm/include/llvm/IR/Instruction.h @@ -54,6 +54,14 @@ // The 15 first bits of `Value::SubclassData` are available for subclasses of // `Instruction` to use. using OpaqueField = Bitfield::Element; // Next bit:15 + + // Template alias so that all Instruction storing alignment use the same + // definiton. + template + using BitfieldAlignmentElement = + typename Bitfield::Element; + private: // The last bit is used to store whether the instruction has metadata attached // or not. diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -60,7 +60,7 @@ class AllocaInst : public UnaryInstruction { Type *AllocatedType; - using AlignmentField = Bitfield::Element; // Next bit:5 + using AlignmentField = BitfieldAlignmentElement<0>; // Next bit:5 using UsedWithInAllocaField = Bitfield::Element; // Next bit:6 using SwiftErrorField = Bitfield::Element; // Next bit:7 @@ -113,7 +113,7 @@ /// Return the alignment of the memory that is being allocated by the /// instruction. Align getAlign() const { - return *decodeMaybeAlign(getSubclassData()); + return Align(1ULL << getSubclassData()); } // FIXME: Remove this one transition to Align is over. unsigned getAlignment() const { return getAlign().value(); } @@ -165,9 +165,9 @@ /// Value to store whether or not the load is volatile. class LoadInst : public UnaryInstruction { using VolatileField = Bitfield::Element; // Next bit:1 - using AlignmentField = Bitfield::Element; // Next bit:7 - using OrderingField = Bitfield::Element; // Next bit:10 + using AlignmentField = BitfieldAlignmentElement<1>; // Next bit:6 + using OrderingField = Bitfield::Element; // Next bit:9 void AssertOK(); @@ -210,7 +210,7 @@ /// Return the alignment of the access that is being performed. Align getAlign() const { - return *decodeMaybeAlign(getSubclassData()); + return Align(1ULL << (getSubclassData())); } void setAlignment(Align Alignment); @@ -290,9 +290,9 @@ /// An instruction for storing to memory. class StoreInst : public Instruction { using VolatileField = Bitfield::Element; // Next bit:1 - using AlignmentField = Bitfield::Element; // Next bit:7 - using OrderingField = Bitfield::Element; // Next bit:10 + using AlignmentField = BitfieldAlignmentElement<1>; // Next bit:6 + using OrderingField = Bitfield::Element; // Next bit:9 void AssertOK(); @@ -337,7 +337,7 @@ unsigned getAlignment() const { return getAlign().value(); } Align getAlign() const { - return *decodeMaybeAlign(getSubclassData()); + return Align(1ULL << (getSubclassData())); } void setAlignment(Align Alignment); diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -1300,7 +1300,7 @@ void AllocaInst::setAlignment(Align Align) { assert(Align <= MaximumAlignment && "Alignment is greater than MaximumAlignment!"); - setSubclassData(encode(Align)); + setSubclassData(Log2(Align)); } bool AllocaInst::isArrayAllocation() const { @@ -1396,7 +1396,7 @@ void LoadInst::setAlignment(Align Align) { assert(Align <= MaximumAlignment && "Alignment is greater than MaximumAlignment!"); - setSubclassData(encode(Align)); + setSubclassData(Log2(Align)); } //===----------------------------------------------------------------------===// @@ -1473,7 +1473,7 @@ void StoreInst::setAlignment(Align Alignment) { assert(Alignment <= MaximumAlignment && "Alignment is greater than MaximumAlignment!"); - setSubclassData(encode(Alignment)); + setSubclassData(Log2(Alignment)); } //===----------------------------------------------------------------------===//