67 const size_t depRefIndex;
68 std::set<size_t> dependents;
99 handler_(
ref.getCodeHandler()) {
106 bool testAdd(
size_t iDep2,
116 cmpColor_ = minColor_;
123 dependents.insert(
iDep2);
136 inline void findIndexedPath(
size_t dep,
137 const std::vector<CG<Base> >&
depVals,
143 std::set<const OperationNode<Base>*> findOperationsUsingIndependents(
OperationNode<Base>& node)
const {
144 std::set<const OperationNode<Base>*>
ops;
146 handler_->startNewOperationTreeVisit();
148 findOperationsWithIndeps(node,
ops);
160 const std::vector<Argument<Base> >&
args = node->getArguments();
161 size_t size =
args.size();
162 for (
size_t a = 0;
a < size;
a++) {
170 if (
it->second.find(argumentIndex) !=
it->second.end()) {
182 using MapIndep2Dep_type =
typename OperationIndexedIndependents<Base>::MapDep2Indep_type;
194 for (
size_t argIndex = 0; argIndex <
aSize; argIndex++) {
246 if (
h1 !=
nullptr &&
h2 !=
nullptr)
247 throw CGException(
"Only one code handler allowed");
251 if (
dep1.isParameter() &&
dep2.isParameter()) {
252 return dep1.getValue() ==
dep2.getValue();
254 }
else if (
dep1.isVariable() &&
dep2.isVariable()) {
257 CPPADCG_ASSERT_UNKNOWN(
depRefOp->getOperationType() != CGOpCode::Inv)
268 CodeHandlerVector<Base, size_t>&
varColor) {
270 if (dependents.size() == 1) {
271 saveOperationReference(depRefIndex,
scRef,
scRef);
274 while (
scRef->getOperationType() == CGOpCode::Alias) {
275 CPPADCG_ASSERT_KNOWN(
scRef->getArguments().size() == 1,
"Invalid number of arguments for alias")
276 OperationNode<Base>*
sc =
scRef->getArguments()[0].getOperation();
277 if (
sc !=
nullptr &&
sc->getOperationType() == CGOpCode::Inv)
break;
280 while (
sc2->getOperationType() == CGOpCode::Alias) {
281 CPPADCG_ASSERT_KNOWN(
sc2->getArguments().size() == 1,
"Invalid number of arguments for alias")
282 OperationNode<Base>*
sc =
sc2->getArguments()[0].getOperation();
283 if (
sc !=
nullptr &&
sc->getOperationType() == CGOpCode::Inv)
break;
306 if (
scRef->getOperationType() !=
sc2->getOperationType()) {
310 CPPADCG_ASSERT_UNKNOWN(
scRef->getOperationType() != CGOpCode::Inv)
312 const std::vector<size_t>&
info1 =
scRef->getInfo();
313 const std::vector<size_t>&
info2 =
sc2->getInfo();
318 for (
size_t e = 0;
e <
info1.size();
e++) {
324 const std::vector<Argument<Base> >&
args1 =
scRef->getArguments();
325 const std::vector<Argument<Base> >&
args2 =
sc2->getArguments();
326 size_t size =
args1.size();
327 if (size !=
args2.size()) {
330 for (
size_t a = 0;
a < size;
a++) {
334 if (
a1.getParameter() !=
nullptr) {
335 if (
a2.getParameter() ==
nullptr || *
a1.getParameter() != *
a2.getParameter())
338 if (
a2.getOperation() ==
nullptr) {
344 if (
argRefOp->getOperationType() == CGOpCode::Inv) {
358 inline void saveOperationReference(
size_t dep2,
368 if (
argRefOp->getOperationType() != CGOpCode::Inv ||
arg2Op->getOperationType() != CGOpCode::Inv) {
378 if (
it->second.find(argIndex) !=
it->second.end()) {
394 inline void findIndexedPath(
const CG<Base>& depRef,
395 const CG<Base>&
dep2,
398 if (depRef.isVariable() &&
dep2.isVariable()) {
401 if (
depRefOp->getOperationType() != CGOpCode::Inv) {
420 while (
scRef->getOperationType() == CGOpCode::Alias) {
421 CPPADCG_ASSERT_KNOWN(
scRef->getArguments().size() == 1,
"Invalid number of arguments for alias")
422 OperationNode<Base>*
sc =
scRef->getArguments()[0].getOperation();
423 if (
sc !=
nullptr &&
sc->getOperationType() == CGOpCode::Inv)
break;
426 while (
sc2->getOperationType() == CGOpCode::Alias) {
427 CPPADCG_ASSERT_KNOWN(
sc2->getArguments().size() == 1,
"Invalid number of arguments for alias")
428 OperationNode<Base>*
sc =
sc2->getArguments()[0].getOperation();
429 if (
sc !=
nullptr &&
sc->getOperationType() == CGOpCode::Inv)
break;
433 CPPADCG_ASSERT_UNKNOWN(
scRef->getOperationType() ==
sc2->getOperationType())
437 typename std::map<
const OperationNode<Base>*, OperationIndexedIndependents<Base> >::iterator
itop2a;
443 for (
size_t a = 0;
a < size;
a++) {
447 if (
argRefOp->getOperationType() == CGOpCode::Inv) {
462 const std::vector<Argument<Base> >&
args2 =
sc2->getArguments();
463 CPPADCG_ASSERT_UNKNOWN(size ==
args2.size())
477 void findOperationsWithIndeps(OperationNode<Base>& node,
478 std::set<
const OperationNode<Base>*>&
ops)
const {
479 if (handler_->isVisited(node))
482 handler_->markVisited(node);
484 const std::vector<Argument<Base> >&
args = node.getArguments();
485 size_t size =
args.size();
486 for (
size_t a = 0;
a < size;
a++) {
488 if (
argOp !=
nullptr) {
489 if (
argOp->getOperationType() == CGOpCode::Inv) {
492 findOperationsWithIndeps(*
argOp,
ops);