[llvm] [ctx_profile] Profile reader and writer (PR #91859)
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Mon May 13 16:16:18 PDT 2024
================
@@ -0,0 +1,164 @@
+//===- PGOCtxProfReader.cpp - Contextual Instrumentation profile reader ---===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Read a contextual profile into a datastructure suitable for maintenance
+// throughout IPO
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ProfileData/PGOCtxProfReader.h"
+#include "llvm/Bitstream/BitCodeEnums.h"
+#include "llvm/Bitstream/BitstreamReader.h"
+#include "llvm/ProfileData/PGOCtxProfWriter.h"
+#include "llvm/Support/Errc.h"
+#include "llvm/Support/Error.h"
+
+using namespace llvm;
+
+#define EXPECT_OR_RET(LHS, RHS) \
+ auto LHS = RHS; \
+ if (!LHS) \
+ return LHS.takeError();
+
+#define RET_ON_ERR(EXPR) \
+ if (auto Err = (EXPR)) \
+ return Err;
----------------
snehasish wrote:
This pattern is being used within LLVM with different names in at least a couple of other places that I could find easily.
1. https://github.com/llvm/llvm-project/blob/c3028a230557405b0f10bdd7d450f7f92747bbe3/llvm/tools/llvm-rc/ResourceScriptParser.cpp#L20-L30
2. https://github.com/llvm/llvm-project/blob/c3028a230557405b0f10bdd7d450f7f92747bbe3/llvm/unittests/tools/llvm-profdata/OutputSizeLimitTest.cpp#L56-L70
I'm sure there are more that I missed. I think we should formalize this as a macro in Support/Error.h so that others can reuse. Should be in a separate patch though. What do you think?
https://github.com/llvm/llvm-project/pull/91859
More information about the llvm-commits
mailing list