private boolean isScopeEntryForVectorVariable(ScopeEntry scopeEntry) { return scopeEntry != null && scopeEntry.hasVariableDeclInfo() && scopeEntry.getVariableDeclInfo() == vectorVariableDeclInfo; }
private String applyVariableNameMapping(String name) { ScopeEntry scopeEntry = currentScope.lookupScopeEntry(name); if (scopeEntry == null) { return name; } if (scopeEntry.hasVariableDeclInfo()) { return varDeclMapping.getOrDefault(scopeEntry.getVariableDeclInfo(), name); } assert scopeEntry.hasParameterDecl(); return paramDeclMapping.getOrDefault(scopeEntry.getParameterDecl(), name); }
@Override public void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr) { super.visitVariableIdentifierExpr(variableIdentifierExpr); final ScopeEntry scopeEntry = currentScope.lookupScopeEntry(variableIdentifierExpr.getName()); if (scopeEntry != null && scopeEntry.hasVariableDeclInfo()) { // If this is a global, mark it as used. unusedGlobals.remove(scopeEntry.getVariableDeclInfo()); } }
private boolean isCurrentComponentVariable(String name) { ScopeEntry entry = currentScope.lookupScopeEntry(name); return entry != null && entry.hasVariableDeclInfo() && currentComponent.getVariableDeclInfo() == entry.getVariableDeclInfo(); }
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 public void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr) { super.visitVariableIdentifierExpr(variableIdentifierExpr); final ScopeEntry se = currentScope.lookupScopeEntry(variableIdentifierExpr.getName()); if (se != null && se.hasVariableDeclInfo() && se.getVariableDeclInfo() == backupVdi) { found = true; } }
@Override public void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr) { super.visitVariableIdentifierExpr(variableIdentifierExpr); if (parentMap.getParent(variableIdentifierExpr) instanceof MemberLookupExpr) { return; } if (!variableIdentifierExpr.getName().equals(vectorVariableDeclInfo.getName())) { return; } final ScopeEntry se = currentScope.lookupScopeEntry(variableIdentifierExpr.getName()); if (se != null && se.hasVariableDeclInfo() && se.getVariableDeclInfo() == vectorVariableDeclInfo) { vectorUsedDirectly = true; } }
@Override public void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr) { super.visitVariableIdentifierExpr(variableIdentifierExpr); final ScopeEntry se = currentScope.lookupScopeEntry(variableIdentifierExpr.getName()); if (se == null || !se.hasVariableDeclInfo()) { return; } final VariableDeclInfo variableDeclInfo = se.getVariableDeclInfo(); if (!allowedToReduce(variableDeclInfo)) { return; } if (inLValueContext()) { if (!context.reduceEverywhere() && !currentProgramPointHasNoEffect()) { // The declaration is used as an l-value. To preserve semantics we cannot inline its // initializer. For example, in: // int x = 2; // x += 2; // x += x; // we end up with x == 8, but if we would inline the initializer to the r-value usage of // x we would get x == 6. blackList.add(variableDeclInfo); } return; } inlineableUsages.add(new ImmutablePair<>(variableDeclInfo, variableIdentifierExpr)); }
for (String name : currentScope.keys()) { ScopeEntry entry = currentScope.lookupScopeEntry(name); if (entry.hasVariableDeclInfo() && !referencedScopeEntries.peek().contains(entry)) { if (allowedToReduceLocalDecl(entry.getVariableDeclInfo())) { addOpportunity( if (!entry.hasVariableDeclInfo()) { continue;
private boolean isCandidateForMerging(ScopeEntry entry) { if (!entry.hasVariableDeclInfo()) { return false; } if (shadingLanguageVersion.initializersOfConstMustBeConst()) { if (entry.getType() instanceof QualifiedType && ((QualifiedType) entry.getType()).hasQualifier(TypeQualifier.CONST)) { // Do not merge const variables if the shading language requires the initializers of // const variables to be const. The issue is that if v is const and used in // some future initialiser, and we merge v into m, as m.x say, then m.x will appear in the // future initializer, which is illegal if m is not const itself. // With some additional analysis we could make this restriction only apply to consts // that are actually used in future initialisers. return false; } } Type unqualifiedType = entry.getType().getWithoutQualifiers(); if (!(unqualifiedType instanceof BasicType)) { return false; } BasicType basicType = (BasicType) unqualifiedType; if (!(basicType.isScalar() || basicType.isVector())) { return false; } if (basicType.isBoolean()) { return false; } return true; }