/// Return the alignment of the memory that is being allocated by the
/// instruction.
unsigned getAlignment() const {
- return (1u << (getSubclassDataFromInstruction() & 31)) >> 1;
+ if (const auto MA = decodeMaybeAlign(getSubclassDataFromInstruction() & 31))
+ return MA->value();
+ return 0;
}
+ // FIXME: Remove once migration to llvm::Align is over.
void setAlignment(unsigned Align);
+ void setAlignment(llvm::MaybeAlign Align);
/// Return true if this alloca is in the entry block of the function and is a
/// constant size. If so, the code generator will fold it into the
/// Return the alignment of the access that is being performed.
unsigned getAlignment() const {
- return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
+ if (const auto MA =
+ decodeMaybeAlign((getSubclassDataFromInstruction() >> 1) & 31))
+ return MA->value();
+ return 0;
}
+ // FIXME: Remove once migration to llvm::Align is over.
void setAlignment(unsigned Align);
+ void setAlignment(llvm::MaybeAlign Align);
/// Returns the ordering constraint of this load instruction.
AtomicOrdering getOrdering() const {
/// Return the alignment of the access that is being performed
unsigned getAlignment() const {
- return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
+ if (const auto MA =
+ decodeMaybeAlign((getSubclassDataFromInstruction() >> 1) & 31))
+ return MA->value();
+ return 0;
}
+ // FIXME: Remove once migration to llvm::Align is over.
void setAlignment(unsigned Align);
+ void setAlignment(llvm::MaybeAlign Align);
/// Returns the ordering constraint of this store instruction.
AtomicOrdering getOrdering() const {
}
void AllocaInst::setAlignment(unsigned Align) {
- assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
- assert(Align <= MaximumAlignment &&
+ setAlignment(llvm::MaybeAlign(Align));
+}
+
+void AllocaInst::setAlignment(llvm::MaybeAlign Align) {
+ assert((!Align || *Align <= MaximumAlignment) &&
"Alignment is greater than MaximumAlignment!");
setInstructionSubclassData((getSubclassDataFromInstruction() & ~31) |
- (Log2_32(Align) + 1));
- assert(getAlignment() == Align && "Alignment representation error!");
+ encode(Align));
+ if (Align)
+ assert(getAlignment() == Align->value() &&
+ "Alignment representation error!");
+ else
+ assert(getAlignment() == 0 && "Alignment representation error!");
}
bool AllocaInst::isArrayAllocation() const {
}
void LoadInst::setAlignment(unsigned Align) {
- assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
- assert(Align <= MaximumAlignment &&
+ setAlignment(llvm::MaybeAlign(Align));
+}
+
+void LoadInst::setAlignment(llvm::MaybeAlign Align) {
+ assert((!Align || *Align <= MaximumAlignment) &&
"Alignment is greater than MaximumAlignment!");
setInstructionSubclassData((getSubclassDataFromInstruction() & ~(31 << 1)) |
- ((Log2_32(Align)+1)<<1));
- assert(getAlignment() == Align && "Alignment representation error!");
+ (encode(Align) << 1));
+ if (Align)
+ assert(getAlignment() == Align->value() &&
+ "Alignment representation error!");
+ else
+ assert(getAlignment() == 0 && "Alignment representation error!");
}
//===----------------------------------------------------------------------===//
}
void StoreInst::setAlignment(unsigned Align) {
- assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!");
- assert(Align <= MaximumAlignment &&
+ setAlignment(llvm::MaybeAlign(Align));
+}
+
+void StoreInst::setAlignment(llvm::MaybeAlign Align) {
+ assert((!Align || *Align <= MaximumAlignment) &&
"Alignment is greater than MaximumAlignment!");
setInstructionSubclassData((getSubclassDataFromInstruction() & ~(31 << 1)) |
- ((Log2_32(Align)+1) << 1));
- assert(getAlignment() == Align && "Alignment representation error!");
+ (encode(Align) << 1));
+ if (Align)
+ assert(getAlignment() == Align->value() &&
+ "Alignment representation error!");
+ else
+ assert(getAlignment() == 0 && "Alignment representation error!");
}
//===----------------------------------------------------------------------===//