Restructured aslopt, first pass

date	2002.08.23.22.50.00;	author rmoore1;	state Exp;
This commit is contained in:
aystarik 2005-06-29 16:08:10 +00:00
parent 64fcabb3e1
commit 8af47c4246

View File

@ -1,7 +1,7 @@
/******************************************************************************
*
* Module Name: aslopt- Compiler optimizations
* $Revision: 1.2 $
* $Revision: 1.3 $
*
*****************************************************************************/
@ -129,9 +129,363 @@
UINT32 OptTotal = 0;
/*******************************************************************************
*
* FUNCTION: LkOptimizeNamedReference
* FUNCTION: LkSearchToRoot
*
* PARAMETERS: Op - Current parser op
* WalkState - Current state
* AmlNameString - Unoptimized namepath
* TargetNode - Node to which AmlNameString refers
*
* RETURN: Status
*
* DESCRIPTION:
*
******************************************************************************/
ACPI_STATUS
LkSearchToRoot (
ACPI_PARSE_OBJECT *Op,
ACPI_WALK_STATE *WalkState,
ACPI_NAMESPACE_NODE *CurrentNode,
ACPI_NAMESPACE_NODE *TargetNode,
ACPI_BUFFER *TargetPath,
char **NewPath)
{
ACPI_NAMESPACE_NODE *Node;
ACPI_GENERIC_STATE ScopeInfo;
ACPI_STATUS Status;
char *Path;
ACPI_FUNCTION_NAME ("LkSearchToRoot");
/*
* Check if search-to-root can be utilized. Use the last NameSeg of
* the NamePath and 1) See if can be found and 2) If found, make
* sure that it is the same node that we want. If there is another
* name in the search path before the one we want, the nodes will
* not match, and we cannot use this optimization.
*/
Path = &(((NATIVE_CHAR *) TargetPath->Pointer)[TargetPath->Length - ACPI_NAME_SIZE]),
ScopeInfo.Scope.Node = CurrentNode;
/* Lookup the NameSeg using SEARCH_PARENT (search-to-root) */
Status = AcpiNsLookup (&ScopeInfo, Path, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
WalkState, &(Node));
if (ACPI_FAILURE (Status))
{
return (Status);
}
/*
* We found the name, but we must check to make sure that the node
* matches. Otherwise, there is another identical name in the search
* path that precludes the use of this optimization.
*/
if (Node != TargetNode)
{
/*
* This means that another object with the same name was found first,
* and we cannot use this optimization.
*/
return (AE_NOT_FOUND);
}
/* Found the node, we can use this optimization */
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
"NAMESEG: %-24s", Path));
/* We must allocate a new string for the name (TargetPath gets deleted) */
*NewPath = ACPI_MEM_CALLOCATE (ACPI_NAME_SIZE + 1);
ACPI_STRCPY (*NewPath, Path);
AslError (ASL_OPTIMIZATION, ASL_MSG_SINGLE_NAME_OPTIMIZATION, Op,
*NewPath);
return (AE_OK);
}
/*******************************************************************************
*
* FUNCTION: LkBuildShortestPath
*
* PARAMETERS: Op - Current parser op
* WalkState - Current state
* AmlNameString - Unoptimized namepath
* TargetNode - Node to which AmlNameString refers
*
* RETURN: Status
*
* DESCRIPTION:
*
******************************************************************************/
ACPI_STATUS
LkBuildShortestPath (
ACPI_PARSE_OBJECT *Op,
ACPI_WALK_STATE *WalkState,
ACPI_NAMESPACE_NODE *CurrentNode,
ACPI_NAMESPACE_NODE *TargetNode,
ACPI_BUFFER *CurrentPath,
ACPI_BUFFER *TargetPath,
ACPI_SIZE AmlNameStringLength,
UINT8 IsDeclaration,
char **ReturnNewPath)
{
UINT32 NumCommonSegments;
UINT32 MaxCommonSegments;
NATIVE_UINT Index;
UINT32 NumCarats;
NATIVE_UINT i;
char *NewPath;
char *NewPathExternal;
ACPI_NAMESPACE_NODE *Node;
ACPI_GENERIC_STATE ScopeInfo;
ACPI_STATUS Status;
BOOLEAN SubPath = FALSE;
ACPI_FUNCTION_NAME ("LkBuildShortestPath");
ScopeInfo.Scope.Node = CurrentNode;
/*
* Determine the maximum number of NameSegs that the Target and Current paths
* can possibly have in common. (To optimize, we have to have at least 1)
*
* Note: The external NamePath string lengths are always a multiple of 5
* (ACPI_NAME_SIZE + separator)
*/
MaxCommonSegments = TargetPath->Length / PATH_SEGMENT_LENGTH;
if (CurrentPath->Length < TargetPath->Length)
{
MaxCommonSegments = CurrentPath->Length / PATH_SEGMENT_LENGTH;
}
/*
* Determine how many NameSegs the two paths have in common.
* (Starting from the root)
*/
for (NumCommonSegments = 0;
NumCommonSegments < MaxCommonSegments;
NumCommonSegments++)
{
/* Compare two single NameSegs */
if (ACPI_STRNCMP (
&((NATIVE_CHAR *) TargetPath->Pointer)[(NumCommonSegments * PATH_SEGMENT_LENGTH) + 1],
&((NATIVE_CHAR *) CurrentPath->Pointer)[(NumCommonSegments * PATH_SEGMENT_LENGTH) + 1],
ACPI_NAME_SIZE))
{
/* Mismatch */
break;
}
}
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " COMMON: %d", NumCommonSegments));
/* There must be at least 1 common NameSeg in order to optimize */
if (NumCommonSegments == 0)
{
return (AE_NOT_FOUND);
}
if (NumCommonSegments == MaxCommonSegments)
{
if (CurrentPath->Length == TargetPath->Length)
{
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " SAME PATH"));
return (AE_NOT_FOUND);
}
else
{
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " SUBPATH"));
SubPath = TRUE;
}
}
/* Determine how many prefix Carats are required */
NumCarats = (CurrentPath->Length / PATH_SEGMENT_LENGTH) - NumCommonSegments;
/*
* Construct a new target string
*/
NewPathExternal = ACPI_MEM_CALLOCATE (TargetPath->Length + NumCarats);
/* Insert the Carats into the Target string */
for (i = 0; i < NumCarats; i++)
{
NewPathExternal[i] = '^';
}
/* Copy only the necessary (optimal) segments from the original target string */
Index = (NumCommonSegments * PATH_SEGMENT_LENGTH) + 1;
/* Special handling for exact subpath in a name declaration */
if (IsDeclaration && SubPath)
{
/* We must include one more NameSeg */
Index -= PATH_SEGMENT_LENGTH;
}
ACPI_STRCPY (&NewPathExternal[i], &((NATIVE_CHAR *) TargetPath->Pointer)[Index]);
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " %-24s", NewPathExternal));
/*
* Internalize the new target string and check it against the original string
* to make sure that this is in fact an optimization. If the original string
* is already optimal, there is no point in continuing.
*/
Status = AcpiNsInternalizeName (NewPathExternal, &NewPath);
ACPI_MEM_FREE (NewPathExternal);
#if 0
if (ACPI_FAILURE (Status))
{
return (Status);
}
#endif
if (ACPI_STRLEN (NewPath) >= AmlNameStringLength)
{
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " NOT SHORTER (New %d old %d)",
ACPI_STRLEN (NewPath), AmlNameStringLength));
return (AE_NOT_FOUND);
}
/*
* Check to make sure that the optimization finds the node we are
* looking for. This is simply a sanity check on the new
* path that has been created.
*/
Status = AcpiNsLookup (&ScopeInfo, NewPath,
ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
ACPI_NS_DONT_OPEN_SCOPE, WalkState, &(Node));
if (ACPI_SUCCESS (Status))
{
/* Found the namepath, but make sure the node is correct */
if (Node == TargetNode)
{
/* The lookup matched the node, accept this optimization */
AslError (ASL_OPTIMIZATION, ASL_MSG_NAME_OPTIMIZATION,
Op, NewPathExternal);
*ReturnNewPath = NewPath;
}
else
{
/* Node is not correct, do not use this optimization */
Status = AE_NOT_FOUND;
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ***** WRONG NODE"));
AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
"Not using optimized name - found wrong node");
}
}
else
{
/* The lookup failed, we obviously cannot use this optimization */
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ***** NOT FOUND"));
AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
"Not using optimized name - did not find node");
}
return (Status);
}
/*******************************************************************************
*
* FUNCTION: LkOptimizeNameDeclaration
*
* PARAMETERS: Op - Current parser op
* WalkState - Current state
* AmlNameString - Unoptimized namepath
* TargetNode - Node to which AmlNameString refers
*
* RETURN: Status. AE_OK If path is optimized
*
* DESCRIPTION:
*
******************************************************************************/
ACPI_STATUS
LkOptimizeNameDeclaration (
ACPI_PARSE_OBJECT *Op,
ACPI_WALK_STATE *WalkState,
ACPI_NAMESPACE_NODE *CurrentNode,
NATIVE_CHAR *AmlNameString,
char **NewPath)
{
ACPI_STATUS Status;
char *ExternalNameString;
ACPI_FUNCTION_TRACE ("LkOptimizeNameDeclaration");
if (((CurrentNode == AcpiGbl_RootNode) ||
(Op->Common.Parent->Asl.ParseOpcode == PARSEOP_DEFINITIONBLOCK)) &&
(AmlNameString[0] == '\\'))
{
/*
* The current scope is the root, and the namepath has a root prefix
* that is therefore extraneous. Remove it.
*/
*NewPath = &AmlNameString[1];
/* Debug output */
Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, *NewPath,
NULL, &ExternalNameString);
if (ACPI_FAILURE (Status))
{
/* TBD: this simply quietly aborts! */
AslAbort ();
}
AslError (ASL_OPTIMIZATION, ASL_MSG_NAME_OPTIMIZATION,
Op, ExternalNameString);
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
"AT ROOT: %-24s", ExternalNameString));
ACPI_MEM_FREE (ExternalNameString);
return (AE_OK);
}
/* Could not optimize */
return (AE_NOT_FOUND);
}
/*******************************************************************************
*
* FUNCTION: LkOptimizeNamePath
*
* PARAMETERS: Op - Current parser op
* WalkState - Current state
@ -140,9 +494,9 @@ UINT32 OptTotal = 0;
*
* RETURN: None. If path is optimized, the Op is updated with new path
*
* DESCRIPTION: Optimize a Named Reference to the minimal length. Must take
* into account both the current location in the namespace and
* the actual reference path.
* DESCRIPTION: Optimize a Named Declaration or Reference to the minimal length.
* Must take into account both the current location in the
* namespace and the actual reference path.
*
******************************************************************************/
@ -157,31 +511,16 @@ LkOptimizeNamePath (
ACPI_STATUS Status;
ACPI_BUFFER TargetPath;
ACPI_BUFFER CurrentPath;
ACPI_SIZE TargetPathLength;
ACPI_SIZE CurrentPathLength;
ACPI_SIZE AmlNameStringLength;
UINT32 NumCommonSegments;
UINT32 MaxCommonSegments;
ACPI_NAMESPACE_NODE *CurrentNode;
ACPI_NAMESPACE_NODE *Node = NULL;
char *ExternalNameString;
char *NewPath = NULL;
char *NewPathExternal;
UINT32 OptCount = 0;
NATIVE_UINT Index;
UINT32 NumCarats;
NATIVE_UINT i;
ACPI_GENERIC_STATE ScopeInfo;
ACPI_SIZE HowMuchShorter;
ACPI_FUNCTION_TRACE ("LkOptimizeNamedReference");
ACPI_FUNCTION_TRACE ("LkOptimizeNamePath");
#if 0
if (Flags & AML_NAMED)
{
return_VOID;
}
#endif
/* This is an optional optimization */
if (!Gbl_ReferenceOptimizationFlag)
@ -196,8 +535,6 @@ LkOptimizeNamePath (
return_VOID;
}
/* We don't want to optimize paths for certain opcodes */
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "%5d [%12.12s] [%12.12s] ",
Op->Asl.LogicalLineNumber,
AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode),
@ -205,12 +542,13 @@ LkOptimizeNamePath (
if (!(Flags & (AML_NAMED | AML_CREATE)))
{
/* We don't want to fuss with actual name declaration nodes here */
if (Op->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)
{
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "******* NAME DECLARATION"));
goto Exit;
/* We don't want to fuss with actual name declaration nodes here */
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
"******* NAME DECLARATION\n"));
return_VOID;
}
}
@ -221,48 +559,56 @@ LkOptimizeNamePath (
AmlNameStringLength = ACPI_STRLEN (AmlNameString);
if (AmlNameStringLength <= ACPI_NAME_SIZE)
{
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "NAMESEG %4.4s", AmlNameString));
goto Exit;
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
"NAMESEG %4.4s\n", AmlNameString));
return_VOID;
}
/*
* We need the node that represents the current scope -- where
* we are now in the namespace
* We need to obtain the node that represents the current scope -- where
* we are right now in the namespace. We will compare this path
* against the Namepath, looking for commonality.
*/
CurrentNode = AcpiGbl_RootNode;
if (WalkState->ScopeInfo)
{
CurrentNode = WalkState->ScopeInfo->Scope.Node;
}
if (Flags & (AML_NAMED | AML_CREATE))
{
/* This is the declaration of a new name */
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "NAME"));
#if 0
if (WalkState->ScopeInfo)
{
if (AcpiNsOpensScope (TargetNode->Type))
{
/* The target has opened a scope, so we need to backup to the parent */
CurrentNode = AcpiNsGetParentNode (WalkState->ScopeInfo->Scope.Node);
}
else
{
CurrentNode = WalkState->ScopeInfo->Scope.Node;
}
}
#endif
CurrentNode = Op->Asl.Parent->Asl.Node;
if (!CurrentNode)
{
CurrentNode = AcpiGbl_RootNode;
}
}
else
{
/* This is a reference to an existing named object */
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "REF "));
if (WalkState->ScopeInfo)
{
CurrentNode = WalkState->ScopeInfo->Scope.Node;
}
}
ScopeInfo.Scope.Node = CurrentNode;
/*
* Convert the namestrings (Target and current namespace location) to
* external format -- something we can easily manipulate
* Obtain the full paths to the two nodes that we are interested in
* (Target and current namespace location) in external
* format -- something we can easily manipulate
*/
TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
Status = AcpiNsHandleToPathname (TargetNode, &TargetPath);
@ -270,7 +616,7 @@ LkOptimizeNamePath (
{
AslAbort ();
}
TargetPathLength = ACPI_STRLEN (TargetPath.Pointer);
TargetPath.Length--; /* Subtract one for null terminator */
/* CurrentPath is the path to this scope (where we are in the namespace) */
@ -280,7 +626,7 @@ LkOptimizeNamePath (
{
AslAbort ();
}
CurrentPathLength = ACPI_STRLEN (CurrentPath.Pointer);
CurrentPath.Length--; /* Subtract one for null terminator */
/* Debug output only */
@ -293,213 +639,65 @@ LkOptimizeNamePath (
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
"%37s (%2d) ==> %-32s(%2d) %-32s",
(char *) CurrentPath.Pointer, CurrentPathLength,
(char *) TargetPath.Pointer, TargetPathLength, ExternalNameString));
(char *) CurrentPath.Pointer, CurrentPath.Length,
(char *) TargetPath.Pointer, TargetPath.Length, ExternalNameString));
ACPI_MEM_FREE (ExternalNameString);
Status = AE_NOT_FOUND;
if (!(Flags & (AML_NAMED | AML_CREATE)))
{
/*
* Check if search-to-root can be utilized. Use the last NameSeg of
* the NamePath and 1) See if can be found and 2) If found, make
* sure that it is the same node that we want. If there is another
* name in the search path before the one we want, the nodes will
* not match, and we cannot use this optimization.
*/
NewPath = &(((NATIVE_CHAR *) TargetPath.Pointer)[TargetPathLength - ACPI_NAME_SIZE]);
NewPathExternal = NewPath;
/* Lookup the NameSeg using SEARCH_PARENT (search-to-root) */
Status = AcpiNsLookup (&ScopeInfo, NewPath,
ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
if (ACPI_SUCCESS (Status))
{
/*
* We found the name, but we must check to make sure that the node
* matches. Otherwise, there is another identical name in the search
* path that precludes the use of this optimization.
*/
if (Node == TargetNode)
{
/* Found the node, we can use this optimization */
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
"NAMESEG: %-24s", NewPath));
OptCount = (AmlNameStringLength - ACPI_NAME_SIZE);
/* We must allocate a new string for the name (TargetPath gets deleted) */
NewPath = ACPI_MEM_CALLOCATE (ACPI_NAME_SIZE + 1);
ACPI_STRCPY (NewPath, NewPathExternal);
AslError (ASL_OPTIMIZATION, ASL_MSG_SINGLE_NAME_OPTIMIZATION, Op,
NewPathExternal);
}
else
{
/* This means that another object with the same name was found first */
Status = AE_NOT_FOUND;
}
}
}
else
/*
* Attempt an optmization depending on the type of namepath
*/
if (Flags & (AML_NAMED | AML_CREATE))
{
/*
* This is a named opcode and the namepath is a name declaration, not
* a reference.
*/
if (((CurrentNode == AcpiGbl_RootNode) ||
(Op->Common.Parent->Asl.ParseOpcode == PARSEOP_DEFINITIONBLOCK)) &&
(AmlNameString[0] == '\\'))
Status = LkOptimizeNameDeclaration (Op, WalkState, CurrentNode,
AmlNameString, &NewPath);
if (ACPI_FAILURE (Status))
{
NewPath = &AmlNameString[1];
Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, NewPath,
NULL, &ExternalNameString);
if (ACPI_FAILURE (Status))
{
/* TBD: this simply quietly aborts! */
AslAbort ();
}
AslError (ASL_OPTIMIZATION, ASL_MSG_NAME_OPTIMIZATION, Op, ExternalNameString);
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
"AT ROOT: %-24s", ExternalNameString));
ACPI_MEM_FREE (ExternalNameString);
OptCount = 1;
Status = AE_OK;
/*
* 2) Search-to-root could not be used, now attempt to
* optimize the namestring with carats (up-arrow)
*/
Status = LkBuildShortestPath (Op, WalkState, CurrentNode,
TargetNode, &CurrentPath, &TargetPath,
AmlNameStringLength, 1, &NewPath);
}
}
/*
* If search-to-root could not be used, attempt to optimize the namestring
* with carats (up-arrow)
*/
if (ACPI_FAILURE (Status))
else
{
/*
* Determine the maximum number of NameSegs that the Target and Current paths
* can possibly have in common. (To optimize, we have to have at least 1)
*
* Note: The external NamePath string lengths are always a multiple of 5
* (ACPI_NAME_SIZE + separator)
* This is a reference to an existing named object
*
* 1) Check if search-to-root can be utilized using the last
* NameSeg of the NamePath
*/
MaxCommonSegments = TargetPathLength / PATH_SEGMENT_LENGTH;
if (CurrentPathLength < TargetPathLength)
Status = LkSearchToRoot (Op, WalkState, CurrentNode,
TargetNode, &TargetPath, &NewPath);
if (ACPI_FAILURE (Status))
{
MaxCommonSegments = CurrentPathLength / PATH_SEGMENT_LENGTH;
}
/*
* Determine how many NameSegs the two paths have in common.
* (Starting from the root)
*/
for (NumCommonSegments = 0;
NumCommonSegments < MaxCommonSegments;
NumCommonSegments++)
{
/* Compare two single NameSegs */
if (ACPI_STRNCMP (
&((NATIVE_CHAR *) TargetPath.Pointer)[(NumCommonSegments * PATH_SEGMENT_LENGTH) + 1],
&((NATIVE_CHAR *) CurrentPath.Pointer)[(NumCommonSegments * PATH_SEGMENT_LENGTH) + 1],
ACPI_NAME_SIZE))
{
break;
}
}
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " COMMON: %d", NumCommonSegments));
/* There must be at least 1 common NameSeg in order to optimize */
if (NumCommonSegments > 0)
{
/* Determine how many prefix Carats are required */
NumCarats = (CurrentPathLength / PATH_SEGMENT_LENGTH) - NumCommonSegments;
Index = (NumCommonSegments * PATH_SEGMENT_LENGTH) + 1 - NumCarats;
/* Insert the Carats into the Target string */
for (i = 0; i < NumCarats; i++)
{
((NATIVE_CHAR *) TargetPath.Pointer)[Index + i] = '^';
}
NewPathExternal = &((NATIVE_CHAR *) TargetPath.Pointer)[Index];
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " %-24s", NewPathExternal));
/*
* Internalize the new target string and check it against the original string
* to make sure that this is in fact an optimization. If the original string
* is already optimal, there is no point in continuing.
* 2) Search-to-root could not be used, now attempt to
* optimize the namestring with carats (up-arrow)
*/
AcpiNsInternalizeName (NewPathExternal, &NewPath);
if (ACPI_STRLEN (NewPath) < AmlNameStringLength)
{
/*
* Check to make sure that the optimization finds the node we are
* looking for. This is simply a sanity check on the new
* path that has been created.
*/
Status = AcpiNsLookup (&ScopeInfo, NewPath,
ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
0, WalkState, &(Node));
if (ACPI_SUCCESS (Status))
{
/* Found the namepath, but make sure the node is correct */
if (Node == TargetNode)
{
/* The lookup matched the node, accept this optimization */
OptCount = (AmlNameStringLength - ACPI_STRLEN (NewPath));
AslError (ASL_OPTIMIZATION, ASL_MSG_NAME_OPTIMIZATION, Op, NewPathExternal);
}
else
{
/* Node is not correct, do not use this optimization */
Status = AE_NOT_FOUND;
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " WRONG NODE"));
AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
"Not using optimized name - found wrong node");
}
}
else
{
/* The lookup failed, we obviously cannot use this optimization */
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " NOT FOUND"));
AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
"Not using optimized name - did not find node");
}
}
else
{
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " NOT SHORTER (New %d old %d)",
ACPI_STRLEN (NewPath), AmlNameStringLength));
}
Status = LkBuildShortestPath (Op, WalkState, CurrentNode,
TargetNode, &CurrentPath, &TargetPath,
AmlNameStringLength, 0, &NewPath);
}
}
/*
* Success from above indicates that the NamePath was successfully
* optimized
* optimized. We need to update the parse op with the new name
*/
if (ACPI_SUCCESS (Status))
{
OptTotal += OptCount;
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " REDUCED %2d (%d)", OptCount, OptTotal));
HowMuchShorter = (AmlNameStringLength - ACPI_STRLEN (NewPath));
OptTotal += HowMuchShorter;
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " REDUCED %2d (%d)",
HowMuchShorter, OptTotal));
if (Flags & AML_NAMED)
{
@ -508,6 +706,8 @@ LkOptimizeNamePath (
}
else if (Flags & AML_CREATE)
{
/* TBD: Create case - must traverse to proper node */
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " NOT HANDLED - CREATE FIELD"));
}
else
@ -523,88 +723,12 @@ LkOptimizeNamePath (
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ALREADY OPTIMAL"));
}
/* Cleanup path buffers */
ACPI_MEM_FREE (TargetPath.Pointer);
ACPI_MEM_FREE (CurrentPath.Pointer);
Exit:
ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "\n"));
return_VOID;
}
#if 0
/*******************************************************************************
*
* FUNCTION: LkOptimizeName
*
* PARAMETERS: Op - Current parser op
* WalkState - Current state
* AmlNameString - Unoptimized namepath
* TargetNode - Node to which AmlNameString refers
*
* RETURN: None. If path is optimized, the Op is updated with new path
*
* DESCRIPTION: Optimize a Name to the minimal length. Must take
* into account both the current location in the namespace and
* the actual path.
*
******************************************************************************/
void
LkOptimizeName (
ACPI_PARSE_OBJECT *Op,
ACPI_WALK_STATE *WalkState,
NATIVE_CHAR *AmlNameString,
ACPI_NAMESPACE_NODE *TargetNode)
{
ACPI_SIZE AmlNameStringLength;
char *ExternalNameString;
ACPI_STATUS Status;
ACPI_FUNCTION_TRACE ("LkOptimizeName");
/* This is an optional optimization */
if (!Gbl_ReferenceOptimizationFlag)
{
return_VOID;
}
/*
* The original path must be longer than one NameSeg (4 chars) for there
* to be any possibility that it can be optimized to a shorter string
*/
AmlNameStringLength = ACPI_STRLEN (AmlNameString);
if (AmlNameStringLength <= 4)
{
return_VOID;
}
if (!WalkState->ScopeInfo ||
(WalkState->ScopeInfo->Scope.Node == AcpiGbl_RootNode))
{
if (AmlNameString[0] == '\\')
{
Op->Asl.Child->Asl.Value.String = &AmlNameString[1];
Op->Asl.Child->Asl.AmlLength = AmlNameStringLength - 1;
Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, Op->Asl.Child->Asl.Value.String,
NULL, &ExternalNameString);
if (ACPI_FAILURE (Status))
{
/* TBD: this simply quietly aborts! */
AslAbort ();
}
AslError (ASL_OPTIMIZATION, ASL_MSG_NAME_OPTIMIZATION, Op, ExternalNameString);
ACPI_MEM_FREE (ExternalNameString);
}
}
return_VOID;
}
#endif