[clang] [PGO] Add ability to mark cold functions as optsize/minsize/optnone (PR #69030)

Ellis Hoag via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 16 16:49:05 PDT 2023


================
@@ -0,0 +1,28 @@
+//===- MarkColdFunctions.h - ------------------------------------*- 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_TRANSFORMS_INSTRUMENTATION_MARKCOLDFUNCTIONS_H
+#define LLVM_TRANSFORMS_INSTRUMENTATION_MARKCOLDFUNCTIONS_H
+
+#include "llvm/IR/PassManager.h"
+#include "llvm/Support/PGOOptions.h"
+
+namespace llvm {
+
+struct MarkColdFunctionsPass : public PassInfoMixin<MarkColdFunctionsPass> {
----------------
ellishg wrote:

I think this pass could be generalized a bit. It seems that the goal for this pr is to reduce the size overhead of `-O2` by forcing cold functions to be `optsize`/`minsize`. Another goal could be to improve the performance of `-Oz` by forcing very hot functions to be `optsize` (as opposed to `minsize`) or remove `optsize`/`minsize` from them entirely. This is actually something we explored in [this paper](https://dl.acm.org/doi/10.1145/3497776.3517764) a while back and I would eventually like to upstream something similar. I believe this could be incorporated into this pass, but the name seems to be too vague. I think "PGO" should to be in the name so users know that it is involved. Maybe `PGOForceFuncAttrsPass` or `ProfileGuidedFuncAttrsPass`?

CC @kyulee-com 

https://github.com/llvm/llvm-project/pull/69030


More information about the cfe-commits mailing list