Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
glslang
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
glslang
Commits
bb0ac546
Commit
bb0ac546
authored
May 09, 2016
by
qining
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rebase to
d3d3ce71
,update comments, rename a…
Rebase to
d3d3ce71
,update comments, rename a member variable name, fix format issue
parent
5bec2b56
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
37 deletions
+35
-37
propagateNoContraction.cpp
glslang/MachineIndependent/propagateNoContraction.cpp
+35
-37
No files found.
glslang/MachineIndependent/propagateNoContraction.cpp
View file @
bb0ac546
...
...
@@ -142,7 +142,7 @@ ObjectAccessChain generateSymbolLabel(glslang::TIntermSymbol* node)
return
symbol_id
;
}
// Return true if the operation is an arithmetic operation and valid for
// Return
s
true if the operation is an arithmetic operation and valid for
// 'NoContraction' decoration.
bool
isArithmeticOperation
(
glslang
::
TOperator
op
)
{
...
...
@@ -173,11 +173,6 @@ bool isArithmeticOperation(glslang::TOperator op)
case
glslang
:
:
EOpDot
:
case
glslang
:
:
EOpAddCarry
:
case
glslang
:
:
EOpSubBorrow
:
case
glslang
:
:
EOpUMulExtended
:
case
glslang
:
:
EOpIMulExtended
:
case
glslang
:
:
EOpPostIncrement
:
case
glslang
:
:
EOpPostDecrement
:
case
glslang
:
:
EOpPreIncrement
:
...
...
@@ -224,7 +219,8 @@ ObjectAccessChain getSubAccessChainAfterPrefix(const ObjectAccessChain& chain,
const
ObjectAccessChain
&
prefix
)
{
size_t
pos
=
chain
.
find
(
prefix
);
if
(
pos
!=
0
)
return
chain
;
if
(
pos
!=
0
)
return
chain
;
return
chain
.
substr
(
prefix
.
length
()
+
sizeof
(
ObjectAccesschainDelimiter
));
}
...
...
@@ -257,7 +253,7 @@ protected:
ReturnBranchNodeSet
&
precise_return_nodes_
;
// A temporary cache of the symbol node whose defining node is to be found
// currently along traversing the AST.
ObjectAccessChain
object_to_be_defined
_
;
ObjectAccessChain
current_object_
_
;
// A map from object node to its accesschain. This traverser stores
// the built accesschains into this map for each object node it has
// visited.
...
...
@@ -273,18 +269,18 @@ TSymbolDefinitionCollectingTraverser::TSymbolDefinitionCollectingTraverser(
ObjectAccesschainSet
*
precise_objects
,
std
::
unordered_set
<
glslang
::
TIntermBranch
*>*
precise_return_nodes
)
:
TIntermTraverser
(
true
,
false
,
false
),
symbol_definition_mapping_
(
*
symbol_definition_mapping
),
precise_objects_
(
*
precise_objects
),
object_to_be_defined
_
(),
precise_objects_
(
*
precise_objects
),
current_object_
_
(),
accesschain_mapping_
(
*
accesschain_mapping
),
current_function_definition_node_
(
nullptr
),
precise_return_nodes_
(
*
precise_return_nodes
)
{}
// Visits a symbol node, set the
object_to_be_defined
_ to the
// Visits a symbol node, set the
current_object_
_ to the
// current node symbol ID, and record a mapping from this node to the current
//
object_to_be_defined
_, which is the just obtained symbol
//
current_object_
_, which is the just obtained symbol
// ID.
void
TSymbolDefinitionCollectingTraverser
::
visitSymbol
(
glslang
::
TIntermSymbol
*
node
)
{
object_to_be_defined
_
=
generateSymbolLabel
(
node
);
accesschain_mapping_
[
node
]
=
object_to_be_defined
_
;
current_object_
_
=
generateSymbolLabel
(
node
);
accesschain_mapping_
[
node
]
=
current_object_
_
;
}
// Visits an aggregate node, traverses all of its children.
...
...
@@ -304,7 +300,7 @@ bool TSymbolDefinitionCollectingTraverser::visitAggregate(glslang::TVisit,
// Traverse the items in the sequence.
glslang
::
TIntermSequence
&
seq
=
node
->
getSequence
();
for
(
int
i
=
0
;
i
<
(
int
)
seq
.
size
();
++
i
)
{
object_to_be_defined
_
.
clear
();
current_object_
_
.
clear
();
seq
[
i
]
->
traverse
(
this
);
}
return
false
;
...
...
@@ -329,11 +325,11 @@ bool TSymbolDefinitionCollectingTraverser::visitBranch(glslang::TVisit,
bool
TSymbolDefinitionCollectingTraverser
::
visitUnary
(
glslang
::
TVisit
/* visit */
,
glslang
::
TIntermUnary
*
node
)
{
object_to_be_defined
_
.
clear
();
current_object_
_
.
clear
();
node
->
getOperand
()
->
traverse
(
this
);
if
(
isAssignOperation
(
node
->
getOp
()))
{
// We should always be able to get an accesschain of the operand node.
assert
(
!
object_to_be_defined
_
.
empty
());
assert
(
!
current_object_
_
.
empty
());
// If the operand node object is 'precise', we collect its accesschain
// for the initial set of 'precise' objects.
...
...
@@ -341,16 +337,16 @@ bool TSymbolDefinitionCollectingTraverser::visitUnary(glslang::TVisit /* visit *
// The operand node is an 'precise' object node, add its
// accesschain to the set of 'precise' objects. This is to collect
// the initial set of 'precise' objects.
precise_objects_
.
insert
(
object_to_be_defined
_
);
precise_objects_
.
insert
(
current_object_
_
);
}
// Gets the symbol ID from the object's accesschain.
ObjectAccessChain
id_symbol
=
getFrontElement
(
object_to_be_defined
_
);
ObjectAccessChain
id_symbol
=
getFrontElement
(
current_object_
_
);
// Add a mapping from the symbol ID to this assignment operation node.
symbol_definition_mapping_
.
insert
(
std
::
make_pair
(
id_symbol
,
node
));
}
// Unary node is not a dereference node, so we clear the accesschain which
// is under construction.
object_to_be_defined
_
.
clear
();
current_object_
_
.
clear
();
return
false
;
}
...
...
@@ -360,12 +356,12 @@ bool TSymbolDefinitionCollectingTraverser::visitBinary(glslang::TVisit /* visit
glslang
::
TIntermBinary
*
node
)
{
// Traverses the left node to build the accesschain info for the object.
object_to_be_defined
_
.
clear
();
current_object_
_
.
clear
();
node
->
getLeft
()
->
traverse
(
this
);
if
(
isAssignOperation
(
node
->
getOp
()))
{
// We should always be able to get an accesschain for the left node.
assert
(
!
object_to_be_defined
_
.
empty
());
assert
(
!
current_object_
_
.
empty
());
// If the left node object is 'precise', it is an initial precise object
// specified in the shader source. Adds it to the initial worklist to
...
...
@@ -374,17 +370,17 @@ bool TSymbolDefinitionCollectingTraverser::visitBinary(glslang::TVisit /* visit
// The left node is an 'precise' object node, add its accesschain to
// the set of 'precise' objects. This is to collect the initial set
// of 'precise' objects.
precise_objects_
.
insert
(
object_to_be_defined
_
);
precise_objects_
.
insert
(
current_object_
_
);
}
// Gets the symbol ID from the object accesschain, which should be the
// first element recorded in the accesschain.
ObjectAccessChain
id_symbol
=
getFrontElement
(
object_to_be_defined
_
);
ObjectAccessChain
id_symbol
=
getFrontElement
(
current_object_
_
);
// Adds a mapping from the symbol ID to this assignment operation node.
symbol_definition_mapping_
.
insert
(
std
::
make_pair
(
id_symbol
,
node
));
// Traverses the right node, there may be other 'assignment'
// operatrions in the right.
object_to_be_defined
_
.
clear
();
current_object_
_
.
clear
();
node
->
getRight
()
->
traverse
(
this
);
}
else
if
(
isDereferenceOperation
(
node
->
getOp
()))
{
...
...
@@ -393,26 +389,27 @@ bool TSymbolDefinitionCollectingTraverser::visitBinary(glslang::TVisit /* visit
// object id.
if
(
node
->
getOp
()
==
glslang
::
EOpIndexDirectStruct
)
{
unsigned
struct_dereference_index
=
getStructIndexFromConstantUnion
(
node
->
getRight
());
object_to_be_defined
_
.
push_back
(
ObjectAccesschainDelimiter
);
object_to_be_defined
_
.
append
(
std
::
to_string
(
struct_dereference_index
));
current_object_
_
.
push_back
(
ObjectAccesschainDelimiter
);
current_object_
_
.
append
(
std
::
to_string
(
struct_dereference_index
));
}
accesschain_mapping_
[
node
]
=
object_to_be_defined
_
;
accesschain_mapping_
[
node
]
=
current_object_
_
;
// For dereference node, there is no need to traverse the right child
// node as the right node should always be an integer type object.
}
else
{
// For other binary nodes, still traverse the right node.
object_to_be_defined
_
.
clear
();
node
->
getRight
()
->
traverse
(
this
)
;
current_object_
_
.
clear
();
return
true
;
}
return
false
;
}
// Traverses the AST and returns a tuple of
three
members:
// Traverses the AST and returns a tuple of
four
members:
// 1) a mapping from symbol IDs to the definition nodes (aka. assignment nodes) of these symbols.
// 2) a mapping from object nodes in the AST to the accesschains of these objects.
// 3) a set of accesschains of precise objects.
// 4) a set of return nodes with precise expressions.
std
::
tuple
<
NodeMapping
,
AccessChainMapping
,
ObjectAccesschainSet
,
ReturnBranchNodeSet
>
getSymbolToDefinitionMappingAndPreciseSymbolIDs
(
const
glslang
::
TIntermediate
&
intermediate
)
{
...
...
@@ -420,7 +417,8 @@ getSymbolToDefinitionMappingAndPreciseSymbolIDs(const glslang::TIntermediate& in
ReturnBranchNodeSet
());
TIntermNode
*
root
=
intermediate
.
getTreeRoot
();
if
(
root
==
0
)
return
result_tuple
;
if
(
root
==
0
)
return
result_tuple
;
NodeMapping
&
symbol_definition_mapping
=
std
::
get
<
0
>
(
result_tuple
);
AccessChainMapping
&
accesschain_mapping
=
std
::
get
<
1
>
(
result_tuple
);
...
...
@@ -561,7 +559,7 @@ protected:
const
ObjectAccessChain
*
precise_object_
;
};
// Visit a binary node. If the node is an object node, it must be a dereference
// Visit
s
a binary node. If the node is an object node, it must be a dereference
// node. In such cases, if the left node is 'precise', this node should also be
// 'precise'.
bool
TNoContractionAssigneeCheckingTraverser
::
visitBinary
(
glslang
::
TVisit
,
...
...
@@ -588,7 +586,7 @@ bool TNoContractionAssigneeCheckingTraverser::visitBinary(glslang::TVisit,
return
false
;
}
// Visit a symbol node, if the symbol node ID (its accesschain string) matches
// Visit
s
a symbol node, if the symbol node ID (its accesschain string) matches
// with the given precise object, this node should be 'precise'.
void
TNoContractionAssigneeCheckingTraverser
::
visitSymbol
(
glslang
::
TIntermSymbol
*
node
)
{
...
...
@@ -649,7 +647,7 @@ public:
}
protected
:
// Visit an aggregate node. The node can be a initializer list, in which
// Visit
s
an aggregate node. The node can be a initializer list, in which
// case we need to find the 'precise' or 'precise' containing object node
// with the accesschain record. In other cases, just need to traverse all
// the children nodes.
...
...
@@ -683,7 +681,7 @@ protected:
return
true
;
}
// Visit a binary node. A binary node can be an object node, e.g. a dereference node.
// Visit
s
a binary node. A binary node can be an object node, e.g. a dereference node.
// As only the top object nodes in the right side of an assignment needs to be visited
// and added to 'precise' worklist, this traverser won't visit the children nodes of
// an object node. If the binary node does not represent an object node, it should
...
...
@@ -779,7 +777,7 @@ void PropagateNoContraction(const glslang::TIntermediate& intermediate)
{
// First, traverses the AST, records symbols with their defining operations
// and collects the initial set of precise symbols (symbol nodes that marked
// as 'noContraction').
// as 'noContraction')
and precise return nodes
.
auto
mappings_and_precise_objects
=
getSymbolToDefinitionMappingAndPreciseSymbolIDs
(
intermediate
);
...
...
@@ -831,7 +829,7 @@ void PropagateNoContraction(const glslang::TIntermediate& intermediate)
// Get all the defining nodes of that symbol ID.
std
::
pair
<
NodeMapping
::
iterator
,
NodeMapping
::
iterator
>
range
=
symbol_definition_mapping
.
equal_range
(
symbol_id
);
// Visit all the assignment nodes of that symbol ID and
// Visit
s
all the assignment nodes of that symbol ID and
// 1) Check if the assignee node is 'precise' or contains 'precise'
// objects.
// 2) Propagate the 'precise' to the top layer object ndoes
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment