@Override public String toString() { return entries.stream().map(item -> item.getVariableDeclInfo().getName()) .collect(Collectors.toList()).toString(); }
private boolean isScopeEntryForVectorVariable(ScopeEntry scopeEntry) { return scopeEntry != null && scopeEntry.hasVariableDeclInfo() && scopeEntry.getVariableDeclInfo() == vectorVariableDeclInfo; }
private boolean isCurrentComponentVariable(String name) { ScopeEntry entry = currentScope.lookupScopeEntry(name); return entry != null && entry.hasVariableDeclInfo() && currentComponent.getVariableDeclInfo() == entry.getVariableDeclInfo(); }
@Override public void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration) { assert !inDeclarationOfTargetVariable; for (VariableDeclInfo vdi : variablesDeclaration.getDeclInfos()) { if (currentComponent.getVariableDeclInfo() == vdi) { inDeclarationOfTargetVariable = true; break; } } super.visitVariablesDeclaration(variablesDeclaration); inDeclarationOfTargetVariable = false; }
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); }
public List<Integer> getIndices(String name) { int startIndex = 0; for (ScopeEntry entry : entries) { BasicType type = (BasicType) entry.getType().getWithoutQualifiers(); if (entry.getVariableDeclInfo().getName().equals(name)) { List<Integer> result = new ArrayList<>(); for (int i = 0; i < type.getNumElements(); i++) { result.add(startIndex + i); } return result; } startIndex += type.getNumElements(); } throw new RuntimeException("Should be unreachable."); }
@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()); } }
public String getMergedName() { final List<MergedVariablesComponentData> mergedVariablesComponentDataList = new ArrayList<>(); int currentOffset = 0; for (ScopeEntry entry : entries) { mergedVariablesComponentDataList.add( new MergedVariablesComponentData(currentOffset, getWidth(entry), entry.getVariableDeclInfo().getName())); currentOffset += getWidth(entry); } return getMergedName(mergedVariablesComponentDataList); }
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)); }
ScopeEntry entry = currentScope.lookupScopeEntry(name); if (entry.hasVariableDeclInfo() && !referencedScopeEntries.peek().contains(entry)) { if (allowedToReduceLocalDecl(entry.getVariableDeclInfo())) { addOpportunity( new VariableDeclReductionOpportunity( entry.getVariableDeclInfo(), entry.getVariablesDeclaration(), getVistitationDepth())); String name = entry.getVariableDeclInfo().getName(); assert currentScope.lookupScopeEntry(name) == entry || currentScope.getParent().lookupScopeEntry(name) == entry;