Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / XmlUtils / System / Xml / Xsl / IlGen / TailCallAnalyzer.cs / 1 / TailCallAnalyzer.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Diagnostics; using System.Xml.Xsl.Qil; namespace System.Xml.Xsl.IlGen { ////// This analyzer walks each function in the graph and annotates Invoke nodes which can /// be compiled using the IL .tailcall instruction. This instruction will discard the /// current stack frame before calling the new function. /// internal static class TailCallAnalyzer { ////// Perform tail-call analysis on the functions in the specified QilExpression. /// public static void Analyze(QilExpression qil) { foreach (QilFunction ndFunc in qil.FunctionList) { // Only analyze functions which are pushed to the writer, since otherwise code // is generated after the call instruction in order to process cached results if (XmlILConstructInfo.Read(ndFunc).ConstructMethod == XmlILConstructMethod.Writer) AnalyzeDefinition(ndFunc.Definition); } } ////// Recursively analyze the definition of a function. /// private static void AnalyzeDefinition(QilNode nd) { Debug.Assert(XmlILConstructInfo.Read(nd).PushToWriterLast, "Only need to analyze expressions which will be compiled in push mode."); switch (nd.NodeType) { case QilNodeType.Invoke: // Invoke node can either be compiled as IteratorThenWriter, or Writer. // Since IteratorThenWriter involves caching the results of the function call // and iterating over them, .tailcall cannot be used if (XmlILConstructInfo.Read(nd).ConstructMethod == XmlILConstructMethod.Writer) OptimizerPatterns.Write(nd).AddPattern(OptimizerPatternName.TailCall); break; case QilNodeType.Loop: { // Recursively analyze Loop return value QilLoop ndLoop = (QilLoop) nd; if (ndLoop.Variable.NodeType == QilNodeType.Let || !ndLoop.Variable.Binding.XmlType.MaybeMany) AnalyzeDefinition(ndLoop.Body); break; } case QilNodeType.Sequence: { // Recursively analyze last expression in Sequence QilList ndSeq = (QilList) nd; if (ndSeq.Count > 0) AnalyzeDefinition(ndSeq[ndSeq.Count - 1]); break; } case QilNodeType.Choice: { // Recursively analyze Choice branches QilChoice ndChoice = (QilChoice) nd; for (int i = 0; i < ndChoice.Branches.Count; i++) AnalyzeDefinition(ndChoice.Branches[i]); break; } case QilNodeType.Conditional: { // Recursively analyze Conditional branches QilTernary ndCond = (QilTernary) nd; AnalyzeDefinition(ndCond.Center); AnalyzeDefinition(ndCond.Right); break; } case QilNodeType.Nop: AnalyzeDefinition(((QilUnary) nd).Child); break; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Diagnostics; using System.Xml.Xsl.Qil; namespace System.Xml.Xsl.IlGen { ////// This analyzer walks each function in the graph and annotates Invoke nodes which can /// be compiled using the IL .tailcall instruction. This instruction will discard the /// current stack frame before calling the new function. /// internal static class TailCallAnalyzer { ////// Perform tail-call analysis on the functions in the specified QilExpression. /// public static void Analyze(QilExpression qil) { foreach (QilFunction ndFunc in qil.FunctionList) { // Only analyze functions which are pushed to the writer, since otherwise code // is generated after the call instruction in order to process cached results if (XmlILConstructInfo.Read(ndFunc).ConstructMethod == XmlILConstructMethod.Writer) AnalyzeDefinition(ndFunc.Definition); } } ////// Recursively analyze the definition of a function. /// private static void AnalyzeDefinition(QilNode nd) { Debug.Assert(XmlILConstructInfo.Read(nd).PushToWriterLast, "Only need to analyze expressions which will be compiled in push mode."); switch (nd.NodeType) { case QilNodeType.Invoke: // Invoke node can either be compiled as IteratorThenWriter, or Writer. // Since IteratorThenWriter involves caching the results of the function call // and iterating over them, .tailcall cannot be used if (XmlILConstructInfo.Read(nd).ConstructMethod == XmlILConstructMethod.Writer) OptimizerPatterns.Write(nd).AddPattern(OptimizerPatternName.TailCall); break; case QilNodeType.Loop: { // Recursively analyze Loop return value QilLoop ndLoop = (QilLoop) nd; if (ndLoop.Variable.NodeType == QilNodeType.Let || !ndLoop.Variable.Binding.XmlType.MaybeMany) AnalyzeDefinition(ndLoop.Body); break; } case QilNodeType.Sequence: { // Recursively analyze last expression in Sequence QilList ndSeq = (QilList) nd; if (ndSeq.Count > 0) AnalyzeDefinition(ndSeq[ndSeq.Count - 1]); break; } case QilNodeType.Choice: { // Recursively analyze Choice branches QilChoice ndChoice = (QilChoice) nd; for (int i = 0; i < ndChoice.Branches.Count; i++) AnalyzeDefinition(ndChoice.Branches[i]); break; } case QilNodeType.Conditional: { // Recursively analyze Conditional branches QilTernary ndCond = (QilTernary) nd; AnalyzeDefinition(ndCond.Center); AnalyzeDefinition(ndCond.Right); break; } case QilNodeType.Nop: AnalyzeDefinition(((QilUnary) nd).Child); break; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SpellerError.cs
- ActivityUtilities.cs
- TextSelectionProcessor.cs
- JapaneseLunisolarCalendar.cs
- GraphicsPathIterator.cs
- ConfigPathUtility.cs
- XmlnsDictionary.cs
- LicenseException.cs
- SafeBitVector32.cs
- WindowsAuthenticationEventArgs.cs
- DeflateStream.cs
- unitconverter.cs
- AmbientLight.cs
- EntityDataSourceUtil.cs
- SqlProfileProvider.cs
- IndexedWhereQueryOperator.cs
- NeutralResourcesLanguageAttribute.cs
- CacheOutputQuery.cs
- Positioning.cs
- AnnouncementEndpoint.cs
- ComponentChangedEvent.cs
- EntityDataSourceChangedEventArgs.cs
- AssemblyName.cs
- Screen.cs
- XmlDigitalSignatureProcessor.cs
- ElapsedEventArgs.cs
- IpcChannel.cs
- ExecutionPropertyManager.cs
- UInt16Storage.cs
- DecoderReplacementFallback.cs
- ModuleBuilder.cs
- XMLSyntaxException.cs
- CounterSetInstance.cs
- PropertyGeneratedEventArgs.cs
- SelectionService.cs
- SingleObjectCollection.cs
- AQNBuilder.cs
- LoginCancelEventArgs.cs
- RequestSecurityTokenForRemoteTokenFactory.cs
- FormViewInsertedEventArgs.cs
- CommandValueSerializer.cs
- SetIterators.cs
- FacetValues.cs
- SqlNodeTypeOperators.cs
- XmlTextAttribute.cs
- InfoCardRSAPKCS1SignatureFormatter.cs
- ClientSponsor.cs
- XmlCharacterData.cs
- HealthMonitoringSection.cs
- hresults.cs
- xmlsaver.cs
- ImportRequest.cs
- TextSegment.cs
- DropDownButton.cs
- WebBrowserDocumentCompletedEventHandler.cs
- recordstatefactory.cs
- PeerName.cs
- ConcurrentDictionary.cs
- DelegateTypeInfo.cs
- XmlSigningNodeWriter.cs
- TypeHelper.cs
- DispatcherTimer.cs
- TreeNodeStyleCollection.cs
- SourceSwitch.cs
- AQNBuilder.cs
- MenuCommand.cs
- SignatureToken.cs
- ReadWriteObjectLock.cs
- WebServiceFaultDesigner.cs
- InteropBitmapSource.cs
- BrowserCapabilitiesFactory35.cs
- IDictionary.cs
- PropertyManager.cs
- ObjectAnimationUsingKeyFrames.cs
- WmlCommandAdapter.cs
- Soap12ProtocolReflector.cs
- DocumentViewerBase.cs
- LookupBindingPropertiesAttribute.cs
- AutoGeneratedField.cs
- TableRow.cs
- SessionSymmetricTransportSecurityProtocolFactory.cs
- DataRecord.cs
- PKCS1MaskGenerationMethod.cs
- ProcessInputEventArgs.cs
- XmlConvert.cs
- ProgramNode.cs
- TriggerActionCollection.cs
- KeyTimeConverter.cs
- CacheSection.cs
- ScriptingRoleServiceSection.cs
- GACIdentityPermission.cs
- ThrowHelper.cs
- TileModeValidation.cs
- MethodSignatureGenerator.cs
- RowUpdatingEventArgs.cs
- ErrorsHelper.cs
- DynamicDataResources.Designer.cs
- TargetConverter.cs
- ComponentDispatcher.cs
- TableItemPatternIdentifiers.cs