Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 45 additions & 2 deletions src/FAST-Core-Tools/FASTAbstractVariableVersionSSA.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
"
I am the abstract representation of a version of a variable in Static Single Assignment form (SSA). A version represents a value assigned exactly once to a variable: each assignment to a variable during the SSA resolution creates a new version.

I store the local declaration (`localDeclaration`) of the variable this version belongs to, and I provide the common behavior shared by the concrete versions:

- `localUses` returns the accesses (reads and writes) linked to this version.
- `readAccesses` and `writeAccesses` split those accesses.
- `ssaVariables` returns the plain variable versions I represent: only myself for a `FASTVariableVersionSSA`, all my choices for a `FASTVariablePhiVersionSSA`.
- `name` returns a readable SSA name.

I have two concrete subclasses:
- `FASTVariableVersionSSA` is a plain version with a version number.
- `FASTVariablePhiVersionSSA` merges several versions at a control-flow join point.

I require the SSA resolution to have been run on the model before being used.
"
Class {
#name : 'FASTAbstractVariableVersionSSA',
#superclass : 'Object',
#superclass : 'MooseEntity',
#instVars : [
'localDeclaration'
],
Expand All @@ -9,6 +25,15 @@ Class {
#tag : 'SSA'
}

{ #category : 'meta' }
FASTAbstractVariableVersionSSA class >> annotation [

<FMClass: #AbstractVariableVersionSSA super: #MooseEntity>
<package: #'FAST-Core-Tools'>
<abstract>

]

{ #category : 'instance creation' }
FASTAbstractVariableVersionSSA class >> for: aFASTFortranVariable [

Expand Down Expand Up @@ -49,7 +74,9 @@ FASTAbstractVariableVersionSSA >> isPhi [
{ #category : 'accessing' }
FASTAbstractVariableVersionSSA >> localDeclaration [

^localDeclaration
<FMProperty: #localDeclaration type: #FASTTEntity>
<FMComment: 'Return the local declaration of the variable I represent.'>
^ localDeclaration
]

{ #category : 'accessing' }
Expand All @@ -75,6 +102,22 @@ FASTAbstractVariableVersionSSA >> name [
^ self subclassResponsibility
]

{ #category : 'accessing' }
FASTAbstractVariableVersionSSA >> nodes [
"Used for LocalResolver"

<FMProperty: #nodes type: #FASTTCanBeLocalDeclaration opposite: #ssaVersion>
<multivalued>
<FMComment: 'Return all entities concerned with this SSA version.'>
^ self attributeAt: #nodes ifAbsentPut: [ FMMultivalueLink on: self opposite: #ssaVersion: ]
]

{ #category : 'accessing' }
FASTAbstractVariableVersionSSA >> nodes: aCollectionOfFASTNodes [

self nodes value: aCollectionOfFASTNodes
]

{ #category : 'printing' }
FASTAbstractVariableVersionSSA >> printOn: aStream [
"Generate a string representation of the receiver based on its instance variables."
Expand Down
3 changes: 1 addition & 2 deletions src/FAST-Core-Tools/FASTLocalResolverScoping.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ Class {
{ #category : 'api' }
FASTLocalResolverScoping >> addUse: referingNode toLocalDeclaration: declarationNode [

referingNode localDeclaration: declarationNode.
declarationNode addLocalUse: referingNode
referingNode localDeclaration: declarationNode
]

{ #category : 'api' }
Expand Down
29 changes: 11 additions & 18 deletions src/FAST-Core-Tools/FASTNonLocalDeclaration.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ A ""null-object"" signaling the declaration of a 'name' was not found
"
Class {
#name : 'FASTNonLocalDeclaration',
#superclass : 'FASTEntity',
#traits : 'FASTTCanBeLocalDeclaration',
#classTraits : 'FASTTCanBeLocalDeclaration classTrait',
#instVars : [
'name'
],
#superclass : 'MooseEntity',
#traits : 'FASTTCanBeLocalDeclaration + FamixTNamedEntity',
#classTraits : 'FASTTCanBeLocalDeclaration classTrait + FamixTNamedEntity classTrait',
#category : 'FAST-Core-Tools-Resolver',
#package : 'FAST-Core-Tools',
#tag : 'Resolver'
}

{ #category : 'meta' }
FASTNonLocalDeclaration class >> annotation [

<FMClass: #NonLocalDeclaration super: #MooseEntity>
<package: #'FAST-Core-Tools'>

]

{ #category : 'accessing' }
FASTNonLocalDeclaration >> activeVersion [
"Used for LocalResolver"
Expand All @@ -31,15 +36,3 @@ FASTNonLocalDeclaration >> isNonLocalDeclaration [
FASTNonLocalDeclaration >> localDeclarationName [
^ self localUses anyOne localDeclarationName
]

{ #category : 'accessing' }
FASTNonLocalDeclaration >> name [

^ name
]

{ #category : 'accessing' }
FASTNonLocalDeclaration >> name: anObject [

name := anObject
]
36 changes: 24 additions & 12 deletions src/FAST-Core-Tools/FASTTCanBeLocalDeclaration.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ FASTTCanBeLocalDeclaration >> activeVersion: aSSAVersion [
FASTTCanBeLocalDeclaration >> addLocalUse: aFASTNode [
"Used for LocalResolver"

(self attributeAt: #localUses ifAbsent: [ Error signal: 'missing #localUses attribute in ' , self asString ]) add: aFASTNode
self localUses add: aFASTNode
]

{ #category : '*FAST-Core-Tools' }
Expand Down Expand Up @@ -69,7 +69,7 @@ FASTTCanBeLocalDeclaration >> assignedExpressionsMap [
FASTTCanBeLocalDeclaration >> clearLocalUses [
"Used for LocalResolver"

self attributeAt: #localUses put: OrderedCollection new
self localUses removeAll
]

{ #category : '*FAST-Core-Tools' }
Expand All @@ -83,18 +83,21 @@ FASTTCanBeLocalDeclaration >> hasLocalDeclaration [
FASTTCanBeLocalDeclaration >> localDeclaration [
"Used for LocalResolver"

^ self localDeclarationIfAbsent: [
self error: 'Missing #localDeclaration attribute in ' , self asString , '. It can have multiple sources:
- The local resolution was not done (launch the local resolver visitor or the SSA visitor on your top module)
- The entity is not an entity with a definition
- There is a bug in the local resolver' ]
<FMProperty: #localDeclaration type: #FASTTCanBeLocalDeclaration opposite: #localUses>
<FMComment:
'Return the local declaration for this node. The local declaration is the declaration of a named entity I represent. In languages without declarations, return the first occurence of the entity. This requires the local resolution to work.'>
^ self attributeAt: #localDeclaration ifAbsent: [ nil ]
]

{ #category : '*FAST-Core-Tools' }
FASTTCanBeLocalDeclaration >> localDeclaration: aDeclarationNode [
"Used for LocalResolver"

self attributeAt: #localDeclaration put: aDeclarationNode
self attributeAt: #localDeclaration put: (FMMultivalueLink
on: self
update: #localUses
from: (self localDeclarationIfAbsent: [ nil ])
to: aDeclarationNode)
]

{ #category : '*FAST-Core-Tools' }
Expand All @@ -115,14 +118,18 @@ FASTTCanBeLocalDeclaration >> localDeclarationifPresent: aBlock ifAbsent: anothe
FASTTCanBeLocalDeclaration >> localUses [
"Used for LocalResolver"

^ self attributeAt: #localUses ifAbsent: [ Error signal: 'missing #localUses attribute in ' , self asString ]
<FMProperty: #localUses type: #FASTTCanBeLocalDeclaration opposite: #localDeclaration>
<multivalued>
<FMComment:
'If I represent the local declaration of an entity, return all nodes representing the usage of the entity I represent. This requires the local resolution to work'>
^ self attributeAt: #localUses ifAbsentPut: [ FMMultivalueLink on: self opposite: #localDeclaration: ]
]

{ #category : '*FAST-Core-Tools' }
FASTTCanBeLocalDeclaration >> localUses: aCollection [
"Used for LocalResolver"

self attributeAt: #localUses put: aCollection
self localUses value: aCollection
]

{ #category : '*FAST-Core-Tools' }
Expand All @@ -143,16 +150,21 @@ FASTTCanBeLocalDeclaration >> ssaName [

{ #category : '*FAST-Core-Tools' }
FASTTCanBeLocalDeclaration >> ssaVersion [
"If I represent a variable and we resolved the SSA of my FAST model, I'll return the SSA version I'm linked to."

<FMProperty: #ssaVersion type: #FASTAbstractVariableVersionSSA opposite: #nodes>
<FMComment: 'If I represent a variable and we resolved the SSA of my FAST model, I''ll return the SSA version I''m linked to.'>
^ self attributeAt: #ssaVersion ifAbsent: [ nil ]
]

{ #category : '*FAST-Core-Tools' }
FASTTCanBeLocalDeclaration >> ssaVersion: aSSAVersion [
"Used for SSA"

self attributeAt: #ssaVersion put: aSSAVersion
self attributeAt: #ssaVersion put: (FMMultivalueLink
on: self
update: #nodes
from: self ssaVersion
to: aSSAVersion)
]

{ #category : '*FAST-Core-Tools' }
Expand Down
29 changes: 26 additions & 3 deletions src/FAST-Core-Tools/FASTVariablePhiVersionSSA.class.st
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
"
I am a phi version of a variable, created at a control-flow join point (for example at the end of an if statement or a loop) to merge the versions coming from the different branches.

I hold the versions I merge (`choices`) and the local declaration (`localDeclaration`) of the variable.

My name is built from the names of my choices, for example `phi(x_1, x_2)`.

I require the SSA resolution to have been run on the model before being used.
"
Class {
#name : 'FASTVariablePhiVersionSSA',
#superclass : 'FASTAbstractVariableVersionSSA',
#instVars : [
'choices'
'#choices => FMMany type: #FASTVariableVersionSSA opposite: #phiVersionContainers'
],
#category : 'FAST-Core-Tools-SSA',
#package : 'FAST-Core-Tools',
#tag : 'SSA'
}

{ #category : 'meta' }
FASTVariablePhiVersionSSA class >> annotation [

<FMClass: #VariablePhiVersionSSA super: #FASTAbstractVariableVersionSSA>
<package: #'FAST-Core-Tools'>

]

{ #category : 'adding' }
FASTVariablePhiVersionSSA >> addChoiceToPhi: aPhiVersion [

Expand All @@ -18,15 +35,21 @@ FASTVariablePhiVersionSSA >> addChoiceToPhi: aPhiVersion [
{ #category : 'accessing' }
FASTVariablePhiVersionSSA >> choices [

^choices
<FMComment: 'List of the SSA variables I could represent.'>
^ choices
]

{ #category : 'accessing' }
FASTVariablePhiVersionSSA >> choices: anObject [

choices value: anObject
]

{ #category : 'instance creation' }
FASTVariablePhiVersionSSA >> for: aCollection [

localDeclaration := aCollection anyOne localDeclaration.

choices := OrderedCollection new.
aCollection do: [ :v | v addChoiceToPhi: self ]
]

Expand Down
33 changes: 32 additions & 1 deletion src/FAST-Core-Tools/FASTVariableVersionSSA.class.st
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
"
I am a plain SSA version of a variable, created each time the variable is assigned. I hold the version number (`version`) of the variable and the local declaration (`localDeclaration`) I belong to.

My name is built from the name of my local declaration and my version number, for example `x_1`.

I require the SSA resolution to have been run on the model before being used.
"
Class {
#name : 'FASTVariableVersionSSA',
#superclass : 'FASTAbstractVariableVersionSSA',
#instVars : [
'version'
'#version',
'#phiVersionContainers => FMMany type: #FASTVariablePhiVersionSSA opposite: #choices'
],
#category : 'FAST-Core-Tools-SSA',
#package : 'FAST-Core-Tools',
#tag : 'SSA'
}

{ #category : 'meta' }
FASTVariableVersionSSA class >> annotation [

<FMClass: #VariableVersionSSA super: #FASTAbstractVariableVersionSSA>
<package: #'FAST-Core-Tools'>

]

{ #category : 'adding' }
FASTVariableVersionSSA >> addChoiceToPhi: aPhiVersion [

Expand Down Expand Up @@ -45,6 +61,19 @@ FASTVariableVersionSSA >> newVersionNumber [
^ version := version + 1
]

{ #category : 'accessing' }
FASTVariableVersionSSA >> phiVersionContainers [

<FMComment: 'I return all the Phi versions having me in their choices.'>
^ phiVersionContainers
]

{ #category : 'accessing' }
FASTVariableVersionSSA >> phiVersionContainers: aCollection [

phiVersionContainers value: aCollection
]

{ #category : 'testing' }
FASTVariableVersionSSA >> sameVariableAs: otherFASTFortranVariable [

Expand All @@ -60,6 +89,8 @@ FASTVariableVersionSSA >> ssaVariables [
{ #category : 'accessing' }
FASTVariableVersionSSA >> version [

<FMProperty: #version type: #Number>
<FMComment: 'The version number of this specific variable version'>
^ version
]

Expand Down
17 changes: 17 additions & 0 deletions src/FAST-Core-Tools/ManifestFASTCoreTools.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"
Please comment package here
"
Class {
#name : 'ManifestFASTCoreTools',
#superclass : 'PackageManifest',
#category : 'FAST-Core-Tools-Manifest',
#package : 'FAST-Core-Tools',
#tag : 'Manifest'
}

{ #category : 'asserting' }
ManifestFASTCoreTools class >> shouldBeIncludedByDefaultInMetamodelsWith: aCollectionOfPackages [
"Includes in MM that are based on FAST"

^ aCollectionOfPackages anySatisfy: [ :package | package definedClasses anySatisfy: [ :class | class = FASTTEntity ] ]
]
Loading