private static List<String> getFunctionNames(List<FunctionPrototype> prototypes) { return prototypes.stream().map(y -> y.getName()).collect(Collectors.toList()); }
@Override public void visitFunctionPrototype(FunctionPrototype functionPrototype) { if (!functionRenaming.containsKey(functionPrototype.getName())) { functionRenaming.put(functionPrototype.getName(), renameFunction(functionPrototype.getName())); } functionPrototype.setName(functionRenaming.get(functionPrototype.getName())); super.visitFunctionPrototype(functionPrototype); }
@Override public void visitFunctionPrototype(FunctionPrototype functionPrototype) { super.visitFunctionPrototype(functionPrototype); names.add(functionPrototype.getName()); }
@Override public void visitFunctionPrototype(FunctionPrototype functionPrototype) { super.visitFunctionPrototype(functionPrototype); String name = functionPrototype.getName(); if (!userDefinedFunctions.containsKey(name)) { userDefinedFunctions.put(name, new HashSet<>()); } userDefinedFunctions.get(name).add(functionPrototype); }
private boolean needToAddDonorFunction(FunctionPrototype fromDonor, List<FunctionPrototype> recipientFunctionPrototypes) { if (fromDonor.getName().equals("main") || prototypeMatches(fromDonor, recipientFunctionPrototypes)) { return false; } if (prototypeClashes(fromDonor, recipientFunctionPrototypes)) { throw new RuntimeException( "Donor and recipient are incompatible as they declare clashing functions named " + fromDonor.getName()); } return true; }
private String functionName() { return fd.getPrototype().getName(); }
@Override public void visitFunctionPrototype(FunctionPrototype functionPrototype) { super.visitFunctionPrototype(functionPrototype); if (functionPrototype.getName().equals(functionDefinition.getPrototype().getName())) { // As we only apply this reduction opportunity if the function name is not overloaded, // this has to be a prototype for the relevant function (there could be multiple identical // prototypes). functionPrototype.removeParameter(paramIndex); } }
boolean check(TranslationUnit tu) { visit(tu); return triggerFunction.isPresent() && callsIndirectly.get("main").contains(triggerFunction.get().getPrototype().getName()); }
@Override public void visitFunctionDefinition(FunctionDefinition functionDefinition) { System.out.println("Entering function " + functionDefinition.getPrototype().getName()); super.visitFunctionDefinition(functionDefinition); System.out.println("Leaving function " + functionDefinition.getPrototype().getName()); }
@Override public void visitFunctionDefinition(FunctionDefinition functionDefinition) { assert enclosingFunctionName == null; enclosingFunctionName = functionDefinition.getPrototype().getName(); super.visitFunctionDefinition(functionDefinition); assert enclosingFunctionName == functionDefinition.getPrototype().getName(); enclosingFunctionName = null; }
@Override public void visitFunctionDefinition(FunctionDefinition functionDefinition) { super.visitFunctionDefinition(functionDefinition); String name = functionDefinition.getPrototype().getName(); if (!userDefinedFunctions.containsKey(name)) { userDefinedFunctions.put(name, new HashSet<>()); } userDefinedFunctions.get(name).add(functionDefinition.getPrototype()); }
private ConstCleaner(TranslationUnit tu, ShadingLanguageVersion shadingLanguageVersion) { this.atGlobalScope = true; this.currentVariablesDeclaration = Optional.empty(); this.globalsToBeReInitialized = new ArrayList<>(); this.shadingLanguageVersion = shadingLanguageVersion; visit(tu); addGlobalInitializers(tu .getTopLevelDeclarations() .stream() .filter(item -> item instanceof FunctionDefinition) .map(item -> (FunctionDefinition) item) .filter(item -> item.getPrototype().getName().equals("main")) .collect(Collectors.toList()) .get(0)); }
private void sweep(TranslationUnit tu, Set<String> callableFromMain) { for (int i = tu.getTopLevelDeclarations().size() - 1; i >= 0; i--) { Declaration decl = tu.getTopLevelDeclarations().get(i); if (decl instanceof FunctionPrototype) { if (!callableFromMain.contains(((FunctionPrototype) decl).getName())) { tu.removeTopLevelDeclaration(i); } } if (decl instanceof FunctionDefinition) { if (!callableFromMain.contains(((FunctionDefinition) decl).getPrototype().getName())) { tu.removeTopLevelDeclaration(i); } } } }
public FunctionCallExprTemplate(FunctionPrototype prototype) { this.name = prototype.getName(); this.resultType = prototype.getReturnType(); this.argTypes = new ArrayList<>(); for (ParameterDecl param : prototype.getParameters()) { assert param.getArrayInfo() == null; this.argTypes.add(param.getType()); } }
@Override public void visitFunctionCallExpr(FunctionCallExpr functionCallExpr) { super.visitFunctionCallExpr(functionCallExpr); if (enclosingFunction.isPresent()) { addCallGraphEdge(enclosingFunction.get().getPrototype().getName(), functionCallExpr.getCallee()); } }
@Override public void visitFunctionCallExpr(FunctionCallExpr functionCallExpr) { super.visitFunctionCallExpr(functionCallExpr); if (functionCallExpr.getCallee().equals(functionDefinition.getPrototype().getName())) { // As we only apply this reduction opportunity if the function name is not overloaded, // this has to be a call to the relevant function. functionCallExpr.removeArg(paramIndex); } }
private Set<FunctionPrototype> findPossibleMatchesForCall(FunctionCallExpr functionCallExpr) { Set<FunctionPrototype> candidates = declaredFunctions.stream() .filter(proto -> proto.getName().equals(functionCallExpr.getCallee())) .filter(proto -> proto.getNumParameters() == functionCallExpr.getNumArgs()) .collect(Collectors.toSet()); for (int i = 0; i < functionCallExpr.getNumArgs(); i++) { if (!typer.hasType(functionCallExpr.getArg(i))) { // If we don't have a type for this argument, we're OK with any function prototype's type continue; } final int currentIndex = i; // Capture i in final variable so it can be used in lambda. candidates = candidates.stream().filter(proto -> typer.lookupType(functionCallExpr.getArg(currentIndex)).getWithoutQualifiers() .equals(proto.getParameters().get(currentIndex).getType().getWithoutQualifiers())) .collect(Collectors.toSet()); } return candidates; }
private void addGlobalInitializers(FunctionDefinition mainFunction) { assert mainFunction.getPrototype().getName().equals("main"); for (int i = globalsToBeReInitialized.size() - 1; i >= 0; i--) { for (int j = globalsToBeReInitialized.get(i).getNumDecls() - 1; j >= 0; j--) { final VariableDeclInfo vdi = globalsToBeReInitialized.get(i).getDeclInfo(j); if (!(vdi.getInitializer() instanceof ScalarInitializer)) { throw new RuntimeException("Only know how to deal with scalar initializers at present."); } mainFunction.getBody().insertStmt(0, new ExprStmt(new BinaryExpr(new VariableIdentifierExpr(vdi.getName()), ((ScalarInitializer) vdi.getInitializer()).getExpr(), BinOp.ASSIGN))); vdi.setInitializer(null); } } }