1 /******************************************************************************
3 * Module Name: aslopt- Compiler optimizations
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
118 #include "aslcompiler.h"
119 #include "aslcompiler.y.h"
121 #include "acparser.h"
123 #include "acnamesp.h"
126 #define _COMPONENT ACPI_COMPILER
127 ACPI_MODULE_NAME ("aslopt")
133 /*******************************************************************************
135 * FUNCTION: OptSearchToRoot
137 * PARAMETERS: Op - Current parser op
138 * WalkState - Current state
139 * CurrentNode - Where we are in the namespace
140 * TargetNode - Node to which we are referring
141 * TargetPath - External full path to the target node
142 * NewPath - Where the optimized path is returned
146 * DESCRIPTION: Attempt to optimize a reference to a single 4-character ACPI
147 * name utilizing the search-to-root name resolution algorithm
148 * that is used by AML interpreters.
150 ******************************************************************************/
154 ACPI_PARSE_OBJECT *Op,
155 ACPI_WALK_STATE *WalkState,
156 ACPI_NAMESPACE_NODE *CurrentNode,
157 ACPI_NAMESPACE_NODE *TargetNode,
158 ACPI_BUFFER *TargetPath,
161 ACPI_NAMESPACE_NODE *Node;
162 ACPI_GENERIC_STATE ScopeInfo;
167 ACPI_FUNCTION_NAME ("OptSearchToRoot");
171 * Check if search-to-root can be utilized. Use the last NameSeg of
172 * the NamePath and 1) See if can be found and 2) If found, make
173 * sure that it is the same node that we want. If there is another
174 * name in the search path before the one we want, the nodes will
175 * not match, and we cannot use this optimization.
177 Path = &(((char *) TargetPath->Pointer)[TargetPath->Length - ACPI_NAME_SIZE]),
178 ScopeInfo.Scope.Node = CurrentNode;
180 /* Lookup the NameSeg using SEARCH_PARENT (search-to-root) */
182 Status = AcpiNsLookup (&ScopeInfo, Path, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
183 ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
185 if (ACPI_FAILURE (Status))
191 * We found the name, but we must check to make sure that the node
192 * matches. Otherwise, there is another identical name in the search
193 * path that precludes the use of this optimization.
195 if (Node != TargetNode)
198 * This means that another object with the same name was found first,
199 * and we cannot use this optimization.
201 return (AE_NOT_FOUND);
204 /* Found the node, we can use this optimization */
206 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
207 "NAMESEG: %-24s", Path));
209 /* We must allocate a new string for the name (TargetPath gets deleted) */
211 *NewPath = ACPI_MEM_CALLOCATE (ACPI_NAME_SIZE + 1);
212 ACPI_STRCPY (*NewPath, Path);
214 if (ACPI_STRNCMP (*NewPath, "_T_", 3))
216 AslError (ASL_OPTIMIZATION, ASL_MSG_SINGLE_NAME_OPTIMIZATION, Op,
224 /*******************************************************************************
226 * FUNCTION: OptBuildShortestPath
228 * PARAMETERS: Op - Current parser op
229 * WalkState - Current state
230 * CurrentNode - Where we are in the namespace
231 * TargetNode - Node to which we are referring
232 * CurrentPath - External full path to the current node
233 * TargetPath - External full path to the target node
234 * AmlNameStringLength - Length of the original namepath
235 * IsDeclaration - TRUE for declaration, FALSE for reference
236 * ReturnNewPath - Where the optimized path is returned
240 * DESCRIPTION: Build an optimal NamePath using carats
242 ******************************************************************************/
245 OptBuildShortestPath (
246 ACPI_PARSE_OBJECT *Op,
247 ACPI_WALK_STATE *WalkState,
248 ACPI_NAMESPACE_NODE *CurrentNode,
249 ACPI_NAMESPACE_NODE *TargetNode,
250 ACPI_BUFFER *CurrentPath,
251 ACPI_BUFFER *TargetPath,
252 ACPI_SIZE AmlNameStringLength,
254 char **ReturnNewPath)
256 UINT32 NumCommonSegments;
257 UINT32 MaxCommonSegments;
258 ACPI_NATIVE_UINT Index;
262 char *NewPathExternal;
263 ACPI_NAMESPACE_NODE *Node;
264 ACPI_GENERIC_STATE ScopeInfo;
266 BOOLEAN SubPath = FALSE;
269 ACPI_FUNCTION_NAME ("OptBuildShortestPath");
272 ScopeInfo.Scope.Node = CurrentNode;
275 * Determine the maximum number of NameSegs that the Target and Current paths
276 * can possibly have in common. (To optimize, we have to have at least 1)
278 * Note: The external NamePath string lengths are always a multiple of 5
279 * (ACPI_NAME_SIZE + separator)
281 MaxCommonSegments = TargetPath->Length / ACPI_PATH_SEGMENT_LENGTH;
282 if (CurrentPath->Length < TargetPath->Length)
284 MaxCommonSegments = CurrentPath->Length / ACPI_PATH_SEGMENT_LENGTH;
288 * Determine how many NameSegs the two paths have in common.
289 * (Starting from the root)
291 for (NumCommonSegments = 0;
292 NumCommonSegments < MaxCommonSegments;
295 /* Compare two single NameSegs */
298 &((char *) TargetPath->Pointer)[(NumCommonSegments * ACPI_PATH_SEGMENT_LENGTH) + 1],
299 &((char *) CurrentPath->Pointer)[(NumCommonSegments * ACPI_PATH_SEGMENT_LENGTH) + 1],
308 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " COMMON: %d", NumCommonSegments));
310 /* There must be at least 1 common NameSeg in order to optimize */
312 if (NumCommonSegments == 0)
314 return (AE_NOT_FOUND);
317 if (NumCommonSegments == MaxCommonSegments)
319 if (CurrentPath->Length == TargetPath->Length)
321 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " SAME PATH"));
322 return (AE_NOT_FOUND);
326 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " SUBPATH"));
331 /* Determine how many prefix Carats are required */
333 NumCarats = (CurrentPath->Length / ACPI_PATH_SEGMENT_LENGTH) - NumCommonSegments;
336 * Construct a new target string
338 NewPathExternal = ACPI_MEM_CALLOCATE (TargetPath->Length + NumCarats);
340 /* Insert the Carats into the Target string */
342 for (i = 0; i < NumCarats; i++)
344 NewPathExternal[i] = '^';
347 /* Copy only the necessary (optimal) segments from the original target string */
349 Index = (NumCommonSegments * ACPI_PATH_SEGMENT_LENGTH) + 1;
351 /* Special handling for exact subpath in a name declaration */
353 if (IsDeclaration && SubPath && (CurrentPath->Length > TargetPath->Length))
356 * The current path is longer than the target, and the target is a subpath
357 * of the current path. We must include one more NameSeg of the target path
359 Index -= ACPI_PATH_SEGMENT_LENGTH;
361 /* Special handling for Scope() operator */
363 if (Op->Asl.AmlOpcode == AML_SCOPE_OP)
365 NewPathExternal[i] = '^';
367 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "(EXTRA ^)"));
371 ACPI_STRCPY (&NewPathExternal[i], &((char *) TargetPath->Pointer)[Index]);
372 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " %-24s", NewPathExternal));
375 * Internalize the new target string and check it against the original string
376 * to make sure that this is in fact an optimization. If the original string
377 * is already optimal, there is no point in continuing.
379 Status = AcpiNsInternalizeName (NewPathExternal, &NewPath);
381 if (ACPI_FAILURE (Status))
383 AslCoreSubsystemError (Op, Status, "Internalizing new NamePath", ASL_NO_ABORT);
384 ACPI_MEM_FREE (NewPathExternal);
388 if (ACPI_STRLEN (NewPath) >= AmlNameStringLength)
390 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " NOT SHORTER (New %d old %d)",
391 ACPI_STRLEN (NewPath), AmlNameStringLength));
392 ACPI_MEM_FREE (NewPathExternal);
393 return (AE_NOT_FOUND);
397 * Check to make sure that the optimization finds the node we are
398 * looking for. This is simply a sanity check on the new
399 * path that has been created.
401 Status = AcpiNsLookup (&ScopeInfo, NewPath,
402 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
403 ACPI_NS_DONT_OPEN_SCOPE, WalkState, &(Node));
404 if (ACPI_SUCCESS (Status))
406 /* Found the namepath, but make sure the node is correct */
408 if (Node == TargetNode)
410 /* The lookup matched the node, accept this optimization */
412 AslError (ASL_OPTIMIZATION, ASL_MSG_NAME_OPTIMIZATION,
413 Op, NewPathExternal);
414 *ReturnNewPath = NewPath;
418 /* Node is not correct, do not use this optimization */
420 Status = AE_NOT_FOUND;
421 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ***** WRONG NODE"));
422 AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
423 "Not using optimized name - found wrong node");
428 /* The lookup failed, we obviously cannot use this optimization */
430 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ***** NOT FOUND"));
431 AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
432 "Not using optimized name - did not find node");
435 ACPI_MEM_FREE (NewPathExternal);
440 /*******************************************************************************
442 * FUNCTION: OptOptimizeNameDeclaration
444 * PARAMETERS: Op - Current parser op
445 * WalkState - Current state
446 * CurrentNode - Where we are in the namespace
447 * AmlNameString - Unoptimized namepath
448 * NewPath - Where the optimized path is returned
450 * RETURN: Status. AE_OK If path is optimized
452 * DESCRIPTION: Perform a simple optimization of removing an extraneous
453 * backslash prefix if we are already at the root scope.
455 ******************************************************************************/
458 OptOptimizeNameDeclaration (
459 ACPI_PARSE_OBJECT *Op,
460 ACPI_WALK_STATE *WalkState,
461 ACPI_NAMESPACE_NODE *CurrentNode,
462 ACPI_NAMESPACE_NODE *TargetNode,
467 char *NewPathExternal;
468 ACPI_GENERIC_STATE ScopeInfo;
469 ACPI_NAMESPACE_NODE *Node;
472 ACPI_FUNCTION_TRACE ("OptOptimizeNameDeclaration");
475 if (((CurrentNode == AcpiGbl_RootNode) ||
476 (Op->Common.Parent->Asl.ParseOpcode == PARSEOP_DEFINITIONBLOCK)) &&
477 (AmlNameString[0] == '\\'))
480 * The current scope is the root, and the namepath has a root prefix
481 * that is therefore extraneous. Remove it.
483 *NewPath = &AmlNameString[1];
487 Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, *NewPath,
488 NULL, &NewPathExternal);
489 if (ACPI_FAILURE (Status))
491 AslCoreSubsystemError (Op, Status, "Externalizing NamePath", ASL_NO_ABORT);
496 * Check to make sure that the optimization finds the node we are
497 * looking for. This is simply a sanity check on the new
498 * path that has been created.
500 ScopeInfo.Scope.Node = CurrentNode;
501 Status = AcpiNsLookup (&ScopeInfo, *NewPath,
502 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
503 ACPI_NS_DONT_OPEN_SCOPE, WalkState, &(Node));
504 if (ACPI_SUCCESS (Status))
506 /* Found the namepath, but make sure the node is correct */
508 if (Node == TargetNode)
510 /* The lookup matched the node, accept this optimization */
512 AslError (ASL_OPTIMIZATION, ASL_MSG_NAME_OPTIMIZATION,
513 Op, NewPathExternal);
515 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
516 "AT ROOT: %-24s", NewPathExternal));
520 /* Node is not correct, do not use this optimization */
522 Status = AE_NOT_FOUND;
523 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ***** WRONG NODE"));
524 AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
525 "Not using optimized name - found wrong node");
530 /* The lookup failed, we obviously cannot use this optimization */
532 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ***** NOT FOUND"));
533 AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
534 "Not using optimized name - did not find node");
537 ACPI_MEM_FREE (NewPathExternal);
541 /* Could not optimize */
543 return (AE_NOT_FOUND);
547 /*******************************************************************************
549 * FUNCTION: OptOptimizeNamePath
551 * PARAMETERS: Op - Current parser op
552 * Flags - Opcode info flags
553 * WalkState - Current state
554 * AmlNameString - Unoptimized namepath
555 * TargetNode - Node to which AmlNameString refers
557 * RETURN: None. If path is optimized, the Op is updated with new path
559 * DESCRIPTION: Optimize a Named Declaration or Reference to the minimal length.
560 * Must take into account both the current location in the
561 * namespace and the actual reference path.
563 ******************************************************************************/
566 OptOptimizeNamePath (
567 ACPI_PARSE_OBJECT *Op,
569 ACPI_WALK_STATE *WalkState,
571 ACPI_NAMESPACE_NODE *TargetNode)
574 ACPI_BUFFER TargetPath;
575 ACPI_BUFFER CurrentPath;
576 ACPI_SIZE AmlNameStringLength;
577 ACPI_NAMESPACE_NODE *CurrentNode;
578 char *ExternalNameString;
579 char *NewPath = NULL;
580 ACPI_SIZE HowMuchShorter;
581 ACPI_PARSE_OBJECT *NextOp;
584 ACPI_FUNCTION_TRACE ("OptOptimizeNamePath");
587 /* This is an optional optimization */
589 if (!Gbl_ReferenceOptimizationFlag)
594 /* Various required items */
596 if (!TargetNode || !WalkState || !AmlNameString || !Op->Common.Parent)
601 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "%5d [%12.12s] [%12.12s] ",
602 Op->Asl.LogicalLineNumber,
603 AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode),
604 AcpiPsGetOpcodeName (Op->Common.AmlOpcode)));
606 if (!(Flags & (AML_NAMED | AML_CREATE)))
608 if (Op->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)
610 /* We don't want to fuss with actual name declaration nodes here */
612 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
613 "******* NAME DECLARATION\n"));
619 * The original path must be longer than one NameSeg (4 chars) for there
620 * to be any possibility that it can be optimized to a shorter string
622 AmlNameStringLength = ACPI_STRLEN (AmlNameString);
623 if (AmlNameStringLength <= ACPI_NAME_SIZE)
625 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
626 "NAMESEG %4.4s\n", AmlNameString));
631 * We need to obtain the node that represents the current scope -- where
632 * we are right now in the namespace. We will compare this path
633 * against the Namepath, looking for commonality.
635 CurrentNode = AcpiGbl_RootNode;
636 if (WalkState->ScopeInfo)
638 CurrentNode = WalkState->ScopeInfo->Scope.Node;
641 if (Flags & (AML_NAMED | AML_CREATE))
643 /* This is the declaration of a new name */
645 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "NAME"));
647 /* The node of interest is the parent of this node (the containing scope) */
649 CurrentNode = Op->Asl.Parent->Asl.Node;
652 CurrentNode = AcpiGbl_RootNode;
657 /* This is a reference to an existing named object */
659 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "REF "));
663 * Obtain the full paths to the two nodes that we are interested in
664 * (Target and current namespace location) in external
665 * format -- something we can easily manipulate
667 TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
668 Status = AcpiNsHandleToPathname (TargetNode, &TargetPath);
669 if (ACPI_FAILURE (Status))
671 AslCoreSubsystemError (Op, Status, "Getting Target NamePath", ASL_NO_ABORT);
674 TargetPath.Length--; /* Subtract one for null terminator */
676 /* CurrentPath is the path to this scope (where we are in the namespace) */
678 CurrentPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
679 Status = AcpiNsHandleToPathname (CurrentNode, &CurrentPath);
680 if (ACPI_FAILURE (Status))
682 AslCoreSubsystemError (Op, Status, "Getting Current NamePath", ASL_NO_ABORT);
685 CurrentPath.Length--; /* Subtract one for null terminator */
687 /* Debug output only */
689 Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, AmlNameString,
690 NULL, &ExternalNameString);
691 if (ACPI_FAILURE (Status))
693 AslCoreSubsystemError (Op, Status, "Externalizing NamePath", ASL_NO_ABORT);
697 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
698 "%37s (%2d) ==> %-32s(%2d) %-32s",
699 (char *) CurrentPath.Pointer, CurrentPath.Length,
700 (char *) TargetPath.Pointer, TargetPath.Length, ExternalNameString));
702 ACPI_MEM_FREE (ExternalNameString);
705 * Attempt an optmization depending on the type of namepath
707 if (Flags & (AML_NAMED | AML_CREATE))
710 * This is a named opcode and the namepath is a name declaration, not
713 Status = OptOptimizeNameDeclaration (Op, WalkState, CurrentNode,
714 TargetNode, AmlNameString, &NewPath);
715 if (ACPI_FAILURE (Status))
719 * optimize the namestring with carats (up-arrow)
721 Status = OptBuildShortestPath (Op, WalkState, CurrentNode,
722 TargetNode, &CurrentPath, &TargetPath,
723 AmlNameStringLength, 1, &NewPath);
729 * This is a reference to an existing named object
731 * 1) Check if search-to-root can be utilized using the last
732 * NameSeg of the NamePath
734 Status = OptSearchToRoot (Op, WalkState, CurrentNode,
735 TargetNode, &TargetPath, &NewPath);
736 if (ACPI_FAILURE (Status))
739 * 2) Search-to-root could not be used, now attempt to
740 * optimize the namestring with carats (up-arrow)
742 Status = OptBuildShortestPath (Op, WalkState, CurrentNode,
743 TargetNode, &CurrentPath, &TargetPath,
744 AmlNameStringLength, 0, &NewPath);
749 * Success from above indicates that the NamePath was successfully
750 * optimized. We need to update the parse op with the new name
752 if (ACPI_SUCCESS (Status))
754 HowMuchShorter = (AmlNameStringLength - ACPI_STRLEN (NewPath));
755 OptTotal += HowMuchShorter;
757 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " REDUCED %2d (%d)",
758 HowMuchShorter, OptTotal));
760 if (Flags & AML_NAMED)
762 if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
765 * ALIAS is the only oddball opcode, the name declaration
766 * (alias name) is the second operand
768 Op->Asl.Child->Asl.Next->Asl.Value.String = NewPath;
769 Op->Asl.Child->Asl.Next->Asl.AmlLength = ACPI_STRLEN (NewPath);
773 Op->Asl.Child->Asl.Value.String = NewPath;
774 Op->Asl.Child->Asl.AmlLength = ACPI_STRLEN (NewPath);
777 else if (Flags & AML_CREATE)
779 /* Name must appear as the last parameter */
781 NextOp = Op->Asl.Child;
782 while (!(NextOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
784 NextOp = NextOp->Asl.Next;
786 /* Update the parse node with the new NamePath */
788 NextOp->Asl.Value.String = NewPath;
789 NextOp->Asl.AmlLength = ACPI_STRLEN (NewPath);
793 /* Update the parse node with the new NamePath */
795 Op->Asl.Value.String = NewPath;
796 Op->Asl.AmlLength = ACPI_STRLEN (NewPath);
801 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ALREADY OPTIMAL"));
804 /* Cleanup path buffers */
806 ACPI_MEM_FREE (TargetPath.Pointer);
807 ACPI_MEM_FREE (CurrentPath.Pointer);
809 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "\n"));