// If the alignment was parsed as an attribute, move to the alignment
// field.
if (FnAttrs.hasAlignmentAttr()) {
- Fn->setAlignment(MaybeAlign(FnAttrs.getAlignment()));
+ Fn->setAlignment(FnAttrs.getAlignment());
FnAttrs.removeAttribute(Attribute::Alignment);
}
if (ParseToken(lltok::StringConstant, "expected partition string"))
return true;
} else if (Lex.getKind() == lltok::kw_align) {
- unsigned Alignment;
+ MaybeAlign Alignment;
if (ParseOptionalAlignment(Alignment)) return true;
- GV->setAlignment(MaybeAlign(Alignment));
+ GV->setAlignment(Alignment);
} else if (Lex.getKind() == lltok::MetadataVar) {
if (ParseGlobalObjectMetadataAttachment(*GV))
return true;
// As a hack, we allow function alignment to be initially parsed as an
// attribute on a function declaration/definition or added to an attribute
// group and later moved to the alignment field.
- unsigned Alignment;
+ MaybeAlign Alignment;
if (inAttrGrp) {
Lex.Lex();
- if (ParseToken(lltok::equal, "expected '=' here") ||
- ParseUInt32(Alignment))
+ uint32_t Value = 0;
+ if (ParseToken(lltok::equal, "expected '=' here") || ParseUInt32(Value))
return true;
+ Alignment = Align(Value);
} else {
if (ParseOptionalAlignment(Alignment))
return true;
continue;
}
case lltok::kw_align: {
- unsigned Alignment;
+ MaybeAlign Alignment;
if (ParseOptionalAlignment(Alignment))
return true;
B.addAlignmentAttr(Alignment);
continue;
}
case lltok::kw_align: {
- unsigned Alignment;
+ MaybeAlign Alignment;
if (ParseOptionalAlignment(Alignment))
return true;
B.addAlignmentAttr(Alignment);
/// ParseOptionalAlignment
/// ::= /* empty */
/// ::= 'align' 4
-bool LLParser::ParseOptionalAlignment(unsigned &Alignment) {
- Alignment = 0;
+bool LLParser::ParseOptionalAlignment(MaybeAlign &Alignment) {
+ Alignment = None;
if (!EatIfPresent(lltok::kw_align))
return false;
LocTy AlignLoc = Lex.getLoc();
- if (ParseUInt32(Alignment)) return true;
- if (!isPowerOf2_32(Alignment))
+ uint32_t Value = 0;
+ if (ParseUInt32(Value))
+ return true;
+ if (!isPowerOf2_32(Value))
return Error(AlignLoc, "alignment is not a power of two");
- if (Alignment > Value::MaximumAlignment)
+ if (Value > Value::MaximumAlignment)
return Error(AlignLoc, "huge alignments are not supported yet");
+ Alignment = Align(Value);
return false;
}
///
/// This returns with AteExtraComma set to true if it ate an excess comma at the
/// end.
-bool LLParser::ParseOptionalCommaAlign(unsigned &Alignment,
+bool LLParser::ParseOptionalCommaAlign(MaybeAlign &Alignment,
bool &AteExtraComma) {
AteExtraComma = false;
while (EatIfPresent(lltok::comma)) {
LocTy BuiltinLoc;
std::string Section;
std::string Partition;
- unsigned Alignment;
+ MaybeAlign Alignment;
std::string GC;
GlobalValue::UnnamedAddr UnnamedAddr = GlobalValue::UnnamedAddr::None;
unsigned AddrSpace = 0;
int LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS) {
Value *Size = nullptr;
LocTy SizeLoc, TyLoc, ASLoc;
- unsigned Alignment = 0;
+ MaybeAlign Alignment;
unsigned AddrSpace = 0;
Type *Ty = nullptr;
if (Size && !Size->getType()->isIntegerTy())
return Error(SizeLoc, "element count must have integer type");
- AllocaInst *AI = new AllocaInst(Ty, AddrSpace, Size, Alignment);
+ AllocaInst *AI =
+ new AllocaInst(Ty, AddrSpace, Size, Alignment ? Alignment->value() : 0);
AI->setUsedWithInAlloca(IsInAlloca);
AI->setSwiftError(IsSwiftError);
Inst = AI;
/// 'singlethread'? AtomicOrdering (',' 'align' i32)?
int LLParser::ParseLoad(Instruction *&Inst, PerFunctionState &PFS) {
Value *Val; LocTy Loc;
- unsigned Alignment = 0;
+ MaybeAlign Alignment;
bool AteExtraComma = false;
bool isAtomic = false;
AtomicOrdering Ordering = AtomicOrdering::NotAtomic;
return Error(ExplicitTypeLoc,
"explicit pointee type doesn't match operand's pointee type");
- Inst = new LoadInst(Ty, Val, "", isVolatile, Alignment, Ordering, SSID);
+ Inst = new LoadInst(Ty, Val, "", isVolatile,
+ Alignment ? Alignment->value() : 0, Ordering, SSID);
return AteExtraComma ? InstExtraComma : InstNormal;
}
/// 'singlethread'? AtomicOrdering (',' 'align' i32)?
int LLParser::ParseStore(Instruction *&Inst, PerFunctionState &PFS) {
Value *Val, *Ptr; LocTy Loc, PtrLoc;
- unsigned Alignment = 0;
+ MaybeAlign Alignment;
bool AteExtraComma = false;
bool isAtomic = false;
AtomicOrdering Ordering = AtomicOrdering::NotAtomic;
Ordering == AtomicOrdering::AcquireRelease)
return Error(Loc, "atomic store cannot use Acquire ordering");
- Inst = new StoreInst(Val, Ptr, isVolatile, Alignment, Ordering, SSID);
+ Inst = new StoreInst(Val, Ptr, isVolatile, Alignment ? Alignment->value() : 0,
+ Ordering, SSID);
return AteExtraComma ? InstExtraComma : InstNormal;
}
void ParseOptionalVisibility(unsigned &Res);
void ParseOptionalDLLStorageClass(unsigned &Res);
bool ParseOptionalCallingConv(unsigned &CC);
- bool ParseOptionalAlignment(unsigned &Alignment);
+ bool ParseOptionalAlignment(MaybeAlign &Alignment);
bool ParseOptionalDerefAttrBytes(lltok::Kind AttrKind, uint64_t &Bytes);
bool ParseScopeAndOrdering(bool isAtomic, SyncScope::ID &SSID,
AtomicOrdering &Ordering);
bool ParseScope(SyncScope::ID &SSID);
bool ParseOrdering(AtomicOrdering &Ordering);
bool ParseOptionalStackAlignment(unsigned &Alignment);
- bool ParseOptionalCommaAlign(unsigned &Alignment, bool &AteExtraComma);
+ bool ParseOptionalCommaAlign(MaybeAlign &Alignment, bool &AteExtraComma);
bool ParseOptionalCommaAddrSpace(unsigned &AddrSpace, LocTy &Loc,
bool &AteExtraComma);
bool ParseOptionalCommaInAlloca(bool &IsInAlloca);
Attr = Attribute::getWithByValType(C, B.getByValType());
break;
case Attribute::Alignment:
- Attr = Attribute::getWithAlignment(C, Align(B.getAlignment()));
+ assert(B.getAlignment() && "Alignment must be set");
+ Attr = Attribute::getWithAlignment(C, *B.getAlignment());
break;
case Attribute::StackAlignment:
- Attr = Attribute::getWithStackAlignment(C, Align(B.getStackAlignment()));
+ assert(B.getStackAlignment() && "StackAlignment must be set");
+ Attr = Attribute::getWithStackAlignment(C, *B.getStackAlignment());
break;
case Attribute::Dereferenceable:
Attr = Attribute::getWithDereferenceableBytes(
// FIXME it is not obvious how this should work for alignment. For now, say
// we can't change a known alignment.
const MaybeAlign OldAlign = getAttributes(Index).getAlignment();
- unsigned NewAlign = B.getAlignment();
+ const MaybeAlign NewAlign = B.getAlignment();
assert((!OldAlign || !NewAlign || OldAlign == NewAlign) &&
"Attempt to change alignment!");
#endif
Attrs[Kind] = true;
if (Kind == Attribute::Alignment)
- Alignment = MaybeAlign(Attr.getAlignment());
+ Alignment = Attr.getAlignment();
else if (Kind == Attribute::StackAlignment)
- StackAlignment = MaybeAlign(Attr.getStackAlignment());
+ StackAlignment = Attr.getStackAlignment();
else if (Kind == Attribute::ByVal)
ByValType = Attr.getValueAsType();
else if (Kind == Attribute::Dereferenceable)