Skip to content

Commit 7fdd0cc

Browse files
committed
grammar: re-work handling of align in global and function declarations
This is not a proper fix, but works for the majority of cases. If anyone has a better idea how to solve the LR-1 conflicts related to Align in FuncAttribute and as part of GlobalDecl and FuncDef, FuncDecl, please do get in touch. Fixes llir/llvm#40. Well, most of it at least. We still need to figure out how to handle Align, AttrString and AttrPair of ReturnAttribute.
1 parent 71126f6 commit 7fdd0cc

File tree

1 file changed

+45
-29
lines changed

1 file changed

+45
-29
lines changed

ll.tm

+45-29
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,22 @@ SelectionKind -> SelectionKind
906906
# Const OptionalAttrs
907907
908908
GlobalDecl -> GlobalDecl
909-
: Name=GlobalIdent '=' Linkage=ExternLinkage Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type (',' Section)? (',' Partition)? (',' Comdat)? (',' Align)? Metadata=(',' MetadataAttachment)+? FuncAttrs=FuncAttribute+?
910-
| Name=GlobalIdent '=' Linkage=Linkageopt Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type Init=Constant (',' Section)? (',' Partition)? (',' Comdat)? (',' Align)? Metadata=(',' MetadataAttachment)+? FuncAttrs=FuncAttribute+?
909+
#: Name=GlobalIdent '=' Linkage=ExternLinkage Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type (',' Section)? (',' Partition)? (',' Comdat)? (',' Align)? Metadata=(',' MetadataAttachment)+? FuncAttrs=FuncAttribute+?
910+
#| Name=GlobalIdent '=' Linkage=Linkageopt Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type Init=Constant (',' Section)? (',' Partition)? (',' Comdat)? (',' Align)? Metadata=(',' MetadataAttachment)+? FuncAttrs=FuncAttribute+?
911+
: Name=GlobalIdent '=' Linkage=ExternLinkage Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type GlobalFields=(',' GlobalField)* Metadata=(',' MetadataAttachment)+? FuncAttrs=FuncAttribute+?
912+
| Name=GlobalIdent '=' Linkage=Linkageopt Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable ContentType=Type Init=Constant GlobalFields=(',' GlobalField)* Metadata=(',' MetadataAttachment)+? FuncAttrs=FuncAttribute+?
913+
;
914+
915+
# NOTE: GlobalField is a workaround to handle the LR-1 shift/reduce conflict
916+
# between FuncAttribute and Align, both of which contain 'align'.
917+
918+
%interface GlobalField;
919+
920+
GlobalField -> GlobalField
921+
: Section
922+
| Partition
923+
| Comdat
924+
| Align
911925
;
912926
913927
ExternallyInitialized -> ExternallyInitialized
@@ -996,11 +1010,26 @@ FuncDef -> FuncDef
9961010
# '(' ArgList ')' OptAddrSpace OptFuncAttrs OptSection OptPartition
9971011
# OptionalAlign OptGC OptionalPrefix OptionalPrologue OptPersonalityFn
9981012
999-
# TODO: Add Alignopt before GCopt once the LR-1 conflict has been resolved.
1000-
# The shift/reduce conflict is present since FuncAttribute also contains 'align'.
1001-
10021013
FuncHeader -> FuncHeader
1003-
: (Linkage | ExternLinkage)? Preemptionopt Visibilityopt DLLStorageClassopt CallingConvopt ReturnAttrs=ReturnAttribute* RetType=Type Name=GlobalIdent '(' Params ')' UnnamedAddropt AddrSpaceopt FuncAttrs=FuncAttributeAndAlign* Sectionopt Partitionopt Comdatopt GCopt Prefixopt Prologueopt Personalityopt
1014+
#: (Linkage | ExternLinkage)? Preemptionopt Visibilityopt DLLStorageClassopt CallingConvopt ReturnAttrs=ReturnAttribute* RetType=Type Name=GlobalIdent '(' Params ')' UnnamedAddropt AddrSpaceopt FuncAttrs=FuncAttributeAndAlign* Sectionopt Partitionopt Comdatopt Alignopt GCopt Prefixopt Prologueopt Personalityopt
1015+
: (Linkage | ExternLinkage)? Preemptionopt Visibilityopt DLLStorageClassopt CallingConvopt ReturnAttrs=ReturnAttribute* RetType=Type Name=GlobalIdent '(' Params ')' UnnamedAddropt AddrSpaceopt FuncHdrFields=FuncHdrField*
1016+
;
1017+
1018+
# NOTE: FuncHdrField is a workaround to handle the LR-1 shift/reduce conflict
1019+
# between FuncAttribute and Align, both of which contain 'align'.
1020+
1021+
%interface FuncHdrField;
1022+
1023+
FuncHdrField -> FuncHdrField
1024+
: FuncAttribute
1025+
| Section
1026+
| Partition
1027+
| Comdat
1028+
| Align
1029+
| GC
1030+
| Prefix
1031+
| Prologue
1032+
| Personality
10041033
;
10051034
10061035
# NOTE: Named GCNode instead of GC to avoid collisions with 'gc' token. Both
@@ -2657,6 +2686,8 @@ SelectInst -> SelectInst
26572686
#
26582687
# bundle-tag ::= String Constant
26592688
2689+
# TODO: add align as valid function attribute to CallInst.
2690+
26602691
CallInst -> CallInst
26612692
: Tailopt 'call' FastMathFlags=FastMathFlag* CallingConvopt ReturnAttrs=ReturnAttribute* AddrSpaceopt Typ=Type Callee=Value '(' Args ')' FuncAttrs=FuncAttribute* OperandBundles=('[' (OperandBundle separator ',')+ ']')? Metadata=(',' MetadataAttachment)+?
26622693
;
@@ -2794,7 +2825,9 @@ BrTerm -> BrTerm
27942825
;
27952826
27962827
# TODO: replace `IntType Value` with TypeValue when the parser generator
2797-
# is capable of handling the shift/reduce conflict.
2828+
# is capable of handling the shift/reduce conflict. When TypeValue is used, the
2829+
# conflict happens as 'br' 'label' may be the start of either BrTerm or
2830+
# CondBrTerm.
27982831
27992832
# Conditional branch.
28002833
CondBrTerm -> CondBrTerm
@@ -2840,6 +2873,8 @@ IndirectBrTerm -> IndirectBrTerm
28402873
# ::= 'invoke' OptionalCallingConv OptionalAttrs Type Value ParamList
28412874
# OptionalAttrs 'to' TypeAndValue 'unwind' TypeAndValue
28422875
2876+
# TODO: add align as valid function attribute to InvokeTerm.
2877+
28432878
InvokeTerm -> InvokeTerm
28442879
: 'invoke' CallingConvopt ReturnAttrs=ReturnAttribute* AddrSpaceopt Typ=Type Invokee=Value '(' Args ')' FuncAttrs=FuncAttribute* OperandBundles=('[' (OperandBundle separator ',')+ ']')? 'to' Normal=Label 'unwind' Exception=Label Metadata=(',' MetadataAttachment)+?
28452880
;
@@ -3348,7 +3383,7 @@ DIGlobalVariableField -> DIGlobalVariableField
33483383
33493384
# ~~~ [ DIGlobalVariableExpression ] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33503385
3351-
# TODO: add link to LangRef.html.
3386+
# https://llvm.org/docs/LangRef.html#diglobalvariableexpression
33523387
33533388
# ref: ParseDIGlobalVariableExpression
33543389
#
@@ -4636,16 +4671,10 @@ FPred -> FPred
46364671
# ::= <attr> | <attr> '=' <value>
46374672
46384673
# NOTE: FuncAttribute should contain Align. However, using LALR(1) this
4639-
# produces a reduce/reduce conflict as GlobalAttr also contains Align.
4640-
#
4641-
# To handle these ambiguities, (FuncAttribute | Align) is used in those places
4642-
# where FuncAttribute is used outside of GlobalDef and GlobalDecl (which also has
4643-
# GlobalAttr).
4674+
# produces a reduce/reduce conflict as GlobalDecl also contains Align.
46444675
46454676
%interface FuncAttribute;
46464677
4647-
# TODO: Figure out how to enable Align in FuncAttribute again.
4648-
46494678
FuncAttribute -> FuncAttribute
46504679
: AttrString
46514680
| AttrPair
@@ -4661,13 +4690,6 @@ FuncAttribute -> FuncAttribute
46614690
| FuncAttr
46624691
;
46634692
4664-
%interface FuncAttributeAndAlign;
4665-
4666-
FuncAttributeAndAlign -> FuncAttributeAndAlign
4667-
: FuncAttribute
4668-
| Align
4669-
;
4670-
46714693
FuncAttr -> FuncAttr
46724694
: 'alwaysinline'
46734695
| 'argmemonly'
@@ -4760,12 +4782,6 @@ Label -> Label
47604782
# this is not possible as it leads to shift/reduce conflicts (when merging
47614783
# GlobalDecl and GlobalDef). Perhaps when the parser generator is better capable
47624784
# at resolving conflicts.
4763-
#
4764-
# ll.tm,812: input: TopLevelEntity_optlist GlobalIdent '=' Linkageopt Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable Type
4765-
# shift/reduce conflict (next: global_ident_tok)
4766-
# GlobalDecl : GlobalIdent '=' Linkageopt Preemptionopt Visibilityopt DLLStorageClassopt ThreadLocalopt UnnamedAddropt AddrSpaceopt ExternallyInitializedopt Immutable Type
4767-
#
4768-
# conflicts: 1 shift/reduce and 0 reduce/reduce
47694785
47704786
Linkage -> Linkage
47714787
: 'appending'
@@ -4870,7 +4886,7 @@ ReturnAttribute -> ReturnAttribute
48704886
# - `ReturnAttrs` cannot be nullable, since it precedes FuncAttrs
48714887
#: AttrString
48724888
#| AttrPair
4873-
#: Align
4889+
#| Align
48744890
: Dereferenceable
48754891
| ReturnAttr
48764892
;

0 commit comments

Comments
 (0)