@@ -140,7 +140,7 @@ bool LLParser::ValidateEndOfModule() {
140
140
// If the alignment was parsed as an attribute, move to the alignment
141
141
// field.
142
142
if (FnAttrs.hasAlignmentAttr ()) {
143
- Fn->setAlignment (MaybeAlign ( FnAttrs.getAlignment () ));
143
+ Fn->setAlignment (FnAttrs.getAlignment ());
144
144
FnAttrs.removeAttribute (Attribute::Alignment);
145
145
}
146
146
@@ -1122,9 +1122,9 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
1122
1122
if (ParseToken (lltok::StringConstant, " expected partition string" ))
1123
1123
return true ;
1124
1124
} else if (Lex.getKind () == lltok::kw_align) {
1125
- unsigned Alignment;
1125
+ MaybeAlign Alignment;
1126
1126
if (ParseOptionalAlignment (Alignment)) return true ;
1127
- GV->setAlignment (MaybeAlign ( Alignment) );
1127
+ GV->setAlignment (Alignment);
1128
1128
} else if (Lex.getKind () == lltok::MetadataVar) {
1129
1129
if (ParseGlobalObjectMetadataAttachment (*GV))
1130
1130
return true ;
@@ -1229,12 +1229,13 @@ bool LLParser::ParseFnAttributeValuePairs(AttrBuilder &B,
1229
1229
// As a hack, we allow function alignment to be initially parsed as an
1230
1230
// attribute on a function declaration/definition or added to an attribute
1231
1231
// group and later moved to the alignment field.
1232
- unsigned Alignment;
1232
+ MaybeAlign Alignment;
1233
1233
if (inAttrGrp) {
1234
1234
Lex.Lex ();
1235
- if ( ParseToken (lltok::equal, " expected '=' here " ) ||
1236
- ParseUInt32 (Alignment ))
1235
+ uint32_t Value = 0 ;
1236
+ if ( ParseToken (lltok::equal, " expected '=' here " ) || ParseUInt32 (Value ))
1237
1237
return true ;
1238
+ Alignment = Align (Value);
1238
1239
} else {
1239
1240
if (ParseOptionalAlignment (Alignment))
1240
1241
return true ;
@@ -1603,7 +1604,7 @@ bool LLParser::ParseOptionalParamAttrs(AttrBuilder &B) {
1603
1604
continue ;
1604
1605
}
1605
1606
case lltok::kw_align: {
1606
- unsigned Alignment;
1607
+ MaybeAlign Alignment;
1607
1608
if (ParseOptionalAlignment (Alignment))
1608
1609
return true ;
1609
1610
B.addAlignmentAttr (Alignment);
@@ -1720,7 +1721,7 @@ bool LLParser::ParseOptionalReturnAttrs(AttrBuilder &B) {
1720
1721
continue ;
1721
1722
}
1722
1723
case lltok::kw_align: {
1723
- unsigned Alignment;
1724
+ MaybeAlign Alignment;
1724
1725
if (ParseOptionalAlignment (Alignment))
1725
1726
return true ;
1726
1727
B.addAlignmentAttr (Alignment);
@@ -2069,16 +2070,19 @@ bool LLParser::ParseOptionalFunctionMetadata(Function &F) {
2069
2070
// / ParseOptionalAlignment
2070
2071
// / ::= /* empty */
2071
2072
// / ::= 'align' 4
2072
- bool LLParser::ParseOptionalAlignment (unsigned &Alignment) {
2073
- Alignment = 0 ;
2073
+ bool LLParser::ParseOptionalAlignment (MaybeAlign &Alignment) {
2074
+ Alignment = None ;
2074
2075
if (!EatIfPresent (lltok::kw_align))
2075
2076
return false ;
2076
2077
LocTy AlignLoc = Lex.getLoc ();
2077
- if (ParseUInt32 (Alignment)) return true ;
2078
- if (!isPowerOf2_32 (Alignment))
2078
+ uint32_t Value = 0 ;
2079
+ if (ParseUInt32 (Value))
2080
+ return true ;
2081
+ if (!isPowerOf2_32 (Value))
2079
2082
return Error (AlignLoc, " alignment is not a power of two" );
2080
- if (Alignment > Value::MaximumAlignment)
2083
+ if (Value > Value::MaximumAlignment)
2081
2084
return Error (AlignLoc, " huge alignments are not supported yet" );
2085
+ Alignment = Align (Value);
2082
2086
return false ;
2083
2087
}
2084
2088
@@ -2115,7 +2119,7 @@ bool LLParser::ParseOptionalDerefAttrBytes(lltok::Kind AttrKind,
2115
2119
// /
2116
2120
// / This returns with AteExtraComma set to true if it ate an excess comma at the
2117
2121
// / end.
2118
- bool LLParser::ParseOptionalCommaAlign (unsigned &Alignment,
2122
+ bool LLParser::ParseOptionalCommaAlign (MaybeAlign &Alignment,
2119
2123
bool &AteExtraComma) {
2120
2124
AteExtraComma = false ;
2121
2125
while (EatIfPresent (lltok::comma)) {
@@ -5370,7 +5374,7 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
5370
5374
LocTy BuiltinLoc;
5371
5375
std::string Section;
5372
5376
std::string Partition;
5373
- unsigned Alignment;
5377
+ MaybeAlign Alignment;
5374
5378
std::string GC;
5375
5379
GlobalValue::UnnamedAddr UnnamedAddr = GlobalValue::UnnamedAddr::None;
5376
5380
unsigned AddrSpace = 0 ;
@@ -6865,7 +6869,7 @@ bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS,
6865
6869
int LLParser::ParseAlloc (Instruction *&Inst, PerFunctionState &PFS) {
6866
6870
Value *Size = nullptr ;
6867
6871
LocTy SizeLoc, TyLoc, ASLoc;
6868
- unsigned Alignment = 0 ;
6872
+ MaybeAlign Alignment;
6869
6873
unsigned AddrSpace = 0 ;
6870
6874
Type *Ty = nullptr ;
6871
6875
@@ -6913,7 +6917,8 @@ int LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS) {
6913
6917
if (Size && !Size->getType ()->isIntegerTy ())
6914
6918
return Error (SizeLoc, " element count must have integer type" );
6915
6919
6916
- AllocaInst *AI = new AllocaInst (Ty, AddrSpace, Size, Alignment);
6920
+ AllocaInst *AI =
6921
+ new AllocaInst (Ty, AddrSpace, Size, Alignment ? Alignment->value () : 0 );
6917
6922
AI->setUsedWithInAlloca (IsInAlloca);
6918
6923
AI->setSwiftError (IsSwiftError);
6919
6924
Inst = AI;
@@ -6926,7 +6931,7 @@ int LLParser::ParseAlloc(Instruction *&Inst, PerFunctionState &PFS) {
6926
6931
// / 'singlethread'? AtomicOrdering (',' 'align' i32)?
6927
6932
int LLParser::ParseLoad (Instruction *&Inst, PerFunctionState &PFS) {
6928
6933
Value *Val; LocTy Loc;
6929
- unsigned Alignment = 0 ;
6934
+ MaybeAlign Alignment;
6930
6935
bool AteExtraComma = false ;
6931
6936
bool isAtomic = false ;
6932
6937
AtomicOrdering Ordering = AtomicOrdering::NotAtomic;
@@ -6964,7 +6969,8 @@ int LLParser::ParseLoad(Instruction *&Inst, PerFunctionState &PFS) {
6964
6969
return Error (ExplicitTypeLoc,
6965
6970
" explicit pointee type doesn't match operand's pointee type" );
6966
6971
6967
- Inst = new LoadInst (Ty, Val, " " , isVolatile, Alignment, Ordering, SSID);
6972
+ Inst = new LoadInst (Ty, Val, " " , isVolatile,
6973
+ Alignment ? Alignment->value () : 0 , Ordering, SSID);
6968
6974
return AteExtraComma ? InstExtraComma : InstNormal;
6969
6975
}
6970
6976
@@ -6975,7 +6981,7 @@ int LLParser::ParseLoad(Instruction *&Inst, PerFunctionState &PFS) {
6975
6981
// / 'singlethread'? AtomicOrdering (',' 'align' i32)?
6976
6982
int LLParser::ParseStore (Instruction *&Inst, PerFunctionState &PFS) {
6977
6983
Value *Val, *Ptr; LocTy Loc, PtrLoc;
6978
- unsigned Alignment = 0 ;
6984
+ MaybeAlign Alignment;
6979
6985
bool AteExtraComma = false ;
6980
6986
bool isAtomic = false ;
6981
6987
AtomicOrdering Ordering = AtomicOrdering::NotAtomic;
@@ -7011,7 +7017,8 @@ int LLParser::ParseStore(Instruction *&Inst, PerFunctionState &PFS) {
7011
7017
Ordering == AtomicOrdering::AcquireRelease)
7012
7018
return Error (Loc, " atomic store cannot use Acquire ordering" );
7013
7019
7014
- Inst = new StoreInst (Val, Ptr, isVolatile, Alignment, Ordering, SSID);
7020
+ Inst = new StoreInst (Val, Ptr, isVolatile, Alignment ? Alignment->value () : 0 ,
7021
+ Ordering, SSID);
7015
7022
return AteExtraComma ? InstExtraComma : InstNormal;
7016
7023
}
7017
7024
0 commit comments