[libc-commits] [PATCH] D131993: [libc] add compile option for printf arg type array
Michael Jones via Phabricator via libc-commits
libc-commits at lists.llvm.org
Wed Aug 24 10:33:13 PDT 2022
michaelrj updated this revision to Diff 455281.
michaelrj added a comment.
rebase
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131993/new/
https://reviews.llvm.org/D131993
Files:
libc/src/stdio/printf_core/parser.h
libc/src/stdio/printf_core/printf_config.h
Index: libc/src/stdio/printf_core/printf_config.h
===================================================================
--- /dev/null
+++ libc/src/stdio/printf_core/printf_config.h
@@ -0,0 +1,24 @@
+//===-- Printf Configuration Handler ----------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PRINTF_CONFIG_H
+#define LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PRINTF_CONFIG_H
+
+// The index array buffer is always initialized when printf is called. In cases
+// where index mode is necessary but memory is limited, or when index mode
+// performance is important and memory is available, this compile option
+// provides a knob to adjust memory usage to an appropriate level. 128 is picked
+// as the default size since that's big enough to handle even extreme cases and
+// the runtime penalty for not having enough space is severe.
+#ifndef LLVM_LIBC_PRINTF_INDEX_ARR_LEN
+#define LLVM_LIBC_PRINTF_INDEX_ARR_LEN 128
+#endif
+
+// TODO(michaelrj): Move the other printf configuration options into this file.
+
+#endif // LLVM_LIBC_SRC_STDIO_PRINTF_CORE_PRINTF_CONFIG_H
Index: libc/src/stdio/printf_core/parser.h
===================================================================
--- libc/src/stdio/printf_core/parser.h
+++ libc/src/stdio/printf_core/parser.h
@@ -11,6 +11,7 @@
#include "src/__support/arg_list.h"
#include "src/stdio/printf_core/core_structs.h"
+#include "src/stdio/printf_core/printf_config.h"
#include <stddef.h>
@@ -41,14 +42,16 @@
return (size == other.size) && (primary_type == other.primary_type);
}
};
- // TODO: Make this size configurable via a compile option.
- static constexpr size_t DESC_ARR_LEN = 32;
+
+ // Defined in printf_config.h
+ static constexpr size_t DESC_ARR_LEN = LLVM_LIBC_PRINTF_INDEX_ARR_LEN;
+
// desc_arr stores the sizes of the variables in the ArgList. This is used in
// index mode to reduce repeated string parsing. The sizes are stored as
// TypeDesc objects, which store the size as well as minimal type information.
// This is necessary because some systems separate the floating point and
// integer values in va_args.
- TypeDesc desc_arr[DESC_ARR_LEN] = {{0, Integer}};;
+ TypeDesc desc_arr[DESC_ARR_LEN] = {{0, Integer}};
// TODO: Look into object stores for optimization.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131993.455281.patch
Type: text/x-patch
Size: 2597 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20220824/09c196e5/attachment.bin>
More information about the libc-commits
mailing list