public class Optimizer
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected Configuration |
config |
static int |
FULL_OPTIMIZATION |
static int |
NO_OPTIMIZATION |
protected boolean |
tracing |
Constructor and Description |
---|
Optimizer(Configuration config)
Create an Optimizer.
|
Modifier and Type | Method and Description |
---|---|
void |
assessFunctionStreamability(XSLFunction sourceFunction,
UserFunction compiledFunction) |
void |
checkStreamability(XSLTemplate sourceTemplate,
TemplateRule compiledTemplate)
Check the streamability of a template
|
Expression |
compileToByteCode(ICompilerService compilerService,
Expression expr,
java.lang.String objectName,
int evaluationMethods)
Generate Java byte code for an expression
|
Expression |
convertPathExpressionToKey(SlashExpression pathExp,
ExpressionVisitor visitor)
Examine a path expression to see whether it can be replaced by a call on the key() function;
if so, generate an appropriate key definition and return the call on key().
|
FilterExpression |
convertToFilterExpression(SlashExpression pathExp,
TypeHierarchy th)
Convert a path expression such as a/b/c[predicate] into a filter expression
of the form (a/b/c)[predicate].
|
Expression |
eliminateCommonSubexpressions(Expression in)
Eliminate common subexpressions.
|
Sequence<?> |
evaluateStreamingArgument(Expression expr,
XPathContext context)
Evaluate the streaming (first) argument of a streamable stylesheet function
|
Expression |
generateMultithreadedInstruction(Expression instruction)
Generate a multi-threaded version of an instruction.
|
Configuration |
getConfiguration()
Get the Saxon configuration object
|
OptimizerOptions |
getOptimizerOptions()
Get the optimizer options
|
void |
injectByteCodeCandidates(Expression exp) |
int |
isIndexableFilter(Expression filter)
Test whether a filter predicate is indexable.
|
boolean |
isOptionSet(int option)
Ask whether a particular optimizer option is set
|
boolean |
isVariableReplaceableByDot(Expression exp,
Binding[] binding)
Determine whether it is possible to rearrange an expression so that all references to a given
variable are replaced by a reference to ".".
|
Expression |
makeByteCodeCandidate(ExpressionOwner owner,
Expression expr,
java.lang.String objectName,
int requiredEvaluationModes)
Insert a ByteCodeCandidate into the expression tree.
|
Expression |
makeConditionalDocumentSorter(DocumentSorter sorter,
SlashExpression path)
Make a conditional document sorter.
|
void |
makeCopyOperationsExplicit(Expression parent,
Operand child)
In streaming mode, make the copy operation applied to subexpressions of a complex-content
sequence constructor into explicit copy-of operations.
|
<T extends Item<?>> |
makeIndexedValue(SequenceIterator<? extends T> iter)
Create an indexed value
|
RuleTarget |
makeInversion(Pattern pattern,
NamedTemplate template)
Generate the inversion of the expression comprising the body of a template rules.
|
Expression |
optimizeForExpressionForStreaming(ForExpression expr)
In streaming mode, optimizer a ForExpression for streaming
|
Expression |
optimizeGeneralComparison(ExpressionVisitor visitor,
GeneralComparison gc,
boolean backwardsCompatible,
ContextItemStaticInfo contextItemType)
Simplify a GeneralComparison expression
|
Expression |
optimizeNumberInstruction(NumberInstruction ni,
ContextItemStaticInfo contextInfo) |
Expression |
optimizeQuantifiedExpressionForStreaming(QuantifiedExpression expr)
In streaming mode, optimizer a QuantifiedExpression for streaming
|
Expression |
optimizeSaxonStreamFunction(ExpressionVisitor visitor,
ContextItemStaticInfo cisi,
Expression select)
Attempt to optimize a call on saxon:stream().
|
void |
prepareForStreaming(Expression exp)
Prepare an expression for streaming
|
Expression |
promoteExpressionsToGlobal(Expression body,
GlobalVariableManager gvManager,
ExpressionVisitor visitor)
Identify expressions within a function or template body that can be promoted to be
evaluated as global variables.
|
Expression |
reorderPredicates(FilterExpression f,
ExpressionVisitor visitor,
ContextItemStaticInfo cisi)
Consider reordering the predicates in a filter expression based on cost estimates
|
void |
setOptimizerOptions(OptimizerOptions options)
Set the optimizer options
|
static void |
trace(Configuration config,
java.lang.String message,
Expression exp) |
void |
trace(java.lang.String message,
Expression exp)
Trace optimization actions
|
Expression |
tryGeneralComparison(ExpressionVisitor visitor,
ContextItemStaticInfo contextItemType,
OrExpression orExpr)
Try to convert an Or expression into a comparison with Literal sequence
|
Expression |
tryIndexedFilter(FilterExpression f,
ExpressionVisitor visitor,
boolean indexFirstOperand,
boolean contextIsDoc)
Try converting a filter expression to a call on the key function.
|
Expression |
tryInlineFunctionCall(UserFunctionCall functionCall,
ExpressionVisitor visitor,
ContextItemStaticInfo contextItemType)
Replace a function call by the body of the function, assuming all conditions for inlining
the function are satisfied
|
Expression |
trySwitch(Choose choose,
ExpressionVisitor visitor)
Try to convert a Choose expression into a switch
|
public static final int NO_OPTIMIZATION
public static final int FULL_OPTIMIZATION
protected Configuration config
protected boolean tracing
public Optimizer(Configuration config)
config
- the Saxon configurationpublic Configuration getConfiguration()
public void setOptimizerOptions(OptimizerOptions options)
options
- the optimizer optionspublic OptimizerOptions getOptimizerOptions()
public boolean isOptionSet(int option)
option
- the code identifying the option, e.g. OptimizerOptions.BYTE_CODE
public Expression optimizeGeneralComparison(ExpressionVisitor visitor, GeneralComparison gc, boolean backwardsCompatible, ContextItemStaticInfo contextItemType)
visitor
- the expression visitorgc
- the GeneralComparison to be simplifiedbackwardsCompatible
- true if in 1.0 compatibility modepublic Expression optimizeSaxonStreamFunction(ExpressionVisitor visitor, ContextItemStaticInfo cisi, Expression select) throws XPathException
select
- the expression that selects the items to be copiedXPathException
public Expression convertPathExpressionToKey(SlashExpression pathExp, ExpressionVisitor visitor) throws XPathException
pathExp
- The path expression to be converted.visitor
- The expression visitorXPathException
public Expression tryIndexedFilter(FilterExpression f, ExpressionVisitor visitor, boolean indexFirstOperand, boolean contextIsDoc)
f
- the filter expression to be convertedvisitor
- the expression visitor, which must be currently visiting the filter expression findexFirstOperand
- true if the first operand of the filter comparison is to be indexed;
false if it is the second operandcontextIsDoc
- true if the context item is known to be a document nodepublic Expression reorderPredicates(FilterExpression f, ExpressionVisitor visitor, ContextItemStaticInfo cisi) throws XPathException
f
- the filter expression (which is known to have more than one predicate)visitor
- expression visitorcisi
- information about the context item typeXPathException
- if things go wrongpublic FilterExpression convertToFilterExpression(SlashExpression pathExp, TypeHierarchy th) throws XPathException
pathExp
- the path expression to be convertedth
- the type hierarchy cacheXPathException
public int isIndexableFilter(Expression filter)
filter
- the predicate expressionpublic <T extends Item<?>> GroundedValue<T> makeIndexedValue(SequenceIterator<? extends T> iter) throws XPathException
iter
- the iterator that delivers the sequence of values to be indexedUnsupportedOperationException:
- this method should not be called in Saxon-HEXPathException
public void prepareForStreaming(Expression exp) throws XPathException
exp
- the expression to be preparedXPathException
public Sequence<?> evaluateStreamingArgument(Expression expr, XPathContext context) throws XPathException
expr
- the expression supplied for the value of the streaming argumentcontext
- the XPath evaluation context of the callerXPathException
public boolean isVariableReplaceableByDot(Expression exp, Binding[] binding)
exp
- the expression in questionbinding
- an array of bindings defining range variables; the method tests that there are no
references to any of these variables within a predicate or on the rhs of "/"public Expression makeConditionalDocumentSorter(DocumentSorter sorter, SlashExpression path) throws XPathException
sorter
- the document sorterpath
- the path expressionXPathException
public Expression tryInlineFunctionCall(UserFunctionCall functionCall, ExpressionVisitor visitor, ContextItemStaticInfo contextItemType)
functionCall
- the functionCall expressionvisitor
- the expression visitorcontextItemType
- the context item typepublic Expression promoteExpressionsToGlobal(Expression body, GlobalVariableManager gvManager, ExpressionVisitor visitor) throws XPathException
body
- the body of the template or functionvisitor
- the expression visitorXPathException
public Expression eliminateCommonSubexpressions(Expression in)
in
- the expression to be optimizedpublic Expression trySwitch(Choose choose, ExpressionVisitor visitor)
choose
- the Choose expressionpublic Expression tryGeneralComparison(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType, OrExpression orExpr) throws XPathException
visitor
- an expression visitorcontextItemType
- the static type of "." at the point where this expression is invoked.
The parameter is set to null if it is known statically that the context item will be undefined.
If the type of the context item is not known statically, the argument is set to
Type.ITEM_TYPE
orExpr
- the expression to be convertedXPathException
public RuleTarget makeInversion(Pattern pattern, NamedTemplate template) throws XPathException
pattern
- the match pattern of this template ruletemplate
- the template to be invertedXPathException
public void makeCopyOperationsExplicit(Expression parent, Operand child) throws XPathException
XPathException
public void checkStreamability(XSLTemplate sourceTemplate, TemplateRule compiledTemplate) throws XPathException
sourceTemplate
- the source of the template in the stylesheet treecompiledTemplate
- the compiled templateXPathException
- if the template is declared streamable but does not satisfy the straming rulespublic Expression optimizeForExpressionForStreaming(ForExpression expr) throws XPathException
expr
- the expression to be optimizedXPathException
public Expression optimizeQuantifiedExpressionForStreaming(QuantifiedExpression expr) throws XPathException
expr
- the expression to be optimizedXPathException
public Expression generateMultithreadedInstruction(Expression instruction)
instruction
- the instruction to be multi-threadedpublic Expression compileToByteCode(ICompilerService compilerService, Expression expr, java.lang.String objectName, int evaluationMethods)
compilerService
- expr
- the expression to be compiledobjectName
- the name of the object (e.g. function) being compiledevaluationMethods
- The evaluation modes for which code is generated. Currently a subset of
Expression.PROCESS_METHOD
, Expression.ITERATE_METHOD
. If no code is generated forpublic Expression makeByteCodeCandidate(ExpressionOwner owner, Expression expr, java.lang.String objectName, int requiredEvaluationModes)
owner
- the owning construct in the expression treeexpr
- the child (target) expressionobjectName
- name to be used in forming the name of the bytecode classrequiredEvaluationModes
- the evaluation modes for which code should be generatedpublic void injectByteCodeCandidates(Expression exp) throws XPathException
XPathException
public Expression optimizeNumberInstruction(NumberInstruction ni, ContextItemStaticInfo contextInfo)
public void assessFunctionStreamability(XSLFunction sourceFunction, UserFunction compiledFunction) throws XPathException
XPathException
public void trace(java.lang.String message, Expression exp)
message
- the message to be displayedexp
- the expression after being rewrittenpublic static void trace(Configuration config, java.lang.String message, Expression exp)
Copyright (c) 2004-2020 Saxonica Limited. All rights reserved.