[llvm] [StaticDataLayout][PGO] Add profile format for static data layout, and the classes to operate on the profiles. (PR #138170)
Mingming Liu via llvm-commits
llvm-commits at lists.llvm.org
Thu May 15 16:48:55 PDT 2025
================
@@ -0,0 +1,214 @@
+//===- DataAccessProf.h - Data access profile format support ---------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains support to construct and use data access profiles.
+//
+// For the original RFC of this pass please see
+// https://discourse.llvm.org/t/rfc-profile-guided-static-data-partitioning/83744
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_PROFILEDATA_DATAACCESSPROF_H_
+#define LLVM_PROFILEDATA_DATAACCESSPROF_H_
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseMapInfoVariant.h"
+#include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ProfileData/InstrProf.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/StringSaver.h"
+
+#include <cstdint>
+#include <optional>
+#include <variant>
+
+namespace llvm {
+
+namespace data_access_prof {
+
+/// The location of data in the source code. Used by profile lookup API.
+struct SourceLocation {
+ SourceLocation(StringRef FileNameRef, uint32_t Line)
+ : FileName(FileNameRef.str()), Line(Line) {}
+ /// The filename where the data is located.
+ std::string FileName;
+ /// The line number in the source code.
+ uint32_t Line;
+};
+
+namespace internal {
----------------
mingmingl-llvm wrote:
I tried to use forward declaration under `internal` namespace; this gives compile errors which indicates forward decl doesn't work with class template instantiation.
Something like this when moving `SourceLocationRef` itself, and moving `DataAccessProfRecordRef` along with `SourceLocationRef` caused similar static assertion errors for `class DataAccessProfData`.
```
/../../../../include/c++/14/type_traits:1364:21: error: static assertion failed due to requirement 'std::__is_complete_or_unbounded(std::__type_identity<llvm::data_access_prof::internal::SourceLocationRef>{})': template argument must be a complete class or an unbounded array
1364 | static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
llvm/include/llvm/ADT/SmallVector.h:327:36: note: in instantiation of template class 'std::is_trivially_move_constructible<llvm::data_access_prof::internal::SourceLocationRef>' requested here
327 | (std::is_trivially_move_constructible<T>::value) &&
| ^
llvm/include/llvm/ADT/SmallVector.h:573:32: note: in instantiation of default argument for 'SmallVectorTemplateBase<llvm::data_access_prof::internal::SourceLocationRef>' required here
573 | class SmallVectorImpl : public SmallVectorTemplateBase<T> {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
llvm/include/llvm/ADT/SmallVector.h:1195:43: note: in instantiation of template class 'llvm::SmallVectorImpl<llvm::data_access_prof::internal::SourceLocationRef>' requested here
1195 | class LLVM_GSL_OWNER SmallVector : public SmallVectorImpl<T>,
| ^
llvm/include/llvm/ProfileData/DataAccessProf.h:82:43: note: in instantiation of template class 'llvm::SmallVector<llvm::data_access_prof::internal::SourceLocationRef, 0>' requested here
82 | llvm::SmallVector<SourceLocationRef, 0> Locations;
```
https://github.com/llvm/llvm-project/pull/138170
More information about the llvm-commits
mailing list