public List<String> namesOfAllVariablesInScope() { List<String> result = new ArrayList<>(); Scope scope = this; while (scope != null) { result.addAll(scope.keys()); scope = scope.parent; } result.sort(String::compareTo); return Collections.unmodifiableList(result); }
Map<String, Type> getGlobalsFromShader(TranslationUnit shader) { visit(shader); Map<String, Type> result = new HashMap<>(); for (String globalName : currentScope.keys()) { result.put(globalName, currentScope.lookupType(globalName)); } return result; } }.getGlobalsFromShader(shader);
private void getReductionOpportunitiesForUnusedGlobals() { for (String name : currentScope.keys()) { ScopeEntry entry = currentScope.lookupScopeEntry(name); assert entry.hasVariableDeclInfo(); assert referencedScopeEntries.peek() != null; if (!referencedScopeEntries.peek().contains(entry)) { addOpportunity(new VariableDeclReductionOpportunity(entry.getVariableDeclInfo(), entry.getVariablesDeclaration(), getVistitationDepth())); } } }
@Override protected void popScope() { assert lastExitedBlock != null; if (!(parentMap.getParent(lastExitedBlock) instanceof SwitchStmt)) { List<MergeSet> mergeSetsForThisScope = new ArrayList<>(); for (String v : currentScope.keys()) { ScopeEntry entry = currentScope.lookupScopeEntry(v); if (!isCandidateForMerging(entry)) { continue; } List<MergeSet> mergeSetsWithSpace = mergeSetsForThisScope.stream() .filter(mergeSet -> mergeSet .canAccept(entry)).collect(Collectors.toList()); int index = generator.nextInt(mergeSetsWithSpace.size() + 1); if (index == mergeSetsWithSpace.size()) { MergeSet newMergeSet = new MergeSet(entry); mergeSetsForThisScope.add(newMergeSet); } else { mergeSetsWithSpace.get(index).add(entry); } } opportunities.addAll( mergeSetsForThisScope.stream().filter(mergeSet -> mergeSet.getNumVars() > 1) .map(mergeSet -> new VectorizationOpportunity(lastExitedBlock, mergeSet, parentMap)) .collect(Collectors.toList())); } super.popScope(); }
@Override public void visitDeclarationStmt(DeclarationStmt declarationStmt) { List<String> existingKeys = new ArrayList<>(); existingKeys.addAll(currentScope.keys()); super.visitDeclarationStmt(declarationStmt); List<String> newKeys = currentScope.keys().stream().filter(key -> !existingKeys.contains(key)) .collect(Collectors.toList()); newKeys.sort(String::compareTo); for (String newKey : newKeys) { if (isCurrentComponentVariable(newKey)) { final ExprStmt insertedStmt = new ExprStmt( new BinaryExpr( new MemberLookupExpr( new VariableIdentifierExpr(mergeSet.getMergedName()), getSwizzle(newKey)), new VariableIdentifierExpr(newKey), BinOp.ASSIGN )); assert parentMap.getParent(declarationStmt) instanceof BlockStmt; ((BlockStmt) parentMap.getParent(declarationStmt)).insertAfter(declarationStmt, insertedStmt); } } } }
@Override protected void popScope() { for (String name : currentScope.keys()) { ScopeEntry entry = currentScope.lookupScopeEntry(name); if (entry.hasVariableDeclInfo() && !referencedScopeEntries.peek().contains(entry)) { assert currentScope.lookupScopeEntry(name) == entry || currentScope.getParent().lookupScopeEntry(name) == entry; if (!currentScope.keys().contains(name)) { addReferencedScopeEntry(entry);