[llvm-branch-commits] [clang] add-loan-analysis-to-benchmark (PR #149577)
https://github.com/usx95 created https://github.com/llvm/llvm-project/pull/149577 None >From cb9a52142e992ee632dc669d80b02443af84ae5e Mon Sep 17 00:00:00 2001 From: Utkarsh Saxena Date: Fri, 18 Jul 2025 19:16:43 + Subject: [PATCH] add-loan-analysis-to-benchmark --- .../test/Analysis/LifetimeSafety/benchmark.py | 238 -- 1 file changed, 157 insertions(+), 81 deletions(-) diff --git a/clang/test/Analysis/LifetimeSafety/benchmark.py b/clang/test/Analysis/LifetimeSafety/benchmark.py index 9d5f36c51b9ee..229f58ba019e4 100644 --- a/clang/test/Analysis/LifetimeSafety/benchmark.py +++ b/clang/test/Analysis/LifetimeSafety/benchmark.py @@ -21,22 +21,12 @@ def generate_cpp_cycle_test(n: int) -> str: struct MyObj { int id; ~MyObj() {} }; void long_cycle_4(bool condition) { -MyObj v1{1}; -MyObj v2{1}; -MyObj v3{1}; -MyObj v4{1}; - -MyObj* p1 = &v1; -MyObj* p2 = &v2; -MyObj* p3 = &v3; -MyObj* p4 = &v4; +MyObj v1{1}; MyObj v2{1}; MyObj v3{1}; MyObj v4{1}; +MyObj* p1 = &v1; MyObj* p2 = &v2; MyObj* p3 = &v3; MyObj* p4 = &v4; while (condition) { MyObj* temp = p1; -p1 = p2; -p2 = p3; -p3 = p4; -p4 = temp; +p1 = p2; p2 = p3; p3 = p4; p4 = temp; } } """ @@ -99,28 +89,81 @@ def generate_cpp_merge_test(n: int) -> str: return cpp_code -def analyze_trace_file(trace_path: str) -> tuple[float, float]: +def generate_cpp_nested_loop_test(n: int) -> str: """ -Parses the -ftime-trace JSON output to find durations. +Generates C++ code with N levels of nested loops. +This pattern tests how analysis performance scales with loop nesting depth, +which is a key factor in the complexity of dataflow analyses on structured +control flow. + +Example (n=3): +struct MyObj { int id; ~MyObj() {} }; +void nested_loops_3() { +MyObj* p = nullptr; +for(int i0=0; i0<2; ++i0) { +MyObj s0; p = &s0; +for(int i1=0; i1<2; ++i1) { +MyObj s1; p = &s1; +for(int i2=0; i2<2; ++i2) { +MyObj s2; p = &s2; +} +} +} +} +""" +if n <= 0: +return "// Nesting depth must be positive." + +cpp_code = "struct MyObj { int id; ~MyObj() {} };\n\n" +cpp_code += f"void nested_loops_{n}() {{\n" +cpp_code += "MyObj* p = nullptr;\n" + +for i in range(n): +indent = "" * (i + 1) +cpp_code += f"{indent}for(int i{i}=0; i{i}<2; ++i{i}) {{\n" +cpp_code += f"{indent}MyObj s{i}; p = &s{i};\n" + +for i in range(n - 1, -1, -1): +indent = "" * (i + 1) +cpp_code += f"{indent}}}\n" + +cpp_code += "}\n" +cpp_code += f"\nint main() {{ nested_loops_{n}(); return 0; }}\n" +return cpp_code + -Returns: -A tuple of (lifetime_analysis_duration_us, total_clang_duration_us). +def analyze_trace_file(trace_path: str) -> dict: """ -lifetime_duration = 0.0 -total_duration = 0.0 +Parses the -ftime-trace JSON output to find durations for the lifetime +analysis and its sub-phases. +Returns a dictionary of durations in microseconds. +""" +durations = { +"lifetime_us": 0.0, +"total_us": 0.0, +"fact_gen_us": 0.0, +"loan_prop_us": 0.0, +"expired_loans_us": 0.0, +} +event_name_map = { +"LifetimeSafetyAnalysis": "lifetime_us", +"ExecuteCompiler": "total_us", +"FactGenerator": "fact_gen_us", +"LoanPropagation": "loan_prop_us", +"ExpiredLoans": "expired_loans_us", +} try: with open(trace_path, "r") as f: trace_data = json.load(f) for event in trace_data.get("traceEvents", []): -if event.get("name") == "LifetimeSafetyAnalysis": -lifetime_duration += float(event.get("dur", 0)) -if event.get("name") == "ExecuteCompiler": -total_duration += float(event.get("dur", 0)) - +event_name = event.get("name") +if event_name in event_name_map: +key = event_name_map[event_name] +durations[key] += float(event.get("dur", 0)) except (IOError, json.JSONDecodeError) as e: print(f"Error reading or parsing trace file {trace_path}: {e}", file=sys.stderr) -return 0.0, 0.0 -return lifetime_duration, total_duration +return {key: 0.0 for key in durations} +return durations def power_law(n, c, k): @@ -135,8 +178,29 @@ def human_readable_time(ms: float) -> str: return f"{ms:.2f} ms" +def calculate_complexity(n_data, y_data) -> tuple[float |
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149565)
@@ -60,6 +60,17 @@ HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: class Shape +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Abstract base class for shapes. +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Provides a common interface for different types of shapes. +HTML-SHAPE: +HTML-SHAPE: ilovepi wrote: Do we have any notion about why the format w/ the tags is so wonky? The template looks fine. Are we handling whitespace incorrectly in the mustache lib? or do we need to format the template differently to get these to line up correctly? https://github.com/llvm/llvm-project/pull/149565 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149565)
https://github.com/ilovepi approved this pull request. LGTM, except the Q on formatting. Obviously doesn't need to be solved in this patch, though. https://github.com/llvm/llvm-project/pull/149565 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149565)
https://github.com/ilovepi edited https://github.com/llvm/llvm-project/pull/149565 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149565)
@@ -60,6 +60,17 @@ HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: class Shape +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Abstract base class for shapes. +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Provides a common interface for different types of shapes. +HTML-SHAPE: +HTML-SHAPE: evelez7 wrote: This only happens in the comment partial. I'm pretty sure it's something in the mustache library because all other templates handle their whitespace fine. I also haven't tested it but the comment partial is the only one that templates itself recursively, so that might have something to do with it. https://github.com/llvm/llvm-project/pull/149565 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/149589 None >From b36a2d4bc00eee19dae7bd0eaaf08a3b4d8a70a2 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Fri, 18 Jul 2025 13:59:44 -0700 Subject: [PATCH] [clang-doc] integrate JSON as the source for Mustache templates --- .../clang-doc/HTMLMustacheGenerator.cpp | 487 +++--- .../clang-doc/assets/class-template.mustache | 62 +-- .../clang-doc/assets/enum-template.mustache | 12 +- .../assets/function-template.mustache | 2 +- .../assets/namespace-template.mustache| 45 +- .../clang-doc/basic-project.mustache.test | 70 +-- .../test/clang-doc/mustache-index.cpp | 14 +- .../clang-doc/mustache-separate-namespace.cpp | 8 +- .../clang-doc/HTMLMustacheGeneratorTest.cpp | 129 - 9 files changed, 173 insertions(+), 656 deletions(-) diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp index 7aeaa1b7cf67d..98e2935a8aada 100644 --- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp @@ -27,6 +27,9 @@ using namespace llvm::mustache; namespace clang { namespace doc { +static Error generateDocForJSON(json::Value &JSON, StringRef Filename, +StringRef Path, raw_fd_ostream &OS, +const ClangDocContext &CDCtx); static Error createFileOpenError(StringRef FileName, std::error_code EC) { return createFileError("cannot open file " + FileName, EC); @@ -132,404 +135,65 @@ Error MustacheHTMLGenerator::generateDocs( return Err; } - // Track which directories we already tried to create. - StringSet<> CreatedDirs; - // Collect all output by file name and create the necessary directories. - StringMap> FileToInfos; - for (const auto &Group : Infos) { -llvm::TimeTraceScope TS("setup directories"); -doc::Info *Info = Group.getValue().get(); - -SmallString<128> Path; -sys::path::native(RootDir, Path); -sys::path::append(Path, Info->getRelativeFilePath("")); -if (!CreatedDirs.contains(Path)) { - if (std::error_code EC = sys::fs::create_directories(Path)) -return createStringError(EC, "failed to create directory '%s'.", - Path.c_str()); - CreatedDirs.insert(Path); -} - -sys::path::append(Path, Info->getFileBaseName() + ".html"); -FileToInfos[Path].push_back(Info); + { +llvm::TimeTraceScope TS("Generate JSON for Mustache"); +if (auto JSONGenerator = findGeneratorByName("json")) { + if (Error Err = JSONGenerator.get()->generateDocs( + RootDir, std::move(Infos), CDCtx)) +return Err; +} else + return JSONGenerator.takeError(); } + StringMap JSONFileMap; { -llvm::TimeTraceScope TS("Generate Docs"); -for (const auto &Group : FileToInfos) { - llvm::TimeTraceScope TS("Info to Doc"); +llvm::TimeTraceScope TS("Iterate JSON files"); +std::error_code EC; +sys::fs::directory_iterator JSONIter(RootDir, EC); +std::vector JSONFiles; +JSONFiles.reserve(Infos.size()); +if (EC) + return createStringError("Failed to create directory iterator."); + +while (JSONIter != sys::fs::directory_iterator()) { + if (EC) +return createStringError(EC, "Failed to iterate directory"); + + auto Path = StringRef(JSONIter->path()); + if (!Path.ends_with(".json")) { +JSONIter.increment(EC); +continue; + } + + auto File = MemoryBuffer::getFile(Path); + if ((EC = File.getError())) +continue; + + auto Parsed = json::parse((*File)->getBuffer()); + if (!Parsed) +return Parsed.takeError(); + std::error_code FileErr; - raw_fd_ostream InfoOS(Group.getKey(), FileErr, sys::fs::OF_None); + SmallString<16> HTMLPath(Path.begin(), Path.end()); + sys::path::replace_extension(HTMLPath, "html"); + raw_fd_ostream InfoOS(HTMLPath, FileErr, sys::fs::OF_None); if (FileErr) -return createFileOpenError(Group.getKey(), FileErr); +return createFileOpenError(Path, FileErr); - for (const auto &Info : Group.getValue()) -if (Error Err = generateDocForInfo(Info, InfoOS, CDCtx)) - return Err; + if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLPath), + HTMLPath, InfoOS, CDCtx)) +return Err; + JSONIter.increment(EC); } } - return Error::success(); -} - -static json::Value -extractValue(const Location &L, - std::optional RepositoryUrl = std::nullopt) { - Object Obj = Object(); - // TODO: Consider using both Start/End line numbers to improve location report - Obj.insert({"LineNumber", L.StartLineNumber}); - Obj.insert({"Filename", L.Filename}); - - if (!L.IsFileInRootDir || !RepositoryUrl) -return Obj; -
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
evelez7 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/149589?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#149589** https://app.graphite.dev/github/pr/llvm/llvm-project/149589?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/149589?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#149588** https://app.graphite.dev/github/pr/llvm/llvm-project/149588?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/149589 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149565)
https://github.com/evelez7 closed https://github.com/llvm/llvm-project/pull/149565 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149590)
https://github.com/evelez7 created https://github.com/llvm/llvm-project/pull/149590 Comment categories will allow better comment organization in HTML. Before, comments would just be serialized in whatever order they were written, so groups like params or notes wouldn't be in the same sections. >From e3d56c05866222064ac73da6b93771b7f474f4bc Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 17 Jul 2025 15:04:20 -0700 Subject: [PATCH] [clang-doc] separate comments into categories Comment categories will allow better comment organization in HTML. Before, comments would just be serialized in whatever order they were written, so groups like params or notes wouldn't be in the same sections. --- clang-tools-extra/clang-doc/JSONGenerator.cpp | 42 +++ .../test/clang-doc/json/class.cpp | 51 +-- .../test/clang-doc/json/concept.cpp | 15 +++--- 3 files changed, 63 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-doc/JSONGenerator.cpp b/clang-tools-extra/clang-doc/JSONGenerator.cpp index 908e23d24d079..d39077583b2e1 100644 --- a/clang-tools-extra/clang-doc/JSONGenerator.cpp +++ b/clang-tools-extra/clang-doc/JSONGenerator.cpp @@ -83,7 +83,21 @@ serializeLocation(const Location &Loc, return LocationObj; } -static json::Value serializeComment(const CommentInfo &I) { +static void insertComment(Object &Description, json::Value &Comment, + std::string Key) { + auto *CommentArray = Description.getArray(Key); + if (!CommentArray) { +auto CommentsArray = json::Array(); +CommentsArray.push_back(Comment); +Description[Key] = std::move(CommentsArray); +Description["Has" + Key] = true; + } else { +CommentArray->push_back(Comment); +Description[Key] = std::move(*CommentArray); + } +} + +static Object serializeComment(const CommentInfo &I, Object &Description) { // taken from PR #142273 Object Obj = Object(); @@ -94,7 +108,7 @@ static json::Value serializeComment(const CommentInfo &I) { auto &CARef = *ChildArr.getAsArray(); CARef.reserve(I.Children.size()); for (const auto &C : I.Children) -CARef.emplace_back(serializeComment(*C)); +CARef.emplace_back(serializeComment(*C, Description)); switch (I.Kind) { case CommentKind::CK_TextComment: { @@ -106,6 +120,8 @@ static json::Value serializeComment(const CommentInfo &I) { Child.insert({"Command", I.Name}); Child.insert({"Children", ChildArr}); Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.Name == "brief") + insertComment(Description, ChildVal, "BriefComments"); return Obj; } @@ -137,7 +153,10 @@ static json::Value serializeComment(const CommentInfo &I) { if (!I.CloseName.empty()) Child.insert({"CloseName", I.CloseName}); Child.insert({"Children", ChildArr}); -Obj.insert({commentKindToString(I.Kind), ChildVal}); +if (I.CloseName == "endcode") + insertComment(Description, ChildVal, "CodeComments"); +else if (I.CloseName == "endverbatim") + insertComment(Description, ChildVal, "VerbatimComments"); return Obj; } @@ -210,12 +229,17 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, } if (!I.Description.empty()) { -json::Value DescArray = json::Array(); -auto &DescArrayRef = *DescArray.getAsArray(); -DescArrayRef.reserve(I.Description.size()); -for (const auto &Comment : I.Description) - DescArrayRef.push_back(serializeComment(Comment)); -Obj["Description"] = DescArray; +Object Description = Object(); +// Skip straight to the FullComment's children +auto &Comments = I.Description.at(0).Children; +for (const auto &CommentInfo : Comments) { + json::Value Comment = serializeComment(*CommentInfo, Description); + // Paragraph comments might not be children + if (auto *ParagraphComment = + Comment.getAsObject()->get("ParagraphComment")) +insertComment(Description, *ParagraphComment, "ParagraphComments"); +} +Obj["Description"] = std::move(Description); } // Namespaces aren't SymbolInfos, so they dont have a DefLoc diff --git a/clang-tools-extra/test/clang-doc/json/class.cpp b/clang-tools-extra/test/clang-doc/json/class.cpp index a36358982b019..e8fafca28a956 100644 --- a/clang-tools-extra/test/clang-doc/json/class.cpp +++ b/clang-tools-extra/test/clang-doc/json/class.cpp @@ -33,33 +33,30 @@ struct MyClass { }; // CHECK: { -// CHECK-NEXT:"Description": [ -// CHECK-NEXT: { -// CHECK-NEXT: "FullComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "ParagraphComment": { -// CHECK-NEXT: "Children": [ -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " This is a nice class." -// CHECK-NEXT: }, -// CHECK-NEXT: { -// CHECK-NEXT: "TextComment": " It has some
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149590)
evelez7 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/149590?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#149590** https://app.graphite.dev/github/pr/llvm/llvm-project/149590?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/149590?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#149589** https://app.graphite.dev/github/pr/llvm/llvm-project/149589?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#149588** https://app.graphite.dev/github/pr/llvm/llvm-project/149588?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/149590 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
https://github.com/evelez7 edited https://github.com/llvm/llvm-project/pull/149589 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] release/21.x: Revert "Move python binding tests to lit framework" (#149012) (PR #149570)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/149570 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] [llvm] release/21.x: [Hexagon][llvm-objdump] Improve disassembly of Hexagon bundles (#145807) (PR #149578)
llvmbot wrote: @llvm/pr-subscribers-backend-hexagon Author: None (llvmbot) Changes Backport ac7ceb3 Requested by: @quic-areg --- Patch is 24.43 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/149578.diff 11 Files Affected: - (modified) lld/test/ELF/hexagon-plt.s (+9-9) - (modified) lld/test/ELF/hexagon-shared.s (+1-1) - (modified) lld/test/ELF/hexagon-tls-gd-xform.s (+2-2) - (modified) llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h (+12) - (modified) llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp (+85-24) - (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.cpp (+11-23) - (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp (+16-3) - (modified) llvm/test/MC/Hexagon/two_ext.s (+2-2) - (added) llvm/test/tools/llvm-objdump/ELF/Hexagon/hexagon-bundles.s (+47) - (modified) llvm/tools/llvm-mc/Disassembler.cpp (+5-1) - (modified) llvm/tools/llvm-objdump/llvm-objdump.cpp (+107-73) ``diff diff --git a/lld/test/ELF/hexagon-plt.s b/lld/test/ELF/hexagon-plt.s index 679de82923a72..780dc434a6698 100644 --- a/lld/test/ELF/hexagon-plt.s +++ b/lld/test/ELF/hexagon-plt.s @@ -30,31 +30,31 @@ # DIS: <_start>: ## Direct call ## Call foo directly -# DIS-NEXT: { call 0x2003c } +# DIS-NEXT: { call 0x2003c } ## Call bar via plt -# DIS-NEXT: { call 0x20060 } +# DIS-NEXT: { call 0x20060 } ## Call weak via plt -# DIS-NEXT: { call 0x20070 } +# DIS-NEXT: { call 0x20070 } # DIS-NEXT: { immext(#0) ## Call foo directly -# DIS-NEXT: if (p0) jump:nt 0x2003c } +# DIS-NEXT: if (p0) jump:nt 0x2003c } # DIS-NEXT: { immext(#64) ## Call bar via plt -# DIS-NEXT: if (p0) jump:nt 0x20060 } +# DIS-NEXT: if (p0) jump:nt 0x20060 } # DIS-NEXT: { immext(#64) ## Call weak via plt -# DIS-NEXT: if (p0) jump:nt 0x20070 } +# DIS-NEXT: if (p0) jump:nt 0x20070 } # DIS-NEXT: { immext(#0) ## Call foo directly -# DIS-NEXT: r0 = #0 ; jump 0x2003c } +# DIS-NEXT: r0 = #0 ; jump 0x2003c } # DIS-NEXT: { immext(#0) ## Call bar via plt -# DIS-NEXT: r0 = #0 ; jump 0x20060 } +# DIS-NEXT: r0 = #0 ; jump 0x20060 } # DIS-NEXT: { immext(#0) ## Call weak via plt -# DIS-NEXT: r0 = #0 ; jump 0x20070 } +# DIS-NEXT: r0 = #0 ; jump 0x20070 } # DIS: : # DIS-NEXT: 2003c: diff --git a/lld/test/ELF/hexagon-shared.s b/lld/test/ELF/hexagon-shared.s index cc62662d278e2..7f7390f1fa8d8 100644 --- a/lld/test/ELF/hexagon-shared.s +++ b/lld/test/ELF/hexagon-shared.s @@ -88,7 +88,7 @@ pvar: # PLT-NEXT: jumpr r28 } # TEXT: bc 00 01 00 000100bc -# TEXT: { call 0x10300 } +# TEXT: { call 0x10300 } # TEXT: if (p0) jump:nt 0x10300 # TEXT: r0 = #0 ; jump 0x10300 # TEXT: r0 = add(r1,##-65548) diff --git a/lld/test/ELF/hexagon-tls-gd-xform.s b/lld/test/ELF/hexagon-tls-gd-xform.s index 65aeb118fcb33..ade54e8a16fad 100644 --- a/lld/test/ELF/hexagon-tls-gd-xform.s +++ b/lld/test/ELF/hexagon-tls-gd-xform.s @@ -18,10 +18,10 @@ _start: .ifdef GDPLT call x@gdplt -# CHECK_GDPLT: 101ec: { call 0x10220 } +# CHECK_GDPLT: 101ec: { call 0x10220 <__tls_get_addr@plt> } .else call x -# CHECK: 101b8: { call 0x101e0 } +# CHECK: 101b8: { call 0x101e0 } .endif # CHECK_GDPLT:10220: { immext(#0x20040) diff --git a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h index 3a7ca1a69ab85..cae2fbcac1fef 100644 --- a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h +++ b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h @@ -136,6 +136,18 @@ class LLVM_ABI MCDisassembler { ArrayRef Bytes, uint64_t Address, raw_ostream &CStream) const = 0; + /// Returns the disassembly of an instruction bundle for VLIW architectures + /// like Hexagon. + /// + /// \param Instr- An MCInst to populate with the contents of + /// the Bundle with sub-instructions encoded as Inst operands. + virtual DecodeStatus getInstructionBundle(MCInst &Instr, uint64_t &Size, +ArrayRef Bytes, +uint64_t Address, +raw_ostream &CStream) const { +return Fail; + } + /// Used to perform separate target specific disassembly for a particular /// symbol. May parse any prelude that precedes instructions after the /// start of a symbol, or the entire symbol. diff --git a/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp b/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp index 5bd31707acb6f..22cff7c80fa01 100644 --- a/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp +++ b/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp @@ -43,12 +43,12 @@ namespace { class HexagonDisassembler : public MCDisassembler { public: std::unique_ptr const MCII; - std::unique
[llvm-branch-commits] [lld] [llvm] release/21.x: [Hexagon][llvm-objdump] Improve disassembly of Hexagon bundles (#145807) (PR #149578)
llvmbot wrote: @llvm/pr-subscribers-lld-elf Author: None (llvmbot) Changes Backport ac7ceb3 Requested by: @quic-areg --- Patch is 24.43 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/149578.diff 11 Files Affected: - (modified) lld/test/ELF/hexagon-plt.s (+9-9) - (modified) lld/test/ELF/hexagon-shared.s (+1-1) - (modified) lld/test/ELF/hexagon-tls-gd-xform.s (+2-2) - (modified) llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h (+12) - (modified) llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp (+85-24) - (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.cpp (+11-23) - (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp (+16-3) - (modified) llvm/test/MC/Hexagon/two_ext.s (+2-2) - (added) llvm/test/tools/llvm-objdump/ELF/Hexagon/hexagon-bundles.s (+47) - (modified) llvm/tools/llvm-mc/Disassembler.cpp (+5-1) - (modified) llvm/tools/llvm-objdump/llvm-objdump.cpp (+107-73) ``diff diff --git a/lld/test/ELF/hexagon-plt.s b/lld/test/ELF/hexagon-plt.s index 679de82923a72..780dc434a6698 100644 --- a/lld/test/ELF/hexagon-plt.s +++ b/lld/test/ELF/hexagon-plt.s @@ -30,31 +30,31 @@ # DIS: <_start>: ## Direct call ## Call foo directly -# DIS-NEXT: { call 0x2003c } +# DIS-NEXT: { call 0x2003c } ## Call bar via plt -# DIS-NEXT: { call 0x20060 } +# DIS-NEXT: { call 0x20060 } ## Call weak via plt -# DIS-NEXT: { call 0x20070 } +# DIS-NEXT: { call 0x20070 } # DIS-NEXT: { immext(#0) ## Call foo directly -# DIS-NEXT: if (p0) jump:nt 0x2003c } +# DIS-NEXT: if (p0) jump:nt 0x2003c } # DIS-NEXT: { immext(#64) ## Call bar via plt -# DIS-NEXT: if (p0) jump:nt 0x20060 } +# DIS-NEXT: if (p0) jump:nt 0x20060 } # DIS-NEXT: { immext(#64) ## Call weak via plt -# DIS-NEXT: if (p0) jump:nt 0x20070 } +# DIS-NEXT: if (p0) jump:nt 0x20070 } # DIS-NEXT: { immext(#0) ## Call foo directly -# DIS-NEXT: r0 = #0 ; jump 0x2003c } +# DIS-NEXT: r0 = #0 ; jump 0x2003c } # DIS-NEXT: { immext(#0) ## Call bar via plt -# DIS-NEXT: r0 = #0 ; jump 0x20060 } +# DIS-NEXT: r0 = #0 ; jump 0x20060 } # DIS-NEXT: { immext(#0) ## Call weak via plt -# DIS-NEXT: r0 = #0 ; jump 0x20070 } +# DIS-NEXT: r0 = #0 ; jump 0x20070 } # DIS: : # DIS-NEXT: 2003c: diff --git a/lld/test/ELF/hexagon-shared.s b/lld/test/ELF/hexagon-shared.s index cc62662d278e2..7f7390f1fa8d8 100644 --- a/lld/test/ELF/hexagon-shared.s +++ b/lld/test/ELF/hexagon-shared.s @@ -88,7 +88,7 @@ pvar: # PLT-NEXT: jumpr r28 } # TEXT: bc 00 01 00 000100bc -# TEXT: { call 0x10300 } +# TEXT: { call 0x10300 } # TEXT: if (p0) jump:nt 0x10300 # TEXT: r0 = #0 ; jump 0x10300 # TEXT: r0 = add(r1,##-65548) diff --git a/lld/test/ELF/hexagon-tls-gd-xform.s b/lld/test/ELF/hexagon-tls-gd-xform.s index 65aeb118fcb33..ade54e8a16fad 100644 --- a/lld/test/ELF/hexagon-tls-gd-xform.s +++ b/lld/test/ELF/hexagon-tls-gd-xform.s @@ -18,10 +18,10 @@ _start: .ifdef GDPLT call x@gdplt -# CHECK_GDPLT: 101ec: { call 0x10220 } +# CHECK_GDPLT: 101ec: { call 0x10220 <__tls_get_addr@plt> } .else call x -# CHECK: 101b8: { call 0x101e0 } +# CHECK: 101b8: { call 0x101e0 } .endif # CHECK_GDPLT:10220: { immext(#0x20040) diff --git a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h index 3a7ca1a69ab85..cae2fbcac1fef 100644 --- a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h +++ b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h @@ -136,6 +136,18 @@ class LLVM_ABI MCDisassembler { ArrayRef Bytes, uint64_t Address, raw_ostream &CStream) const = 0; + /// Returns the disassembly of an instruction bundle for VLIW architectures + /// like Hexagon. + /// + /// \param Instr- An MCInst to populate with the contents of + /// the Bundle with sub-instructions encoded as Inst operands. + virtual DecodeStatus getInstructionBundle(MCInst &Instr, uint64_t &Size, +ArrayRef Bytes, +uint64_t Address, +raw_ostream &CStream) const { +return Fail; + } + /// Used to perform separate target specific disassembly for a particular /// symbol. May parse any prelude that precedes instructions after the /// start of a symbol, or the entire symbol. diff --git a/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp b/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp index 5bd31707acb6f..22cff7c80fa01 100644 --- a/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp +++ b/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp @@ -43,12 +43,12 @@ namespace { class HexagonDisassembler : public MCDisassembler { public: std::unique_ptr const MCII; - std::unique_ptr Cur
[llvm-branch-commits] [lld] [llvm] release/21.x: [Hexagon][llvm-objdump] Improve disassembly of Hexagon bundles (#145807) (PR #149578)
llvmbot wrote: @llvm/pr-subscribers-llvm-binary-utilities Author: None (llvmbot) Changes Backport ac7ceb3 Requested by: @quic-areg --- Patch is 24.43 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/149578.diff 11 Files Affected: - (modified) lld/test/ELF/hexagon-plt.s (+9-9) - (modified) lld/test/ELF/hexagon-shared.s (+1-1) - (modified) lld/test/ELF/hexagon-tls-gd-xform.s (+2-2) - (modified) llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h (+12) - (modified) llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp (+85-24) - (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonInstPrinter.cpp (+11-23) - (modified) llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCTargetDesc.cpp (+16-3) - (modified) llvm/test/MC/Hexagon/two_ext.s (+2-2) - (added) llvm/test/tools/llvm-objdump/ELF/Hexagon/hexagon-bundles.s (+47) - (modified) llvm/tools/llvm-mc/Disassembler.cpp (+5-1) - (modified) llvm/tools/llvm-objdump/llvm-objdump.cpp (+107-73) ``diff diff --git a/lld/test/ELF/hexagon-plt.s b/lld/test/ELF/hexagon-plt.s index 679de82923a72..780dc434a6698 100644 --- a/lld/test/ELF/hexagon-plt.s +++ b/lld/test/ELF/hexagon-plt.s @@ -30,31 +30,31 @@ # DIS: <_start>: ## Direct call ## Call foo directly -# DIS-NEXT: { call 0x2003c } +# DIS-NEXT: { call 0x2003c } ## Call bar via plt -# DIS-NEXT: { call 0x20060 } +# DIS-NEXT: { call 0x20060 } ## Call weak via plt -# DIS-NEXT: { call 0x20070 } +# DIS-NEXT: { call 0x20070 } # DIS-NEXT: { immext(#0) ## Call foo directly -# DIS-NEXT: if (p0) jump:nt 0x2003c } +# DIS-NEXT: if (p0) jump:nt 0x2003c } # DIS-NEXT: { immext(#64) ## Call bar via plt -# DIS-NEXT: if (p0) jump:nt 0x20060 } +# DIS-NEXT: if (p0) jump:nt 0x20060 } # DIS-NEXT: { immext(#64) ## Call weak via plt -# DIS-NEXT: if (p0) jump:nt 0x20070 } +# DIS-NEXT: if (p0) jump:nt 0x20070 } # DIS-NEXT: { immext(#0) ## Call foo directly -# DIS-NEXT: r0 = #0 ; jump 0x2003c } +# DIS-NEXT: r0 = #0 ; jump 0x2003c } # DIS-NEXT: { immext(#0) ## Call bar via plt -# DIS-NEXT: r0 = #0 ; jump 0x20060 } +# DIS-NEXT: r0 = #0 ; jump 0x20060 } # DIS-NEXT: { immext(#0) ## Call weak via plt -# DIS-NEXT: r0 = #0 ; jump 0x20070 } +# DIS-NEXT: r0 = #0 ; jump 0x20070 } # DIS: : # DIS-NEXT: 2003c: diff --git a/lld/test/ELF/hexagon-shared.s b/lld/test/ELF/hexagon-shared.s index cc62662d278e2..7f7390f1fa8d8 100644 --- a/lld/test/ELF/hexagon-shared.s +++ b/lld/test/ELF/hexagon-shared.s @@ -88,7 +88,7 @@ pvar: # PLT-NEXT: jumpr r28 } # TEXT: bc 00 01 00 000100bc -# TEXT: { call 0x10300 } +# TEXT: { call 0x10300 } # TEXT: if (p0) jump:nt 0x10300 # TEXT: r0 = #0 ; jump 0x10300 # TEXT: r0 = add(r1,##-65548) diff --git a/lld/test/ELF/hexagon-tls-gd-xform.s b/lld/test/ELF/hexagon-tls-gd-xform.s index 65aeb118fcb33..ade54e8a16fad 100644 --- a/lld/test/ELF/hexagon-tls-gd-xform.s +++ b/lld/test/ELF/hexagon-tls-gd-xform.s @@ -18,10 +18,10 @@ _start: .ifdef GDPLT call x@gdplt -# CHECK_GDPLT: 101ec: { call 0x10220 } +# CHECK_GDPLT: 101ec: { call 0x10220 <__tls_get_addr@plt> } .else call x -# CHECK: 101b8: { call 0x101e0 } +# CHECK: 101b8: { call 0x101e0 } .endif # CHECK_GDPLT:10220: { immext(#0x20040) diff --git a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h index 3a7ca1a69ab85..cae2fbcac1fef 100644 --- a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h +++ b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h @@ -136,6 +136,18 @@ class LLVM_ABI MCDisassembler { ArrayRef Bytes, uint64_t Address, raw_ostream &CStream) const = 0; + /// Returns the disassembly of an instruction bundle for VLIW architectures + /// like Hexagon. + /// + /// \param Instr- An MCInst to populate with the contents of + /// the Bundle with sub-instructions encoded as Inst operands. + virtual DecodeStatus getInstructionBundle(MCInst &Instr, uint64_t &Size, +ArrayRef Bytes, +uint64_t Address, +raw_ostream &CStream) const { +return Fail; + } + /// Used to perform separate target specific disassembly for a particular /// symbol. May parse any prelude that precedes instructions after the /// start of a symbol, or the entire symbol. diff --git a/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp b/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp index 5bd31707acb6f..22cff7c80fa01 100644 --- a/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp +++ b/llvm/lib/Target/Hexagon/Disassembler/HexagonDisassembler.cpp @@ -43,12 +43,12 @@ namespace { class HexagonDisassembler : public MCDisassembler { public: std::unique_ptr const MCII; - std::
[llvm-branch-commits] [clang] [LifetimeSafety] Enhance benchmark script for ExpiredLoans analysis (PR #149577)
github-actions[bot] wrote: :warning: Python code formatter, darker found issues in your code. :warning: You can test this locally with the following command: ``bash darker --check --diff -r HEAD~1...HEAD clang/test/Analysis/LifetimeSafety/benchmark.py `` View the diff from darker here. ``diff --- benchmark.py2025-07-18 19:49:32.00 + +++ benchmark.py2025-07-18 19:51:58.973643 + @@ -115,20 +115,20 @@ return "// Nesting depth must be positive." cpp_code = "struct MyObj { int id; ~MyObj() {} };\n\n" cpp_code += f"void nested_loops_{n}() {{\n" cpp_code += "MyObj* p = nullptr;\n" - + for i in range(n): indent = "" * (i + 1) cpp_code += f"{indent}for(int i{i}=0; i{i}<2; ++i{i}) {{\n" cpp_code += f"{indent}MyObj s{i}; p = &s{i};\n" for i in range(n - 1, -1, -1): indent = "" * (i + 1) cpp_code += f"{indent}}}\n" - + cpp_code += "}\n" cpp_code += f"\nint main() {{ nested_loops_{n}(); return 0; }}\n" return cpp_code @@ -238,18 +238,18 @@ report.append(" ".join(row)) report.append("\n**Complexity Analysis:**\n") report.append("| Analysis Phase| Complexity O(nk) |") report.append("|:--|:--|") - + analysis_phases = { "Total Analysis": data["lifetime_ms"], "FactGenerator": data["fact_gen_ms"], "LoanPropagation": data["loan_prop_ms"], "ExpiredLoans": data["expired_loans_ms"], } - + for phase_name, y_data in analysis_phases.items(): k, delta = calculate_complexity(n_data, np.array(y_data)) if k is not None and delta is not None: complexity_str = f"O(n{k:.2f} ± {delta:.2f})" else: @@ -291,11 +291,13 @@ print(f"Compilation failed for N={n}!", file=sys.stderr) print(result.stderr, file=sys.stderr) return {} durations_us = analyze_trace_file(trace_file) -return {key.replace('_us', '_ms'): value / 1000.0 for key, value in durations_us.items()} +return { +key.replace("_us", "_ms"): value / 1000.0 for key, value in durations_us.items() +} if __name__ == "__main__": parser = argparse.ArgumentParser( description="Generate, compile, and benchmark C++ test cases for Clang's lifetime analysis." @@ -360,11 +362,11 @@ ) if durations_ms: results[test_name]["n"].append(n) for key, value in durations_ms.items(): results[test_name][key].append(value) - + print( f"Total Analysis: {human_readable_time(durations_ms['lifetime_ms'])} | " f"FactGen: {human_readable_time(durations_ms['fact_gen_ms'])} | " f"LoanProp: {human_readable_time(durations_ms['loan_prop_ms'])} | " f"ExpiredLoans: {human_readable_time(durations_ms['expired_loans_ms'])}" @@ -374,10 +376,10 @@ print("Generating Markdown Report...") print("=" * 80 + "\n") markdown_report = generate_markdown_report(results) print(markdown_report) - + report_filename = os.path.join(args.output_dir, "performance_report.md") with open(report_filename, "w") as f: f.write(markdown_report) print(f"Report saved to: {report_filename}") `` https://github.com/llvm/llvm-project/pull/149577 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] [llvm] release/21.x: [Hexagon][llvm-objdump] Improve disassembly of Hexagon bundles (#145807) (PR #149578)
llvmbot wrote: @MaskRay What do you think about merging this PR to the release branch? https://github.com/llvm/llvm-project/pull/149578 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [LifetimeSafety] Enhance benchmark script for ExpiredLoans analysis (PR #149577)
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/149577 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149564)
@@ -210,12 +229,17 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, } if (!I.Description.empty()) { -json::Value DescArray = json::Array(); -auto &DescArrayRef = *DescArray.getAsArray(); -DescArrayRef.reserve(I.Description.size()); -for (const auto &Comment : I.Description) - DescArrayRef.push_back(serializeComment(Comment)); -Obj["Description"] = DescArray; +Object Description = Object(); +// Skip straight to the FullComment's children +auto &Comments = I.Description.at(0).Children; +for (const auto &CommentInfo : Comments) { + json::Value Comment = serializeComment(*CommentInfo, Description); + // Paragraph comments might not be children + if (auto *ParagraphComment = + Comment.getAsObject()->get("ParagraphComment")) +insertComment(Description, *ParagraphComment, "ParagraphComments"); ilovepi wrote: yeah, rewording would be helpful. thanks https://github.com/llvm/llvm-project/pull/149564 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] LowerTypeTests: Start using !elf_section_properties metadata to mark CFI jump table sections. (PR #149261)
https://github.com/pcc edited https://github.com/llvm/llvm-project/pull/149261 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [AMDGPU] Add the code generation support for `llvm.[sin/cos].bf16` (PR #149631)
https://github.com/shiltian created https://github.com/llvm/llvm-project/pull/149631 This is a partial support because some other instructions have not been upstreamed yet. >From 76cf51351db63757e8caa1cf6c542dfd6d110978 Mon Sep 17 00:00:00 2001 From: Shilei Tian Date: Fri, 18 Jul 2025 21:52:34 -0400 Subject: [PATCH] [AMDGPU] Add the code generation support for `llvm.[sin/cos].bf16` This is a partial support because some other instructions have not been upstreamed yet. --- llvm/lib/Target/AMDGPU/SIISelLowering.cpp | 2 +- llvm/test/CodeGen/AMDGPU/llvm.cos.bf16.ll | 38 +++ llvm/test/CodeGen/AMDGPU/llvm.sin.bf16.ll | 38 +++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 llvm/test/CodeGen/AMDGPU/llvm.cos.bf16.ll create mode 100644 llvm/test/CodeGen/AMDGPU/llvm.sin.bf16.ll diff --git a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp index 79487dcec3525..181db6291b361 100644 --- a/llvm/lib/Target/AMDGPU/SIISelLowering.cpp +++ b/llvm/lib/Target/AMDGPU/SIISelLowering.cpp @@ -620,7 +620,7 @@ SITargetLowering::SITargetLowering(const TargetMachine &TM, // BF16 - VOP1 Actions. if (Subtarget->hasBF16TransInsts()) - setOperationAction(ISD::FDIV, MVT::bf16, Custom); + setOperationAction({ISD::FCOS, ISD::FSIN, ISD::FDIV}, MVT::bf16, Custom); setOperationAction({ISD::FP_TO_SINT, ISD::FP_TO_UINT}, MVT::f16, Promote); setOperationAction({ISD::FP_TO_SINT, ISD::FP_TO_UINT}, MVT::bf16, Promote); diff --git a/llvm/test/CodeGen/AMDGPU/llvm.cos.bf16.ll b/llvm/test/CodeGen/AMDGPU/llvm.cos.bf16.ll new file mode 100644 index 0..ced96ee98e0ad --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/llvm.cos.bf16.ll @@ -0,0 +1,38 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 +; RUN: llc -global-isel=0 -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1250 %s -o - | FileCheck -check-prefixes=GCN %s +; xUN: llc -global-isel=1 -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1250 -verify-machineinstrs %s -o - | FileCheck -check-prefix=GCN %s + +; FIXME: GlobalISel does not work with bf16 + +declare bfloat @llvm.cos.bf16(bfloat) #0 + +define amdgpu_kernel void @cos_bf16_constant_4(ptr addrspace(1) %out) #1 { +; GCN-LABEL: cos_bf16_constant_4: +; GCN: ; %bb.0: +; GCN-NEXT:s_load_b64 s[0:1], s[4:5], 0x0 +; GCN-NEXT:v_cos_bf16_e32 v0, 0x3f23 +; GCN-NEXT:v_mov_b32_e32 v1, 0 +; GCN-NEXT:s_wait_kmcnt 0x0 +; GCN-NEXT:global_store_b16 v1, v0, s[0:1] +; GCN-NEXT:s_endpgm + %cos = call bfloat @llvm.cos.bf16(bfloat 4.0) #0 + store bfloat %cos, ptr addrspace(1) %out, align 2 + ret void +} + +define amdgpu_kernel void @cos_bf16_constant_100(ptr addrspace(1) %out) #1 { +; GCN-LABEL: cos_bf16_constant_100: +; GCN: ; %bb.0: +; GCN-NEXT:s_load_b64 s[0:1], s[4:5], 0x0 +; GCN-NEXT:v_cos_bf16_e32 v0, 0x417f +; GCN-NEXT:v_mov_b32_e32 v1, 0 +; GCN-NEXT:s_wait_kmcnt 0x0 +; GCN-NEXT:global_store_b16 v1, v0, s[0:1] +; GCN-NEXT:s_endpgm + %cos = call bfloat @llvm.cos.bf16(bfloat 100.0) #0 + store bfloat %cos, ptr addrspace(1) %out, align 2 + ret void +} + +attributes #0 = { nounwind readnone } +attributes #1 = { nounwind } diff --git a/llvm/test/CodeGen/AMDGPU/llvm.sin.bf16.ll b/llvm/test/CodeGen/AMDGPU/llvm.sin.bf16.ll new file mode 100644 index 0..7a355a36b15bf --- /dev/null +++ b/llvm/test/CodeGen/AMDGPU/llvm.sin.bf16.ll @@ -0,0 +1,38 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 +; RUN: llc -global-isel=0 -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1250 %s -o - | FileCheck -check-prefixes=GCN %s +; xUN: llc -global-isel=1 -mtriple=amdgcn-amd-amdhsa -mcpu=gfx1250 -verify-machineinstrs %s -o - | FileCheck -check-prefix=GCN %s + +; FIXME: GlobalISel does not work with bf16 + +declare bfloat @llvm.sin.bf16(bfloat) #0 + +define amdgpu_kernel void @sin_bf16_constant_4(ptr addrspace(1) %out) #1 { +; GCN-LABEL: sin_bf16_constant_4: +; GCN: ; %bb.0: +; GCN-NEXT:s_load_b64 s[0:1], s[4:5], 0x0 +; GCN-NEXT:v_sin_bf16_e32 v0, 0x3f23 +; GCN-NEXT:v_mov_b32_e32 v1, 0 +; GCN-NEXT:s_wait_kmcnt 0x0 +; GCN-NEXT:global_store_b16 v1, v0, s[0:1] +; GCN-NEXT:s_endpgm + %sin = call bfloat @llvm.sin.bf16(bfloat 4.0) #0 + store bfloat %sin, ptr addrspace(1) %out, align 2 + ret void +} + +define amdgpu_kernel void @sin_bf16_constant_100(ptr addrspace(1) %out) #1 { +; GCN-LABEL: sin_bf16_constant_100: +; GCN: ; %bb.0: +; GCN-NEXT:s_load_b64 s[0:1], s[4:5], 0x0 +; GCN-NEXT:v_sin_bf16_e32 v0, 0x417f +; GCN-NEXT:v_mov_b32_e32 v1, 0 +; GCN-NEXT:s_wait_kmcnt 0x0 +; GCN-NEXT:global_store_b16 v1, v0, s[0:1] +; GCN-NEXT:s_endpgm + %sin = call bfloat @llvm.sin.bf16(bfloat 100.0) #0 + store bfloat %sin, ptr addrspace(1) %out, align 2 + ret void +} + +attributes #0 = { nounwind readnone } +attributes #1 = { nounwind } _
[llvm-branch-commits] [llvm] [AMDGPU] Add the code generation support for `llvm.[sin/cos].bf16` (PR #149631)
shiltian wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/149631?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#149631** https://app.graphite.dev/github/pr/llvm/llvm-project/149631?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/149631?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#149628** https://app.graphite.dev/github/pr/llvm/llvm-project/149628?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#149627** https://app.graphite.dev/github/pr/llvm/llvm-project/149627?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/149631 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] MC: Refactor FT_Align fragments when linker relaxation is enabled (PR #149465)
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/149465 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] MC: Refactor FT_Align fragments when linker relaxation is enabled (PR #149465)
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/149465 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [AMDGPU] Add the code generation support for `llvm.[sin/cos].bf16` (PR #149631)
https://github.com/changpeng approved this pull request. https://github.com/llvm/llvm-project/pull/149631 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
@@ -603,6 +630,14 @@ class ProfiledBinary { return ProbeDecoder.getInlinerDescForProbe(Probe); } + void addMMapNonTextEvent(MMapEvent MMap) { +MMapNonTextEvents.push_back(MMap); + } + + // Given a runtime address, canonicalize it to the virtual address in the + // binary. mingmingl-llvm wrote: Updated the comment to mention 'non-text' and added a TODO to consider unifying text vs non-text. I think it should be possible to do some refactoring, but not sure if we can completely get rid of a data-vs-text hint from caller side (e.g. executable's linking option may affect the code/data to segment mapping). https://github.com/llvm/llvm-project/pull/148013 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
@@ -370,6 +377,61 @@ PerfReaderBase::create(ProfiledBinary *Binary, PerfInputFile &PerfInput, return PerfReader; } +void PerfReaderBase::parseDataAccessPerfTraces( +StringRef DataAccessPerfTraceFile, std::optional PIDFilter) { + std::regex logRegex( + R"(^.*?PERF_RECORD_SAMPLE\(.*?\):\s*(\d+)\/(\d+):\s*(0x[0-9a-fA-F]+)\s+period:\s*\d+\s+addr:\s*(0x[0-9a-fA-F]+)$)"); + + auto BufferOrErr = MemoryBuffer::getFile(DataAccessPerfTraceFile); + std::error_code EC = BufferOrErr.getError(); + if (EC) +exitWithError("Failed to open perf trace file: " + DataAccessPerfTraceFile); + + assert(!SampleCounters.empty() && "Sample counters should not be empty!"); + SampleCounter &Counter = SampleCounters.begin()->second; + line_iterator LineIt(*BufferOrErr.get(), true); + for (; !LineIt.is_at_eof(); ++LineIt) { +StringRef Line = *LineIt; + +MMapEvent MMap; +if (Line.contains("PERF_RECORD_MMAP2")) { + if (PerfScriptReader::extractMMapEventForBinary(Binary, Line, MMap)) { +if (!MMap.MemProtectionFlag.contains("x")) { + Binary->addMMapNonTextEvent(MMap); +} + } + continue; +} + +// Skip lines that do not contain "PERF_RECORD_SAMPLE". +if (!Line.contains("PERF_RECORD_SAMPLE")) { + continue; +} + +std::smatch matches; +const std::string LineStr = Line.str(); + +if (std::regex_search(LineStr.begin(), LineStr.end(), matches, logRegex)) { + if (matches.size() != 5) +continue; + + const int32_t PID = std::stoi(matches[1].str()); + if (PIDFilter && *PIDFilter != PID) { mingmingl-llvm wrote: done. https://github.com/llvm/llvm-project/pull/148013 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
@@ -540,6 +540,22 @@ void ProfileGenerator::generateLineNumBasedProfile() { // Fill in boundary sample counts as well as call site samples for calls populateBoundarySamplesForAllFunctions(SC.BranchCounter); + // For each instruction with vtable accesses, get its symbolized inline + // stack, and add the vtable counters to the function samples. + for (const auto &[IpData, Count] : SC.DataAccessCounter) { +uint64_t InstAddr = IpData.first; +const SampleContextFrameVector &FrameVec = +Binary->getCachedFrameLocationStack(InstAddr, false); +if (!FrameVec.empty()) { + FunctionSamples &FunctionProfile = + getLeafProfileAndAddTotalSamples(FrameVec, 0); + LineLocation Loc( + FrameVec.back().Location.LineOffset, + getBaseDiscriminator(FrameVec.back().Location.Discriminator)); + FunctionProfile.getTypeSamplesAt(Loc)[FunctionId(IpData.second)] += Count; mingmingl-llvm wrote: done with a slight modification, by adding a helper function `FunctionSamples::addTypeSamplesAt` and calling that function. https://github.com/llvm/llvm-project/pull/148013 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
@@ -0,0 +1,18 @@ +RUN: llvm-profgen --perfscript=%p/Inputs/lbr-perf-for-dap.script --data-access-profile=%p/Inputs/dap-perf-trace.txt \ +RUN: --binary=%p/Inputs/dap.perfbin --format=text --pid=3446532 \ mingmingl-llvm wrote: done. Somehow my previous commit left the `dap.bin` executable as an empty file. Luckily I found the executable in one of the working directory so just copied it here. https://github.com/llvm/llvm-project/pull/148013 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
@@ -67,6 +67,11 @@ static cl::opt DebugBinPath( "from it instead of the executable binary."), cl::cat(ProfGenCategory)); +static cl::opt DataAccessProfileFilename( +"data-access-profile", cl::value_desc("data-access-profile"), +cl::desc("Path of the data access profile to be generated."), mingmingl-llvm wrote: done. https://github.com/llvm/llvm-project/pull/148013 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
https://github.com/mingmingl-llvm commented: thanks for reviews! PTAL. https://github.com/llvm/llvm-project/pull/148013 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
@@ -946,6 +978,14 @@ SampleContextFrameVector ProfiledBinary::symbolize(const InstructionPointer &IP, return CallStack; } +StringRef ProfiledBinary::symbolizeDataAddress(uint64_t Address) { + DIGlobal DataDIGlobal = unwrapOrError( + Symbolizer->symbolizeData(SymbolizerPath.str(), {Address, 0}), mingmingl-llvm wrote: LLVMSymbolizer's symbolize* interfaces [1] require a struct of `object::SectionedAddress` [2] to symbolize an address, like, they don't take an integer of address alone. Chasing down the calls [3], `sectionIndex` field isn't used so its value doesn't matter [4]. Upon this question, it's better to use `UndefSection` [5] here. Added a static helper function `getSectionedAddress` for this purpose, and use it for both code and data inside `ProfiledBinary` class. [1] for [data](https://github.com/llvm/llvm-project/blob/13f7786f72d13a84dfc3d49d87a70e6a05f21fd4/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h#L98-L104) and [code](https://github.com/llvm/llvm-project/blob/13f7786f72d13a84dfc3d49d87a70e6a05f21fd4/llvm/include/llvm/DebugInfo/Symbolize/Symbolize.h#L80-L87) [2] https://github.com/llvm/llvm-project/blob/13f7786f72d13a84dfc3d49d87a70e6a05f21fd4/llvm/include/llvm/Object/ObjectFile.h#L146-L151 [3] https://github.com/llvm/llvm-project/blob/13f7786f72d13a84dfc3d49d87a70e6a05f21fd4/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp#L155-L178 [4] https://github.com/llvm/llvm-project/blob/13f7786f72d13a84dfc3d49d87a70e6a05f21fd4/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp#L1753-L1766 [5] https://github.com/llvm/llvm-project/blob/13f7786f72d13a84dfc3d49d87a70e6a05f21fd4/llvm/include/llvm/Object/ObjectFile.h#L146-L147 https://github.com/llvm/llvm-project/pull/148013 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
@@ -370,6 +377,61 @@ PerfReaderBase::create(ProfiledBinary *Binary, PerfInputFile &PerfInput, return PerfReader; } +void PerfReaderBase::parseDataAccessPerfTraces( +StringRef DataAccessPerfTraceFile, std::optional PIDFilter) { + std::regex logRegex( + R"(^.*?PERF_RECORD_SAMPLE\(.*?\):\s*(\d+)\/(\d+):\s*(0x[0-9a-fA-F]+)\s+period:\s*\d+\s+addr:\s*(0x[0-9a-fA-F]+)$)"); + + auto BufferOrErr = MemoryBuffer::getFile(DataAccessPerfTraceFile); + std::error_code EC = BufferOrErr.getError(); + if (EC) +exitWithError("Failed to open perf trace file: " + DataAccessPerfTraceFile); + + assert(!SampleCounters.empty() && "Sample counters should not be empty!"); + SampleCounter &Counter = SampleCounters.begin()->second; + line_iterator LineIt(*BufferOrErr.get(), true); + for (; !LineIt.is_at_eof(); ++LineIt) { +StringRef Line = *LineIt; + +MMapEvent MMap; +if (Line.contains("PERF_RECORD_MMAP2")) { + if (PerfScriptReader::extractMMapEventForBinary(Binary, Line, MMap)) { +if (!MMap.MemProtectionFlag.contains("x")) { + Binary->addMMapNonTextEvent(MMap); +} + } + continue; +} + +// Skip lines that do not contain "PERF_RECORD_SAMPLE". +if (!Line.contains("PERF_RECORD_SAMPLE")) { + continue; +} + +std::smatch matches; +const std::string LineStr = Line.str(); + +if (std::regex_search(LineStr.begin(), LineStr.end(), matches, logRegex)) { mingmingl-llvm wrote: done. https://github.com/llvm/llvm-project/pull/148013 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
@@ -370,6 +377,61 @@ PerfReaderBase::create(ProfiledBinary *Binary, PerfInputFile &PerfInput, return PerfReader; } +void PerfReaderBase::parseDataAccessPerfTraces( +StringRef DataAccessPerfTraceFile, std::optional PIDFilter) { + std::regex logRegex( mingmingl-llvm wrote: done with llvm::Regex, which uses the POSIX extended regular expression format by default. The regex string literal is also simpler this way. https://github.com/llvm/llvm-project/pull/148013 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
@@ -572,6 +579,13 @@ class PerfReaderBase { // Entry of the reader to parse multiple perf traces virtual void parsePerfTraces() = 0; + + // Parse the from the data access perf trace file, + // and accummuate the data access count for each pair. mingmingl-llvm wrote: done, thanks for the catch. https://github.com/llvm/llvm-project/pull/148013 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
@@ -370,6 +377,61 @@ PerfReaderBase::create(ProfiledBinary *Binary, PerfInputFile &PerfInput, return PerfReader; } +void PerfReaderBase::parseDataAccessPerfTraces( +StringRef DataAccessPerfTraceFile, std::optional PIDFilter) { + std::regex logRegex( + R"(^.*?PERF_RECORD_SAMPLE\(.*?\):\s*(\d+)\/(\d+):\s*(0x[0-9a-fA-F]+)\s+period:\s*\d+\s+addr:\s*(0x[0-9a-fA-F]+)$)"); + + auto BufferOrErr = MemoryBuffer::getFile(DataAccessPerfTraceFile); + std::error_code EC = BufferOrErr.getError(); + if (EC) mingmingl-llvm wrote: done by returning error_code in this function. https://github.com/llvm/llvm-project/pull/148013 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
@@ -598,6 +612,12 @@ class PerfScriptReader : public PerfReaderBase { // Entry of the reader to parse multiple perf traces void parsePerfTraces() override; + + // Parse a single line of a PERF_RECORD_MMAP event looking for a + // mapping between the binary name and its memory layout. + static bool extractMMapEventForBinary(ProfiledBinary *Binary, StringRef Line, mingmingl-llvm wrote: Sure. How does it sound if I do this in a separate change to minimize the code diff? Added a TODO in the comment if that's fine. https://github.com/llvm/llvm-project/pull/148013 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
@@ -946,6 +978,14 @@ SampleContextFrameVector ProfiledBinary::symbolize(const InstructionPointer &IP, return CallStack; } +StringRef ProfiledBinary::symbolizeDataAddress(uint64_t Address) { + DIGlobal DataDIGlobal = unwrapOrError( + Symbolizer->symbolizeData(SymbolizerPath.str(), {Address, 0}), + SymbolizerPath); + auto It = NameStrings.insert(DataDIGlobal.Name); + return StringRef(*It.first); mingmingl-llvm wrote: hmm not really. The original `It` is actually of type `pair`, I revised the code slightly to make the types and names more explicit. https://github.com/llvm/llvm-project/pull/148013 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
@@ -276,6 +286,19 @@ class ProfiledBinary { // String table owning function name strings created from the symbolizer. std::unordered_set NameStrings; + // MMap events for PT_LOAD segments without 'x' memory protection flag. + SmallVector MMapNonTextEvents; + + // Records the file offset, file size and virtual address of program headers. + struct PhdrInfo { +uint64_t FileOffset; +uint64_t FileSz; +uint64_t vAddr; mingmingl-llvm wrote: got it. My original thinking was that the `VA` prefix in `VAddr` felt a bit uncommon and harder to quickly parse. Now I renamed the field to `VirtualAddr`. https://github.com/llvm/llvm-project/pull/148013 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm-profgen] Extend llvm-profgen to generate vtable profiles with data access events. (PR #148013)
https://github.com/mingmingl-llvm edited https://github.com/llvm/llvm-project/pull/148013 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm][AsmPrinter] Emit call graph section (PR #87576)
@@ -1654,6 +1654,94 @@ void AsmPrinter::emitStackUsage(const MachineFunction &MF) { *StackUsageStream << "static\n"; } +/// Extracts a generalized numeric type identifier of a Function's type from +/// type metadata. Returns null if metadata cannot be found. +static ConstantInt *extractNumericCGTypeId(const Function &F) { + SmallVector Types; + F.getMetadata(LLVMContext::MD_type, Types); + for (const auto &Type : Types) { +if (hasGeneralizedMDString(Type)) { + MDString *MDGeneralizedTypeId = cast(Type->getOperand(1)); + uint64_t TypeIdVal = llvm::MD5Hash(MDGeneralizedTypeId->getString()); + IntegerType *Int64Ty = Type::getInt64Ty(F.getContext()); + return ConstantInt::get(Int64Ty, TypeIdVal); +} + } + + return nullptr; +} + +/// Emits .callgraph section. +void AsmPrinter::emitCallGraphSection(const MachineFunction &MF, + FunctionInfo &FuncInfo) { + if (!MF.getTarget().Options.EmitCallGraphSection) +return; + + // Switch to the call graph section for the function + MCSection *FuncCGSection = + getObjFileLowering().getCallGraphSection(*getCurrentSection()); + assert(FuncCGSection && "null callgraph section"); + OutStreamer->pushSection(); + OutStreamer->switchSection(FuncCGSection); + + // Emit format version number. + OutStreamer->emitInt64(CallGraphSectionFormatVersion::V_0); + + // Emit function's self information, which is composed of: + // 1) FunctionEntryPc + // 2) FunctionKind: Whether the function is indirect target, and if so, + // whether its type id is known. + // 3) FunctionTypeId: Emit only when the function is an indirect target + // and its type id is known. + + // Emit function entry pc. + const MCSymbol *FunctionSymbol = getFunctionBegin(); + OutStreamer->emitSymbolValue(FunctionSymbol, TM.getProgramPointerSize()); + + // If this function has external linkage or has its address taken and + // it is not a callback, then anything could call it. + const Function &F = MF.getFunction(); + bool IsIndirectTarget = + !F.hasLocalLinkage() || F.hasAddressTaken(nullptr, +/*IgnoreCallbackUses=*/true, +/*IgnoreAssumeLikeCalls=*/true, +/*IgnoreLLVMUsed=*/false); + + // FIXME: FunctionKind takes a few values but emitted as a 64-bit value. + // Can be optimized to occupy 2 bits instead. + // Emit function kind, and type id if available. + if (!IsIndirectTarget) { +OutStreamer->emitInt64( + static_cast(FunctionInfo::FunctionKind::NOT_INDIRECT_TARGET)); + } else { +const auto *TypeId = extractNumericCGTypeId(F); +if (TypeId) { + OutStreamer->emitInt64(static_cast( + FunctionInfo::FunctionKind::INDIRECT_TARGET_KNOWN_TID)); + OutStreamer->emitInt64(TypeId->getZExtValue()); +} else { + OutStreamer->emitInt64(static_cast( + FunctionInfo::FunctionKind::INDIRECT_TARGET_UNKNOWN_TID)); +} + } + + // Emit callsite labels, where each element is a pair of type id and + // indirect callsite pc. + const auto &CallSiteLabels = FuncInfo.CallSiteLabels; + + // Emit the count of pairs. + OutStreamer->emitInt64(CallSiteLabels.size()); + + // Emit the type id and call site label pairs. Prabhuk wrote: Ack. Removed the redundant comments. PTAL. https://github.com/llvm/llvm-project/pull/87576 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] release/21.x: Revert "Move python binding tests to lit framework" (#149012) (PR #149570)
https://github.com/DeinAlptraum approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/149570 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] Driver, CodeGen: Handle -falign-functions, -fno-align-functions and -falign-functions=1 correctly. (PR #149445)
MaskRay wrote: Can use some description what is the correct behavior. Perhaps https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-falign-functions > If n is not specified or is zero, use a machine-dependent default. https://github.com/llvm/llvm-project/pull/149445 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] [llvm] release/21.x: [Hexagon][llvm-objdump] Improve disassembly of Hexagon bundles (#145807) (PR #149578)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/149578 Backport ac7ceb3 Requested by: @quic-areg >From 00a9a73c8f84dbdc118e9c6dd8950617d5806544 Mon Sep 17 00:00:00 2001 From: quic-areg Date: Fri, 18 Jul 2025 10:27:59 -0500 Subject: [PATCH] [Hexagon][llvm-objdump] Improve disassembly of Hexagon bundles (#145807) Hexagon instructions are VLIW "bundles" of up to four instruction words encoded as a single MCInst with operands for each sub-instruction. Previously, the disassembler's getInstruction() returned the full bundle, which made it difficult to work with llvm-objdump. For example, since all instructions are bundles, and bundles do not branch, branch targets could not be printed. This patch modifies the Hexagon disassembler to return individual sub-instructions instead of entire bundles, enabling correct printing of branch targets and relocations. It also introduces `MCDisassembler::getInstructionBundle` for cases where the full bundle is still needed. By default, llvm-objdump separates instructions with newlines. However, this does not work well for Hexagon syntax: { inst1 inst2 inst3 inst4 } :endloop0 Instructions may be followed by a closing brace, a closing brace with `:endloop`, or a newline. Branches must appear within the braces. To address this, `PrettyPrinter::getInstructionSeparator()` is added and overridden for Hexagon. (cherry picked from commit ac7ceb3dabfac548caa993e7b77bbadc78af4464) --- lld/test/ELF/hexagon-plt.s| 18 +- lld/test/ELF/hexagon-shared.s | 2 +- lld/test/ELF/hexagon-tls-gd-xform.s | 4 +- .../llvm/MC/MCDisassembler/MCDisassembler.h | 12 ++ .../Disassembler/HexagonDisassembler.cpp | 109 --- .../MCTargetDesc/HexagonInstPrinter.cpp | 34 ++-- .../MCTargetDesc/HexagonMCTargetDesc.cpp | 19 +- llvm/test/MC/Hexagon/two_ext.s| 4 +- .../ELF/Hexagon/hexagon-bundles.s | 47 + llvm/tools/llvm-mc/Disassembler.cpp | 6 +- llvm/tools/llvm-objdump/llvm-objdump.cpp | 180 +++--- 11 files changed, 297 insertions(+), 138 deletions(-) create mode 100644 llvm/test/tools/llvm-objdump/ELF/Hexagon/hexagon-bundles.s diff --git a/lld/test/ELF/hexagon-plt.s b/lld/test/ELF/hexagon-plt.s index 679de82923a72..780dc434a6698 100644 --- a/lld/test/ELF/hexagon-plt.s +++ b/lld/test/ELF/hexagon-plt.s @@ -30,31 +30,31 @@ # DIS: <_start>: ## Direct call ## Call foo directly -# DIS-NEXT: { call 0x2003c } +# DIS-NEXT: { call 0x2003c } ## Call bar via plt -# DIS-NEXT: { call 0x20060 } +# DIS-NEXT: { call 0x20060 } ## Call weak via plt -# DIS-NEXT: { call 0x20070 } +# DIS-NEXT: { call 0x20070 } # DIS-NEXT: { immext(#0) ## Call foo directly -# DIS-NEXT: if (p0) jump:nt 0x2003c } +# DIS-NEXT: if (p0) jump:nt 0x2003c } # DIS-NEXT: { immext(#64) ## Call bar via plt -# DIS-NEXT: if (p0) jump:nt 0x20060 } +# DIS-NEXT: if (p0) jump:nt 0x20060 } # DIS-NEXT: { immext(#64) ## Call weak via plt -# DIS-NEXT: if (p0) jump:nt 0x20070 } +# DIS-NEXT: if (p0) jump:nt 0x20070 } # DIS-NEXT: { immext(#0) ## Call foo directly -# DIS-NEXT: r0 = #0 ; jump 0x2003c } +# DIS-NEXT: r0 = #0 ; jump 0x2003c } # DIS-NEXT: { immext(#0) ## Call bar via plt -# DIS-NEXT: r0 = #0 ; jump 0x20060 } +# DIS-NEXT: r0 = #0 ; jump 0x20060 } # DIS-NEXT: { immext(#0) ## Call weak via plt -# DIS-NEXT: r0 = #0 ; jump 0x20070 } +# DIS-NEXT: r0 = #0 ; jump 0x20070 } # DIS: : # DIS-NEXT: 2003c: diff --git a/lld/test/ELF/hexagon-shared.s b/lld/test/ELF/hexagon-shared.s index cc62662d278e2..7f7390f1fa8d8 100644 --- a/lld/test/ELF/hexagon-shared.s +++ b/lld/test/ELF/hexagon-shared.s @@ -88,7 +88,7 @@ pvar: # PLT-NEXT: jumpr r28 } # TEXT: bc 00 01 00 000100bc -# TEXT: { call 0x10300 } +# TEXT: { call 0x10300 } # TEXT: if (p0) jump:nt 0x10300 # TEXT: r0 = #0 ; jump 0x10300 # TEXT: r0 = add(r1,##-65548) diff --git a/lld/test/ELF/hexagon-tls-gd-xform.s b/lld/test/ELF/hexagon-tls-gd-xform.s index 65aeb118fcb33..ade54e8a16fad 100644 --- a/lld/test/ELF/hexagon-tls-gd-xform.s +++ b/lld/test/ELF/hexagon-tls-gd-xform.s @@ -18,10 +18,10 @@ _start: .ifdef GDPLT call x@gdplt -# CHECK_GDPLT: 101ec: { call 0x10220 } +# CHECK_GDPLT: 101ec: { call 0x10220 <__tls_get_addr@plt> } .else call x -# CHECK: 101b8: { call 0x101e0 } +# CHECK: 101b8: { call 0x101e0 } .endif # CHECK_GDPLT:10220: { immext(#0x20040) diff --git a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h index 3a7ca1a69ab85..cae2fbcac1fef 100644 --- a/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h +++ b/llvm/include/llvm/MC/MCDisassembler/MCDisassembler.h @@ -136,6 +136,18 @@ class LLVM_ABI MCDisassembler { ArrayRef Bytes, uint64_t Address,
[llvm-branch-commits] [lld] [llvm] release/21.x: [Hexagon][llvm-objdump] Improve disassembly of Hexagon bundles (#145807) (PR #149578)
https://github.com/llvmbot milestoned https://github.com/llvm/llvm-project/pull/149578 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] add-loan-analysis-to-benchmark (PR #149577)
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/149577 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] add-loan-analysis-to-benchmark (PR #149577)
usx95 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/149577?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#149577** https://app.graphite.dev/github/pr/llvm/llvm-project/149577?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/149577?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#148712** https://app.graphite.dev/github/pr/llvm/llvm-project/148712?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/>: 1 other dependent PR ([#148976](https://github.com/llvm/llvm-project/pull/148976) https://app.graphite.dev/github/pr/llvm/llvm-project/148976?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/>) * **#149158** https://app.graphite.dev/github/pr/llvm/llvm-project/149158?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * **#149199** https://app.graphite.dev/github/pr/llvm/llvm-project/149199?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/149577 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [LifetimeSafety] Enhance benchmark script for end timing (PR #149577)
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/149577 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [llvm] Introduce callee_type metadata (PR #87573)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87573 >From a8a5848885e12c771f12cfa33b4dbc6a0272e925 Mon Sep 17 00:00:00 2001 From: Prabhuk Date: Mon, 22 Apr 2024 11:34:04 -0700 Subject: [PATCH 01/23] Update clang/lib/CodeGen/CodeGenModule.cpp Cleaner if checks. Co-authored-by: Matt Arsenault --- clang/lib/CodeGen/CodeGenModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index e19bbee996f58..ff1586d2fa8ab 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2711,7 +2711,7 @@ void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, void CodeGenModule::CreateFunctionTypeMetadataForIcall(const QualType &QT, llvm::CallBase *CB) { // Only if needed for call graph section and only for indirect calls. - if (!(CodeGenOpts.CallGraphSection && CB && CB->isIndirectCall())) + if (!CodeGenOpts.CallGraphSection || !CB || !CB->isIndirectCall()) return; auto *MD = CreateMetadataIdentifierGeneralized(QT); >From 019b2ca5e1c263183ed114e0b967b4e77b4a17a8 Mon Sep 17 00:00:00 2001 From: Prabhuk Date: Mon, 22 Apr 2024 11:34:31 -0700 Subject: [PATCH 02/23] Update clang/lib/CodeGen/CodeGenModule.cpp Update the comments as suggested. Co-authored-by: Matt Arsenault --- clang/lib/CodeGen/CodeGenModule.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index ff1586d2fa8ab..5635a87d2358a 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2680,9 +2680,9 @@ void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, bool EmittedMDIdGeneralized = false; if (CodeGenOpts.CallGraphSection && (!F->hasLocalLinkage() || - F->getFunction().hasAddressTaken(nullptr, /* IgnoreCallbackUses */ true, -/* IgnoreAssumeLikeCalls */ true, -/* IgnoreLLVMUsed */ false))) { + F->getFunction().hasAddressTaken(nullptr, /*IgnoreCallbackUses=*/ true, +/*IgnoreAssumeLikeCalls=*/ true, +/*IgnoreLLVMUsed=*/ false))) { F->addTypeMetadata(0, CreateMetadataIdentifierGeneralized(FD->getType())); EmittedMDIdGeneralized = true; } >From 99242900c51778abd4b7e7f4361b09202b7abcda Mon Sep 17 00:00:00 2001 From: Prabhuk Date: Mon, 29 Apr 2024 11:53:40 -0700 Subject: [PATCH 03/23] dyn_cast to isa Created using spr 1.3.6-beta.1 --- clang/lib/CodeGen/CGCall.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 526a63b24ff83..45033ced1d834 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -5713,8 +5713,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, if (callOrInvoke && *callOrInvoke && (*callOrInvoke)->isIndirectCall()) { if (const FunctionDecl *FD = dyn_cast_or_null(TargetDecl)) { // Type id metadata is set only for C/C++ contexts. -if (dyn_cast(FD) || dyn_cast(FD) || -dyn_cast(FD)) { +if (isa(FD) || isa(FD) || +isa(FD)) { CGM.CreateFunctionTypeMetadataForIcall(FD->getType(), *callOrInvoke); } } >From 24882b15939b781bcf28d87fdf4f6e8834b6cfde Mon Sep 17 00:00:00 2001 From: prabhukr Date: Tue, 10 Dec 2024 14:54:27 -0800 Subject: [PATCH 04/23] Address review comments. Break llvm and clang patches. Created using spr 1.3.6-beta.1 --- llvm/lib/IR/Verifier.cpp | 7 +++ llvm/test/Verifier/operand-bundles.ll | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 0ad7ba555bfad..b72672e7b8e56 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -3707,10 +3707,9 @@ void Verifier::visitCallBase(CallBase &Call) { if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) visitIntrinsicCall(ID, Call); - // Verify that a callsite has at most one "deopt", at most one "funclet", at - // most one "gc-transition", at most one "cfguardtarget", at most one "type", - // at most one "preallocated" operand bundle, and at most one "ptrauth" - // operand bundle. + // Verify that a callsite has at most one operand bundle for each of the + // following: "deopt", "funclet", "gc-transition", "cfguardtarget", "type", + // "preallocated", and "ptrauth". bool FoundDeoptBundle = false, FoundFuncletBundle = false, FoundGCTransitionBundle = false, FoundCFGuardTargetBundle = false, FoundPreallocatedBundle = false, FoundGCLiveBundle = false, diff --git a/llvm/test/Verifier/operand-bundles.ll b/llvm/t
[llvm-branch-commits] [llvm] [llvm] Add option to emit `callgraph` section (PR #87574)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87574 >From 1d7ee612e408ee7e64e984eb08e6d7089a435d09 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Sun, 2 Feb 2025 00:58:49 + Subject: [PATCH 1/7] Simplify MIR test. Created using spr 1.3.6-beta.1 --- .../CodeGen/MIR/X86/call-site-info-typeid.mir | 21 ++- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir index 5ab797bfcc18f..a99ee50a608fb 100644 --- a/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir +++ b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir @@ -8,11 +8,6 @@ # CHECK-NEXT: 123456789 } --- | - ; ModuleID = 'test.ll' - source_filename = "test.ll" - target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - target triple = "x86_64-unknown-linux-gnu" - define dso_local void @foo(i8 signext %a) { entry: ret void @@ -21,10 +16,10 @@ define dso_local i32 @main() { entry: %retval = alloca i32, align 4 -%fp = alloca void (i8)*, align 8 -store i32 0, i32* %retval, align 4 -store void (i8)* @foo, void (i8)** %fp, align 8 -%0 = load void (i8)*, void (i8)** %fp, align 8 +%fp = alloca ptr, align 8 +store i32 0, ptr %retval, align 4 +store ptr @foo, ptr %fp, align 8 +%0 = load ptr, ptr %fp, align 8 call void %0(i8 signext 97) ret i32 0 } @@ -42,12 +37,8 @@ body: | name:main tracksRegLiveness: true stack: - - { id: 0, name: retval, type: default, offset: 0, size: 4, alignment: 4, - stack-id: default, callee-saved-register: '', callee-saved-restored: true, - debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } - - { id: 1, name: fp, type: default, offset: 0, size: 8, alignment: 8, - stack-id: default, callee-saved-register: '', callee-saved-restored: true, - debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } + - { id: 0, name: retval, size: 4, alignment: 4 } + - { id: 1, name: fp, size: 8, alignment: 8 } callSites: - { bb: 0, offset: 6, fwdArgRegs: [], typeId: 123456789 } >From 86e2c9dc37170499252ed50c6bbef2931e106fbb Mon Sep 17 00:00:00 2001 From: prabhukr Date: Thu, 13 Mar 2025 01:03:40 + Subject: [PATCH 2/7] Add requested tests part 1. Created using spr 1.3.6-beta.1 --- ...te-info-ambiguous-indirect-call-typeid.mir | 145 ++ .../call-site-info-direct-calls-typeid.mir| 145 ++ 2 files changed, 290 insertions(+) create mode 100644 llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir create mode 100644 llvm/test/CodeGen/MIR/X86/call-site-info-direct-calls-typeid.mir diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir new file mode 100644 index 0..9d1b099cc9093 --- /dev/null +++ b/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir @@ -0,0 +1,145 @@ +# Test MIR printer and parser for type id field in callSites. It is used +# for propogating call site type identifiers to emit in the call graph section. + +# RUN: llc --call-graph-section %s -run-pass=none -o - | FileCheck %s +# CHECK: name: main +# CHECK: callSites: +# CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [] +# CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: +# CHECK-NEXT: 1234567890 } + +--- | + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef i32 @_Z3addii(i32 noundef %a, i32 noundef %b) #0 !type !6 !type !6 { + entry: +%a.addr = alloca i32, align 4 +%b.addr = alloca i32, align 4 +store i32 %a, ptr %a.addr, align 4 +store i32 %b, ptr %b.addr, align 4 +%0 = load i32, ptr %a.addr, align 4 +%1 = load i32, ptr %b.addr, align 4 +%add = add nsw i32 %0, %1 +ret i32 %add + } + + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef i32 @_Z8multiplyii(i32 noundef %a, i32 noundef %b) #0 !type !6 !type !6 { + entry: +%a.addr = alloca i32, align 4 +%b.addr = alloca i32, align 4 +store i32 %a, ptr %a.addr, align 4 +store i32 %b, ptr %b.addr, align 4 +%0 = load i32, ptr %a.addr, align 4 +%1 = load i32, ptr %b.addr, align 4 +%mul = mul nsw i32 %0, %1 +ret i32 %mul + } + + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef ptr @_Z13get_operationb(i1 noundef zeroext %is_addition) #0 !type !7 !type !7 { + entry: +%is_addition.addr = alloca i8, align 1 +%storedv = zext i1 %is_addition to i8 +store i8 %storedv, ptr %is_addition.addr, align 1 +%0 = load i8, ptr %is_addition.addr, align 1 +%loadedv = trunc i8 %0 to i1 +br i1 %loade
[llvm-branch-commits] [llvm] [llvm][AsmPrinter] Emit call graph section (PR #87576)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87576 >From 6b67376bd5e1f21606017c83cc67f2186ba36a33 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Thu, 13 Mar 2025 01:41:04 + Subject: [PATCH 1/5] Updated the test as reviewers suggested. Created using spr 1.3.6-beta.1 --- llvm/test/CodeGen/X86/call-graph-section.ll | 66 +++ llvm/test/CodeGen/call-graph-section.ll | 73 - 2 files changed, 66 insertions(+), 73 deletions(-) create mode 100644 llvm/test/CodeGen/X86/call-graph-section.ll delete mode 100644 llvm/test/CodeGen/call-graph-section.ll diff --git a/llvm/test/CodeGen/X86/call-graph-section.ll b/llvm/test/CodeGen/X86/call-graph-section.ll new file mode 100644 index 0..a77a2b8051ed3 --- /dev/null +++ b/llvm/test/CodeGen/X86/call-graph-section.ll @@ -0,0 +1,66 @@ +;; Tests that we store the type identifiers in .callgraph section of the binary. + +; RUN: llc --call-graph-section -filetype=obj -o - < %s | \ +; RUN: llvm-readelf -x .callgraph - | FileCheck %s + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local void @foo() #0 !type !4 { +entry: + ret void +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local i32 @bar(i8 signext %a) #0 !type !5 { +entry: + %a.addr = alloca i8, align 1 + store i8 %a, ptr %a.addr, align 1 + ret i32 0 +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local ptr @baz(ptr %a) #0 !type !6 { +entry: + %a.addr = alloca ptr, align 8 + store ptr %a, ptr %a.addr, align 8 + ret ptr null +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local void @main() #0 !type !7 { +entry: + %retval = alloca i32, align 4 + %fp_foo = alloca ptr, align 8 + %a = alloca i8, align 1 + %fp_bar = alloca ptr, align 8 + %fp_baz = alloca ptr, align 8 + store i32 0, ptr %retval, align 4 + store ptr @foo, ptr %fp_foo, align 8 + %0 = load ptr, ptr %fp_foo, align 8 + call void (...) %0() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] + store ptr @bar, ptr %fp_bar, align 8 + %1 = load ptr, ptr %fp_bar, align 8 + %2 = load i8, ptr %a, align 1 + %call = call i32 %1(i8 signext %2) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] + store ptr @baz, ptr %fp_baz, align 8 + %3 = load ptr, ptr %fp_baz, align 8 + %call1 = call ptr %3(ptr %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] + call void @foo() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] + %4 = load i8, ptr %a, align 1 + %call2 = call i32 @bar(i8 signext %4) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] + %call3 = call ptr @baz(ptr %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] + ret void +} + +;; Check that the numeric type id (md5 hash) for the below type ids are emitted +;; to the callgraph section. + +; CHECK: Hex dump of section '.callgraph': + +; CHECK-DAG: 2444f731 f5eecb3e +!4 = !{i64 0, !"_ZTSFvE.generalized"} +; CHECK-DAG: 5486bc59 814b8e30 +!5 = !{i64 0, !"_ZTSFicE.generalized"} +; CHECK-DAG: 7ade6814 f897fd77 +!6 = !{i64 0, !"_ZTSFPvS_E.generalized"} +; CHECK-DAG: caaf769a 600968fa +!7 = !{i64 0, !"_ZTSFiE.generalized"} diff --git a/llvm/test/CodeGen/call-graph-section.ll b/llvm/test/CodeGen/call-graph-section.ll deleted file mode 100644 index bb158d11e82c9..0 --- a/llvm/test/CodeGen/call-graph-section.ll +++ /dev/null @@ -1,73 +0,0 @@ -; Tests that we store the type identifiers in .callgraph section of the binary. - -; RUN: llc --call-graph-section -filetype=obj -o - < %s | \ -; RUN: llvm-readelf -x .callgraph - | FileCheck %s - -target triple = "x86_64-unknown-linux-gnu" - -define dso_local void @foo() #0 !type !4 { -entry: - ret void -} - -define dso_local i32 @bar(i8 signext %a) #0 !type !5 { -entry: - %a.addr = alloca i8, align 1 - store i8 %a, i8* %a.addr, align 1 - ret i32 0 -} - -define dso_local i32* @baz(i8* %a) #0 !type !6 { -entry: - %a.addr = alloca i8*, align 8 - store i8* %a, i8** %a.addr, align 8 - ret i32* null -} - -define dso_local i32 @main() #0 !type !7 { -entry: - %retval = alloca i32, align 4 - %fp_foo = alloca void (...)*, align 8 - %a = alloca i8, align 1 - %fp_bar = alloca i32 (i8)*, align 8 - %fp_baz = alloca i32* (i8*)*, align 8 - store i32 0, i32* %retval, align 4 - store void (...)* bitcast (void ()* @foo to void (...)*), void (...)** %fp_foo, align 8 - %0 = load void (...)*, void (...)** %fp_foo, align 8 - call void (...) %0() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] - store i32 (i8)* @bar, i32 (i8)** %fp_bar, align 8 - %1 = load i32 (i8)*, i32 (i8)** %fp_bar, align 8 - %2 = load i8, i8* %a, align 1 - %call = call i32 %1(i8 signext %2) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] - store i32* (i8*)* @baz, i32* (i8*)** %fp_baz, align 8 - %3 = load i32* (i8*)*, i32* (i8*)** %fp_baz, align 8 - %call1 = call i32* %3(i8* %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] - call void @foo() [ "callee_type"(meta
[llvm-branch-commits] [llvm] [llvm] Extract and propagate indirect call type id (PR #87575)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87575 >From 1a8d810d352fbe84c0521c7614689b60ade693c8 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Tue, 19 Nov 2024 15:25:34 -0800 Subject: [PATCH 1/7] Fixed the tests and addressed most of the review comments. Created using spr 1.3.6-beta.1 --- llvm/include/llvm/CodeGen/MachineFunction.h | 15 +++-- .../CodeGen/AArch64/call-site-info-typeid.ll | 28 +++-- .../test/CodeGen/ARM/call-site-info-typeid.ll | 28 +++-- .../CodeGen/MIR/X86/call-site-info-typeid.ll | 58 --- .../CodeGen/MIR/X86/call-site-info-typeid.mir | 13 ++--- .../CodeGen/Mips/call-site-info-typeid.ll | 28 +++-- .../test/CodeGen/X86/call-site-info-typeid.ll | 28 +++-- 7 files changed, 71 insertions(+), 127 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h index bb0b87a3a04a3..44633df38a651 100644 --- a/llvm/include/llvm/CodeGen/MachineFunction.h +++ b/llvm/include/llvm/CodeGen/MachineFunction.h @@ -493,7 +493,7 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { /// Callee type id. ConstantInt *TypeId = nullptr; -CallSiteInfo() {} +CallSiteInfo() = default; /// Extracts the numeric type id from the CallBase's type operand bundle, /// and sets TypeId. This is used as type id for the indirect call in the @@ -503,12 +503,11 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { if (!CB.isIndirectCall()) return; - auto Opt = CB.getOperandBundle(LLVMContext::OB_type); - if (!Opt.has_value()) { -errs() << "warning: cannot find indirect call type operand bundle for " - "call graph section\n"; + std::optional Opt = + CB.getOperandBundle(LLVMContext::OB_type); + // Return if the operand bundle for call graph section cannot be found. + if (!Opt.has_value()) return; - } // Get generalized type id string auto OB = Opt.value(); @@ -520,9 +519,9 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { "invalid type identifier"); // Compute numeric type id from generalized type id string - uint64_t TypeIdVal = llvm::MD5Hash(TypeIdStr->getString()); + uint64_t TypeIdVal = MD5Hash(TypeIdStr->getString()); IntegerType *Int64Ty = Type::getInt64Ty(CB.getContext()); - TypeId = llvm::ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false); + TypeId = ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false); } }; diff --git a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll index f0a6b44755c5c..f3b98c2c7a395 100644 --- a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll @@ -1,14 +1,9 @@ -; Tests that call site type ids can be extracted and set from type operand -; bundles. +;; Tests that call site type ids can be extracted and set from type operand +;; bundles. -; Verify the exact typeId value to ensure it is not garbage but the value -; computed as the type id from the type operand bundle. -; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu %s -stop-before=finalize-isel -o - | FileCheck %s - -; ModuleID = 'test.c' -source_filename = "test.c" -target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" -target triple = "aarch64-unknown-linux-gnu" +;; Verify the exact typeId value to ensure it is not garbage but the value +;; computed as the type id from the type operand bundle. +; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu < %s -stop-before=finalize-isel -o - | FileCheck %s define dso_local void @foo(i8 signext %a) !type !3 { entry: @@ -19,10 +14,10 @@ entry: define dso_local i32 @main() !type !4 { entry: %retval = alloca i32, align 4 - %fp = alloca void (i8)*, align 8 - store i32 0, i32* %retval, align 4 - store void (i8)* @foo, void (i8)** %fp, align 8 - %0 = load void (i8)*, void (i8)** %fp, align 8 + %fp = alloca ptr, align 8 + store i32 0, ptr %retval, align 4 + store ptr @foo, ptr %fp, align 8 + %0 = load ptr, ptr %fp, align 8 ; CHECK: callSites: ; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: ; CHECK-NEXT: 7854600665770582568 } @@ -30,10 +25,5 @@ entry: ret i32 0 } -!llvm.module.flags = !{!0, !1, !2} - -!0 = !{i32 1, !"wchar_size", i32 4} -!1 = !{i32 7, !"uwtable", i32 1} -!2 = !{i32 7, !"frame-pointer", i32 2} !3 = !{i64 0, !"_ZTSFvcE.generalized"} !4 = !{i64 0, !"_ZTSFiE.generalized"} diff --git a/llvm/test/CodeGen/ARM/call-site-info-typeid.ll b/llvm/test/CodeGen/ARM/call-site-info-typeid.ll index ec7f8a425051b..9feeef9a564cc 100644 --- a/llvm/test/CodeGen/ARM/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/ARM/call-site-info-typeid.ll @@ -1,14 +1,9 @@ -; Tests that call site type ids can be extracted and set from type operand -; bundles. +;; Tests that ca
[llvm-branch-commits] [llvm] [llvm] Extract and propagate indirect call type id (PR #87575)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87575 >From 1a8d810d352fbe84c0521c7614689b60ade693c8 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Tue, 19 Nov 2024 15:25:34 -0800 Subject: [PATCH 1/7] Fixed the tests and addressed most of the review comments. Created using spr 1.3.6-beta.1 --- llvm/include/llvm/CodeGen/MachineFunction.h | 15 +++-- .../CodeGen/AArch64/call-site-info-typeid.ll | 28 +++-- .../test/CodeGen/ARM/call-site-info-typeid.ll | 28 +++-- .../CodeGen/MIR/X86/call-site-info-typeid.ll | 58 --- .../CodeGen/MIR/X86/call-site-info-typeid.mir | 13 ++--- .../CodeGen/Mips/call-site-info-typeid.ll | 28 +++-- .../test/CodeGen/X86/call-site-info-typeid.ll | 28 +++-- 7 files changed, 71 insertions(+), 127 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h index bb0b87a3a04a3..44633df38a651 100644 --- a/llvm/include/llvm/CodeGen/MachineFunction.h +++ b/llvm/include/llvm/CodeGen/MachineFunction.h @@ -493,7 +493,7 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { /// Callee type id. ConstantInt *TypeId = nullptr; -CallSiteInfo() {} +CallSiteInfo() = default; /// Extracts the numeric type id from the CallBase's type operand bundle, /// and sets TypeId. This is used as type id for the indirect call in the @@ -503,12 +503,11 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { if (!CB.isIndirectCall()) return; - auto Opt = CB.getOperandBundle(LLVMContext::OB_type); - if (!Opt.has_value()) { -errs() << "warning: cannot find indirect call type operand bundle for " - "call graph section\n"; + std::optional Opt = + CB.getOperandBundle(LLVMContext::OB_type); + // Return if the operand bundle for call graph section cannot be found. + if (!Opt.has_value()) return; - } // Get generalized type id string auto OB = Opt.value(); @@ -520,9 +519,9 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { "invalid type identifier"); // Compute numeric type id from generalized type id string - uint64_t TypeIdVal = llvm::MD5Hash(TypeIdStr->getString()); + uint64_t TypeIdVal = MD5Hash(TypeIdStr->getString()); IntegerType *Int64Ty = Type::getInt64Ty(CB.getContext()); - TypeId = llvm::ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false); + TypeId = ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false); } }; diff --git a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll index f0a6b44755c5c..f3b98c2c7a395 100644 --- a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll @@ -1,14 +1,9 @@ -; Tests that call site type ids can be extracted and set from type operand -; bundles. +;; Tests that call site type ids can be extracted and set from type operand +;; bundles. -; Verify the exact typeId value to ensure it is not garbage but the value -; computed as the type id from the type operand bundle. -; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu %s -stop-before=finalize-isel -o - | FileCheck %s - -; ModuleID = 'test.c' -source_filename = "test.c" -target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" -target triple = "aarch64-unknown-linux-gnu" +;; Verify the exact typeId value to ensure it is not garbage but the value +;; computed as the type id from the type operand bundle. +; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu < %s -stop-before=finalize-isel -o - | FileCheck %s define dso_local void @foo(i8 signext %a) !type !3 { entry: @@ -19,10 +14,10 @@ entry: define dso_local i32 @main() !type !4 { entry: %retval = alloca i32, align 4 - %fp = alloca void (i8)*, align 8 - store i32 0, i32* %retval, align 4 - store void (i8)* @foo, void (i8)** %fp, align 8 - %0 = load void (i8)*, void (i8)** %fp, align 8 + %fp = alloca ptr, align 8 + store i32 0, ptr %retval, align 4 + store ptr @foo, ptr %fp, align 8 + %0 = load ptr, ptr %fp, align 8 ; CHECK: callSites: ; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: ; CHECK-NEXT: 7854600665770582568 } @@ -30,10 +25,5 @@ entry: ret i32 0 } -!llvm.module.flags = !{!0, !1, !2} - -!0 = !{i32 1, !"wchar_size", i32 4} -!1 = !{i32 7, !"uwtable", i32 1} -!2 = !{i32 7, !"frame-pointer", i32 2} !3 = !{i64 0, !"_ZTSFvcE.generalized"} !4 = !{i64 0, !"_ZTSFiE.generalized"} diff --git a/llvm/test/CodeGen/ARM/call-site-info-typeid.ll b/llvm/test/CodeGen/ARM/call-site-info-typeid.ll index ec7f8a425051b..9feeef9a564cc 100644 --- a/llvm/test/CodeGen/ARM/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/ARM/call-site-info-typeid.ll @@ -1,14 +1,9 @@ -; Tests that call site type ids can be extracted and set from type operand -; bundles. +;; Tests that ca
[llvm-branch-commits] [clang] [clang] Introduce CallGraphSection option (PR #117037)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/117037 >From 6a12be2c5b60a95a06875b0b2c4f14228d1fa882 Mon Sep 17 00:00:00 2001 From: prabhukr Date: Wed, 12 Mar 2025 23:30:01 + Subject: [PATCH] Fix EOF newlines. Created using spr 1.3.6-beta.1 --- clang/test/Driver/call-graph-section.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Driver/call-graph-section.c b/clang/test/Driver/call-graph-section.c index 108446729d857..5832aa6754137 100644 --- a/clang/test/Driver/call-graph-section.c +++ b/clang/test/Driver/call-graph-section.c @@ -2,4 +2,4 @@ // RUN: %clang -### -S -fcall-graph-section -fno-call-graph-section %s 2>&1 | FileCheck --check-prefix=NO-CALL-GRAPH-SECTION %s // CALL-GRAPH-SECTION: "-fcall-graph-section" -// NO-CALL-GRAPH-SECTION-NOT: "-fcall-graph-section" \ No newline at end of file +// NO-CALL-GRAPH-SECTION-NOT: "-fcall-graph-section" ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm][AsmPrinter] Emit call graph section (PR #87576)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87576 >From 6b67376bd5e1f21606017c83cc67f2186ba36a33 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Thu, 13 Mar 2025 01:41:04 + Subject: [PATCH 1/5] Updated the test as reviewers suggested. Created using spr 1.3.6-beta.1 --- llvm/test/CodeGen/X86/call-graph-section.ll | 66 +++ llvm/test/CodeGen/call-graph-section.ll | 73 - 2 files changed, 66 insertions(+), 73 deletions(-) create mode 100644 llvm/test/CodeGen/X86/call-graph-section.ll delete mode 100644 llvm/test/CodeGen/call-graph-section.ll diff --git a/llvm/test/CodeGen/X86/call-graph-section.ll b/llvm/test/CodeGen/X86/call-graph-section.ll new file mode 100644 index 0..a77a2b8051ed3 --- /dev/null +++ b/llvm/test/CodeGen/X86/call-graph-section.ll @@ -0,0 +1,66 @@ +;; Tests that we store the type identifiers in .callgraph section of the binary. + +; RUN: llc --call-graph-section -filetype=obj -o - < %s | \ +; RUN: llvm-readelf -x .callgraph - | FileCheck %s + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local void @foo() #0 !type !4 { +entry: + ret void +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local i32 @bar(i8 signext %a) #0 !type !5 { +entry: + %a.addr = alloca i8, align 1 + store i8 %a, ptr %a.addr, align 1 + ret i32 0 +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local ptr @baz(ptr %a) #0 !type !6 { +entry: + %a.addr = alloca ptr, align 8 + store ptr %a, ptr %a.addr, align 8 + ret ptr null +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local void @main() #0 !type !7 { +entry: + %retval = alloca i32, align 4 + %fp_foo = alloca ptr, align 8 + %a = alloca i8, align 1 + %fp_bar = alloca ptr, align 8 + %fp_baz = alloca ptr, align 8 + store i32 0, ptr %retval, align 4 + store ptr @foo, ptr %fp_foo, align 8 + %0 = load ptr, ptr %fp_foo, align 8 + call void (...) %0() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] + store ptr @bar, ptr %fp_bar, align 8 + %1 = load ptr, ptr %fp_bar, align 8 + %2 = load i8, ptr %a, align 1 + %call = call i32 %1(i8 signext %2) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] + store ptr @baz, ptr %fp_baz, align 8 + %3 = load ptr, ptr %fp_baz, align 8 + %call1 = call ptr %3(ptr %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] + call void @foo() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] + %4 = load i8, ptr %a, align 1 + %call2 = call i32 @bar(i8 signext %4) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] + %call3 = call ptr @baz(ptr %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] + ret void +} + +;; Check that the numeric type id (md5 hash) for the below type ids are emitted +;; to the callgraph section. + +; CHECK: Hex dump of section '.callgraph': + +; CHECK-DAG: 2444f731 f5eecb3e +!4 = !{i64 0, !"_ZTSFvE.generalized"} +; CHECK-DAG: 5486bc59 814b8e30 +!5 = !{i64 0, !"_ZTSFicE.generalized"} +; CHECK-DAG: 7ade6814 f897fd77 +!6 = !{i64 0, !"_ZTSFPvS_E.generalized"} +; CHECK-DAG: caaf769a 600968fa +!7 = !{i64 0, !"_ZTSFiE.generalized"} diff --git a/llvm/test/CodeGen/call-graph-section.ll b/llvm/test/CodeGen/call-graph-section.ll deleted file mode 100644 index bb158d11e82c9..0 --- a/llvm/test/CodeGen/call-graph-section.ll +++ /dev/null @@ -1,73 +0,0 @@ -; Tests that we store the type identifiers in .callgraph section of the binary. - -; RUN: llc --call-graph-section -filetype=obj -o - < %s | \ -; RUN: llvm-readelf -x .callgraph - | FileCheck %s - -target triple = "x86_64-unknown-linux-gnu" - -define dso_local void @foo() #0 !type !4 { -entry: - ret void -} - -define dso_local i32 @bar(i8 signext %a) #0 !type !5 { -entry: - %a.addr = alloca i8, align 1 - store i8 %a, i8* %a.addr, align 1 - ret i32 0 -} - -define dso_local i32* @baz(i8* %a) #0 !type !6 { -entry: - %a.addr = alloca i8*, align 8 - store i8* %a, i8** %a.addr, align 8 - ret i32* null -} - -define dso_local i32 @main() #0 !type !7 { -entry: - %retval = alloca i32, align 4 - %fp_foo = alloca void (...)*, align 8 - %a = alloca i8, align 1 - %fp_bar = alloca i32 (i8)*, align 8 - %fp_baz = alloca i32* (i8*)*, align 8 - store i32 0, i32* %retval, align 4 - store void (...)* bitcast (void ()* @foo to void (...)*), void (...)** %fp_foo, align 8 - %0 = load void (...)*, void (...)** %fp_foo, align 8 - call void (...) %0() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] - store i32 (i8)* @bar, i32 (i8)** %fp_bar, align 8 - %1 = load i32 (i8)*, i32 (i8)** %fp_bar, align 8 - %2 = load i8, i8* %a, align 1 - %call = call i32 %1(i8 signext %2) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] - store i32* (i8*)* @baz, i32* (i8*)** %fp_baz, align 8 - %3 = load i32* (i8*)*, i32* (i8*)** %fp_baz, align 8 - %call1 = call i32* %3(i8* %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] - call void @foo() [ "callee_type"(meta
[llvm-branch-commits] [clang] [clang] Introduce CallGraphSection option (PR #117037)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/117037 >From 6a12be2c5b60a95a06875b0b2c4f14228d1fa882 Mon Sep 17 00:00:00 2001 From: prabhukr Date: Wed, 12 Mar 2025 23:30:01 + Subject: [PATCH] Fix EOF newlines. Created using spr 1.3.6-beta.1 --- clang/test/Driver/call-graph-section.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Driver/call-graph-section.c b/clang/test/Driver/call-graph-section.c index 108446729d857..5832aa6754137 100644 --- a/clang/test/Driver/call-graph-section.c +++ b/clang/test/Driver/call-graph-section.c @@ -2,4 +2,4 @@ // RUN: %clang -### -S -fcall-graph-section -fno-call-graph-section %s 2>&1 | FileCheck --check-prefix=NO-CALL-GRAPH-SECTION %s // CALL-GRAPH-SECTION: "-fcall-graph-section" -// NO-CALL-GRAPH-SECTION-NOT: "-fcall-graph-section" \ No newline at end of file +// NO-CALL-GRAPH-SECTION-NOT: "-fcall-graph-section" ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm] Add option to emit `callgraph` section (PR #87574)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87574 >From 1d7ee612e408ee7e64e984eb08e6d7089a435d09 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Sun, 2 Feb 2025 00:58:49 + Subject: [PATCH 1/7] Simplify MIR test. Created using spr 1.3.6-beta.1 --- .../CodeGen/MIR/X86/call-site-info-typeid.mir | 21 ++- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir index 5ab797bfcc18f..a99ee50a608fb 100644 --- a/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir +++ b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir @@ -8,11 +8,6 @@ # CHECK-NEXT: 123456789 } --- | - ; ModuleID = 'test.ll' - source_filename = "test.ll" - target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - target triple = "x86_64-unknown-linux-gnu" - define dso_local void @foo(i8 signext %a) { entry: ret void @@ -21,10 +16,10 @@ define dso_local i32 @main() { entry: %retval = alloca i32, align 4 -%fp = alloca void (i8)*, align 8 -store i32 0, i32* %retval, align 4 -store void (i8)* @foo, void (i8)** %fp, align 8 -%0 = load void (i8)*, void (i8)** %fp, align 8 +%fp = alloca ptr, align 8 +store i32 0, ptr %retval, align 4 +store ptr @foo, ptr %fp, align 8 +%0 = load ptr, ptr %fp, align 8 call void %0(i8 signext 97) ret i32 0 } @@ -42,12 +37,8 @@ body: | name:main tracksRegLiveness: true stack: - - { id: 0, name: retval, type: default, offset: 0, size: 4, alignment: 4, - stack-id: default, callee-saved-register: '', callee-saved-restored: true, - debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } - - { id: 1, name: fp, type: default, offset: 0, size: 8, alignment: 8, - stack-id: default, callee-saved-register: '', callee-saved-restored: true, - debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } + - { id: 0, name: retval, size: 4, alignment: 4 } + - { id: 1, name: fp, size: 8, alignment: 8 } callSites: - { bb: 0, offset: 6, fwdArgRegs: [], typeId: 123456789 } >From 86e2c9dc37170499252ed50c6bbef2931e106fbb Mon Sep 17 00:00:00 2001 From: prabhukr Date: Thu, 13 Mar 2025 01:03:40 + Subject: [PATCH 2/7] Add requested tests part 1. Created using spr 1.3.6-beta.1 --- ...te-info-ambiguous-indirect-call-typeid.mir | 145 ++ .../call-site-info-direct-calls-typeid.mir| 145 ++ 2 files changed, 290 insertions(+) create mode 100644 llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir create mode 100644 llvm/test/CodeGen/MIR/X86/call-site-info-direct-calls-typeid.mir diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir new file mode 100644 index 0..9d1b099cc9093 --- /dev/null +++ b/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir @@ -0,0 +1,145 @@ +# Test MIR printer and parser for type id field in callSites. It is used +# for propogating call site type identifiers to emit in the call graph section. + +# RUN: llc --call-graph-section %s -run-pass=none -o - | FileCheck %s +# CHECK: name: main +# CHECK: callSites: +# CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [] +# CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: +# CHECK-NEXT: 1234567890 } + +--- | + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef i32 @_Z3addii(i32 noundef %a, i32 noundef %b) #0 !type !6 !type !6 { + entry: +%a.addr = alloca i32, align 4 +%b.addr = alloca i32, align 4 +store i32 %a, ptr %a.addr, align 4 +store i32 %b, ptr %b.addr, align 4 +%0 = load i32, ptr %a.addr, align 4 +%1 = load i32, ptr %b.addr, align 4 +%add = add nsw i32 %0, %1 +ret i32 %add + } + + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef i32 @_Z8multiplyii(i32 noundef %a, i32 noundef %b) #0 !type !6 !type !6 { + entry: +%a.addr = alloca i32, align 4 +%b.addr = alloca i32, align 4 +store i32 %a, ptr %a.addr, align 4 +store i32 %b, ptr %b.addr, align 4 +%0 = load i32, ptr %a.addr, align 4 +%1 = load i32, ptr %b.addr, align 4 +%mul = mul nsw i32 %0, %1 +ret i32 %mul + } + + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef ptr @_Z13get_operationb(i1 noundef zeroext %is_addition) #0 !type !7 !type !7 { + entry: +%is_addition.addr = alloca i8, align 1 +%storedv = zext i1 %is_addition to i8 +store i8 %storedv, ptr %is_addition.addr, align 1 +%0 = load i8, ptr %is_addition.addr, align 1 +%loadedv = trunc i8 %0 to i1 +br i1 %loade
[llvm-branch-commits] [clang] [clang] callee_type metadata for indirect calls (PR #117036)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/117036 >From b7fbe09b32ff02d4f7c52d82fbf8b5cd28138852 Mon Sep 17 00:00:00 2001 From: prabhukr Date: Wed, 23 Apr 2025 04:05:47 + Subject: [PATCH] Address review comments. Created using spr 1.3.6-beta.1 --- clang/lib/CodeGen/CGCall.cpp| 8 clang/lib/CodeGen/CodeGenModule.cpp | 10 +- clang/lib/CodeGen/CodeGenModule.h | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 185ee1a970aac..d8ab7140f7943 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -5780,19 +5780,19 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, if (callOrInvoke) { *callOrInvoke = CI; if (CGM.getCodeGenOpts().CallGraphSection) { - assert((TargetDecl && TargetDecl->getFunctionType() || - Callee.getAbstractInfo().getCalleeFunctionProtoType()) && - "cannot find callsite type"); QualType CST; if (TargetDecl && TargetDecl->getFunctionType()) CST = QualType(TargetDecl->getFunctionType(), 0); else if (const auto *FPT = Callee.getAbstractInfo().getCalleeFunctionProtoType()) CST = QualType(FPT, 0); + else +llvm_unreachable( +"Cannot find the callee type to generate callee_type metadata."); // Set type identifier metadata of indirect calls for call graph section. if (!CST.isNull()) -CGM.CreateCalleeTypeMetadataForIcall(CST, *callOrInvoke); +CGM.createCalleeTypeMetadataForIcall(CST, *callOrInvoke); } } diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 43cd2405571cf..2fc99639a75cb 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2654,7 +2654,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, // Skip available_externally functions. They won't be codegen'ed in the // current module anyway. if (getContext().GetGVALinkageForFunction(FD) != GVA_AvailableExternally) -CreateFunctionTypeMetadataForIcall(FD, F); +createFunctionTypeMetadataForIcall(FD, F); } } @@ -2868,7 +2868,7 @@ static bool hasExistingGeneralizedTypeMD(llvm::Function *F) { return MD->hasGeneralizedMDString(); } -void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, +void CodeGenModule::createFunctionTypeMetadataForIcall(const FunctionDecl *FD, llvm::Function *F) { if (CodeGenOpts.CallGraphSection && !hasExistingGeneralizedTypeMD(F) && (!F->hasLocalLinkage() || @@ -2898,7 +2898,7 @@ void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, F->addTypeMetadata(0, llvm::ConstantAsMetadata::get(CrossDsoTypeId)); } -void CodeGenModule::CreateCalleeTypeMetadataForIcall(const QualType &QT, +void CodeGenModule::createCalleeTypeMetadataForIcall(const QualType &QT, llvm::CallBase *CB) { // Only if needed for call graph section and only for indirect calls. if (!CodeGenOpts.CallGraphSection || !CB->isIndirectCall()) @@ -2909,7 +2909,7 @@ void CodeGenModule::CreateCalleeTypeMetadataForIcall(const QualType &QT, getLLVMContext(), {llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( llvm::Type::getInt64Ty(getLLVMContext()), 0)), TypeIdMD}); - llvm::MDTuple *MDN = llvm::MDNode::get(getLLVMContext(), { TypeTuple }); + llvm::MDTuple *MDN = llvm::MDNode::get(getLLVMContext(), {TypeTuple}); CB->setMetadata(llvm::LLVMContext::MD_callee_type, MDN); } @@ -3041,7 +3041,7 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F, // jump table. if (!CodeGenOpts.SanitizeCfiCrossDso || !CodeGenOpts.SanitizeCfiCanonicalJumpTables) -CreateFunctionTypeMetadataForIcall(FD, F); +createFunctionTypeMetadataForIcall(FD, F); if (LangOpts.Sanitize.has(SanitizerKind::KCFI)) setKCFIType(FD, F); diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index dfbe4388349dd..4b53f0f241b52 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -1619,11 +1619,11 @@ class CodeGenModule : public CodeGenTypeCache { llvm::Metadata *CreateMetadataIdentifierGeneralized(QualType T); /// Create and attach type metadata to the given function. - void CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, + void createFunctionTypeMetadataForIcall(const FunctionDecl *FD, llvm::Function *F); /// Create and attach type metadata to the given call. - void CreateCalleeTypeMetadataForIcall(const QualType &QT, llvm::CallBase *CB); + void createCa
[llvm-branch-commits] [clang] [clang] callee_type metadata for indirect calls (PR #117036)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/117036 >From b7fbe09b32ff02d4f7c52d82fbf8b5cd28138852 Mon Sep 17 00:00:00 2001 From: prabhukr Date: Wed, 23 Apr 2025 04:05:47 + Subject: [PATCH] Address review comments. Created using spr 1.3.6-beta.1 --- clang/lib/CodeGen/CGCall.cpp| 8 clang/lib/CodeGen/CodeGenModule.cpp | 10 +- clang/lib/CodeGen/CodeGenModule.h | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 185ee1a970aac..d8ab7140f7943 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -5780,19 +5780,19 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, if (callOrInvoke) { *callOrInvoke = CI; if (CGM.getCodeGenOpts().CallGraphSection) { - assert((TargetDecl && TargetDecl->getFunctionType() || - Callee.getAbstractInfo().getCalleeFunctionProtoType()) && - "cannot find callsite type"); QualType CST; if (TargetDecl && TargetDecl->getFunctionType()) CST = QualType(TargetDecl->getFunctionType(), 0); else if (const auto *FPT = Callee.getAbstractInfo().getCalleeFunctionProtoType()) CST = QualType(FPT, 0); + else +llvm_unreachable( +"Cannot find the callee type to generate callee_type metadata."); // Set type identifier metadata of indirect calls for call graph section. if (!CST.isNull()) -CGM.CreateCalleeTypeMetadataForIcall(CST, *callOrInvoke); +CGM.createCalleeTypeMetadataForIcall(CST, *callOrInvoke); } } diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 43cd2405571cf..2fc99639a75cb 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2654,7 +2654,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, // Skip available_externally functions. They won't be codegen'ed in the // current module anyway. if (getContext().GetGVALinkageForFunction(FD) != GVA_AvailableExternally) -CreateFunctionTypeMetadataForIcall(FD, F); +createFunctionTypeMetadataForIcall(FD, F); } } @@ -2868,7 +2868,7 @@ static bool hasExistingGeneralizedTypeMD(llvm::Function *F) { return MD->hasGeneralizedMDString(); } -void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, +void CodeGenModule::createFunctionTypeMetadataForIcall(const FunctionDecl *FD, llvm::Function *F) { if (CodeGenOpts.CallGraphSection && !hasExistingGeneralizedTypeMD(F) && (!F->hasLocalLinkage() || @@ -2898,7 +2898,7 @@ void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, F->addTypeMetadata(0, llvm::ConstantAsMetadata::get(CrossDsoTypeId)); } -void CodeGenModule::CreateCalleeTypeMetadataForIcall(const QualType &QT, +void CodeGenModule::createCalleeTypeMetadataForIcall(const QualType &QT, llvm::CallBase *CB) { // Only if needed for call graph section and only for indirect calls. if (!CodeGenOpts.CallGraphSection || !CB->isIndirectCall()) @@ -2909,7 +2909,7 @@ void CodeGenModule::CreateCalleeTypeMetadataForIcall(const QualType &QT, getLLVMContext(), {llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( llvm::Type::getInt64Ty(getLLVMContext()), 0)), TypeIdMD}); - llvm::MDTuple *MDN = llvm::MDNode::get(getLLVMContext(), { TypeTuple }); + llvm::MDTuple *MDN = llvm::MDNode::get(getLLVMContext(), {TypeTuple}); CB->setMetadata(llvm::LLVMContext::MD_callee_type, MDN); } @@ -3041,7 +3041,7 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F, // jump table. if (!CodeGenOpts.SanitizeCfiCrossDso || !CodeGenOpts.SanitizeCfiCanonicalJumpTables) -CreateFunctionTypeMetadataForIcall(FD, F); +createFunctionTypeMetadataForIcall(FD, F); if (LangOpts.Sanitize.has(SanitizerKind::KCFI)) setKCFIType(FD, F); diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index dfbe4388349dd..4b53f0f241b52 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -1619,11 +1619,11 @@ class CodeGenModule : public CodeGenTypeCache { llvm::Metadata *CreateMetadataIdentifierGeneralized(QualType T); /// Create and attach type metadata to the given function. - void CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, + void createFunctionTypeMetadataForIcall(const FunctionDecl *FD, llvm::Function *F); /// Create and attach type metadata to the given call. - void CreateCalleeTypeMetadataForIcall(const QualType &QT, llvm::CallBase *CB); + void createCa
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149564)
https://github.com/evelez7 closed https://github.com/llvm/llvm-project/pull/149564 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] MC: Refactor FT_Align fragments when linker relaxation is enabled (PR #149465)
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/149465 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] MC: Refactor FT_Align fragments when linker relaxation is enabled (PR #149465)
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/149465 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149564)
https://github.com/ilovepi commented: This seems mostly fine. I'll probably LGTM once I go through the whole stack. https://github.com/llvm/llvm-project/pull/149564 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149564)
@@ -210,12 +229,17 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, } if (!I.Description.empty()) { -json::Value DescArray = json::Array(); -auto &DescArrayRef = *DescArray.getAsArray(); -DescArrayRef.reserve(I.Description.size()); -for (const auto &Comment : I.Description) - DescArrayRef.push_back(serializeComment(Comment)); -Obj["Description"] = DescArray; +Object Description = Object(); +// Skip straight to the FullComment's children +auto &Comments = I.Description.at(0).Children; +for (const auto &CommentInfo : Comments) { + json::Value Comment = serializeComment(*CommentInfo, Description); + // Paragraph comments might not be children + if (auto *ParagraphComment = + Comment.getAsObject()->get("ParagraphComment")) +insertComment(Description, *ParagraphComment, "ParagraphComments"); ilovepi wrote: The comment here implies to me that we may be missing paragraph comments. Am I understanding that correctly? https://github.com/llvm/llvm-project/pull/149564 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149564)
https://github.com/ilovepi edited https://github.com/llvm/llvm-project/pull/149564 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [LifetimeSafety] Enhance benchmark script for ExpiredLoans analysis (PR #149577)
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/149577 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] Driver, CodeGen: Handle -falign-functions, -fno-align-functions and -falign-functions=1 correctly. (PR #149445)
https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149445 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] Driver, CodeGen: Handle -falign-functions, -fno-align-functions and -falign-functions=1 correctly. (PR #149445)
@@ -5516,12 +5517,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CheckCodeGenerationOptions(D, Args); - unsigned FunctionAlignment = ParseFunctionAlignment(TC, Args); - assert(FunctionAlignment <= 31 && "function alignment will be truncated!"); - if (FunctionAlignment) { -CmdArgs.push_back("-function-alignment"); -CmdArgs.push_back(Args.MakeArgString(std::to_string(FunctionAlignment))); - } + llvm::MaybeAlign FunctionAlignment = ParseFunctionAlignment(TC, Args); + CmdArgs.push_back("-function-alignment"); + CmdArgs.push_back( + Args.MakeArgString(std::to_string(llvm::encode(FunctionAlignment; pcc wrote: Done https://github.com/llvm/llvm-project/pull/149445 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] Driver, CodeGen: Handle -falign-functions, -fno-align-functions and -falign-functions=1 correctly. (PR #149445)
https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149445 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Erick Velez (evelez7) Changes This patch integrates JSON as the source to generate HTML Mustache templates. The Mustache generator calls the JSON generator and reads JSON files on the disk to produce HTML serially. --- Patch is 48.74 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/149589.diff 9 Files Affected: - (modified) clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp (+78-409) - (modified) clang-tools-extra/clang-doc/assets/class-template.mustache (+32-30) - (modified) clang-tools-extra/clang-doc/assets/enum-template.mustache (+9-3) - (modified) clang-tools-extra/clang-doc/assets/function-template.mustache (+1-1) - (modified) clang-tools-extra/clang-doc/assets/namespace-template.mustache (+25-20) - (modified) clang-tools-extra/test/clang-doc/basic-project.mustache.test (+13-57) - (modified) clang-tools-extra/test/clang-doc/mustache-index.cpp (+9-5) - (modified) clang-tools-extra/test/clang-doc/mustache-separate-namespace.cpp (+6-2) - (modified) clang-tools-extra/unittests/clang-doc/HTMLMustacheGeneratorTest.cpp (-129) ``diff diff --git a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp index 7aeaa1b7cf67d..98e2935a8aada 100644 --- a/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp +++ b/clang-tools-extra/clang-doc/HTMLMustacheGenerator.cpp @@ -27,6 +27,9 @@ using namespace llvm::mustache; namespace clang { namespace doc { +static Error generateDocForJSON(json::Value &JSON, StringRef Filename, +StringRef Path, raw_fd_ostream &OS, +const ClangDocContext &CDCtx); static Error createFileOpenError(StringRef FileName, std::error_code EC) { return createFileError("cannot open file " + FileName, EC); @@ -132,404 +135,65 @@ Error MustacheHTMLGenerator::generateDocs( return Err; } - // Track which directories we already tried to create. - StringSet<> CreatedDirs; - // Collect all output by file name and create the necessary directories. - StringMap> FileToInfos; - for (const auto &Group : Infos) { -llvm::TimeTraceScope TS("setup directories"); -doc::Info *Info = Group.getValue().get(); - -SmallString<128> Path; -sys::path::native(RootDir, Path); -sys::path::append(Path, Info->getRelativeFilePath("")); -if (!CreatedDirs.contains(Path)) { - if (std::error_code EC = sys::fs::create_directories(Path)) -return createStringError(EC, "failed to create directory '%s'.", - Path.c_str()); - CreatedDirs.insert(Path); -} - -sys::path::append(Path, Info->getFileBaseName() + ".html"); -FileToInfos[Path].push_back(Info); + { +llvm::TimeTraceScope TS("Generate JSON for Mustache"); +if (auto JSONGenerator = findGeneratorByName("json")) { + if (Error Err = JSONGenerator.get()->generateDocs( + RootDir, std::move(Infos), CDCtx)) +return Err; +} else + return JSONGenerator.takeError(); } + StringMap JSONFileMap; { -llvm::TimeTraceScope TS("Generate Docs"); -for (const auto &Group : FileToInfos) { - llvm::TimeTraceScope TS("Info to Doc"); +llvm::TimeTraceScope TS("Iterate JSON files"); +std::error_code EC; +sys::fs::directory_iterator JSONIter(RootDir, EC); +std::vector JSONFiles; +JSONFiles.reserve(Infos.size()); +if (EC) + return createStringError("Failed to create directory iterator."); + +while (JSONIter != sys::fs::directory_iterator()) { + if (EC) +return createStringError(EC, "Failed to iterate directory"); + + auto Path = StringRef(JSONIter->path()); + if (!Path.ends_with(".json")) { +JSONIter.increment(EC); +continue; + } + + auto File = MemoryBuffer::getFile(Path); + if ((EC = File.getError())) +continue; + + auto Parsed = json::parse((*File)->getBuffer()); + if (!Parsed) +return Parsed.takeError(); + std::error_code FileErr; - raw_fd_ostream InfoOS(Group.getKey(), FileErr, sys::fs::OF_None); + SmallString<16> HTMLPath(Path.begin(), Path.end()); + sys::path::replace_extension(HTMLPath, "html"); + raw_fd_ostream InfoOS(HTMLPath, FileErr, sys::fs::OF_None); if (FileErr) -return createFileOpenError(Group.getKey(), FileErr); +return createFileOpenError(Path, FileErr); - for (const auto &Info : Group.getValue()) -if (Error Err = generateDocForInfo(Info, InfoOS, CDCtx)) - return Err; + if (Error Err = generateDocForJSON(*Parsed, sys::path::stem(HTMLPath), + HTMLPath, InfoOS, CDCtx)) +return Err; + JSONIter.increment(EC); } } - return Error::success(); -} - -static json::Value -extractValue(const Location &L, - std::
[llvm-branch-commits] [clang-tools-extra] [clang-doc] integrate JSON as the source for Mustache templates (PR #149589)
https://github.com/evelez7 ready_for_review https://github.com/llvm/llvm-project/pull/149589 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/21.x: [clang] Fix potential constant expression checking with constexpr-unknown. (PR #149402)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Eli Friedman (efriedma-quic) Changes Manual backport of 6a60f18997d62b0e2842a921fcb6beb3e52ed823 --- Full diff: https://github.com/llvm/llvm-project/pull/149402.diff 3 Files Affected: - (modified) clang/lib/AST/ExprConstant.cpp (+7-4) - (modified) clang/test/SemaCXX/constant-expression-p2280r4.cpp (+26) - (modified) clang/test/SemaCXX/constexpr-never-constant.cpp (+7) ``diff diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 1b33b6706e204..d7b1173283c57 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -4441,7 +4441,8 @@ static CompleteObject findCompleteObject(EvalInfo &Info, const Expr *E, } } else if (!IsAccess) { return CompleteObject(LVal.getLValueBase(), nullptr, BaseType); - } else if (IsConstant && Info.checkingPotentialConstantExpression() && + } else if ((IsConstant || BaseType->isReferenceType()) && + Info.checkingPotentialConstantExpression() && BaseType->isLiteralType(Info.Ctx) && !VD->hasDefinition()) { // This variable might end up being constexpr. Don't diagnose it yet. } else if (IsConstant) { @@ -4478,9 +4479,11 @@ static CompleteObject findCompleteObject(EvalInfo &Info, const Expr *E, // a null BaseVal. Any constexpr-unknown variable seen here is an error: // we can't access a constexpr-unknown object. if (!BaseVal) { - Info.FFDiag(E, diag::note_constexpr_access_unknown_variable, 1) - << AK << VD; - Info.Note(VD->getLocation(), diag::note_declared_at); + if (!Info.checkingPotentialConstantExpression()) { +Info.FFDiag(E, diag::note_constexpr_access_unknown_variable, 1) +<< AK << VD; +Info.Note(VD->getLocation(), diag::note_declared_at); + } return CompleteObject(); } } else if (DynamicAllocLValue DA = LVal.Base.dyn_cast()) { diff --git a/clang/test/SemaCXX/constant-expression-p2280r4.cpp b/clang/test/SemaCXX/constant-expression-p2280r4.cpp index 03fea91169787..16f5f823d26c1 100644 --- a/clang/test/SemaCXX/constant-expression-p2280r4.cpp +++ b/clang/test/SemaCXX/constant-expression-p2280r4.cpp @@ -357,3 +357,29 @@ namespace pointer_comparisons { static_assert(!f4()); // expected-error {{static assertion expression is not an integral constant expression}} \ // expected-note {{in call to 'f4()'}} } + +namespace GH149188 { +namespace enable_if_1 { + template <__SIZE_TYPE__ N> + constexpr void foo(const char (&Str)[N]) + __attribute((enable_if(__builtin_strlen(Str), ""))) {} + + void x() { + foo("1234"); + } +} + +namespace enable_if_2 { + constexpr const char (&f())[]; + extern const char (&Str)[]; + constexpr int foo() + __attribute((enable_if(__builtin_strlen(Str), ""))) + {return __builtin_strlen(Str);} + + constexpr const char (&f())[] {return "a";} + constexpr const char (&Str)[] = f(); + void x() { + constexpr int x = foo(); + } +} +} diff --git a/clang/test/SemaCXX/constexpr-never-constant.cpp b/clang/test/SemaCXX/constexpr-never-constant.cpp index 307810ee263dd..5756bb647ce88 100644 --- a/clang/test/SemaCXX/constexpr-never-constant.cpp +++ b/clang/test/SemaCXX/constexpr-never-constant.cpp @@ -24,3 +24,10 @@ constexpr void other_func() { throw 12; } + +namespace GH149041 { + // Make sure these don't trigger the diagnostic. + extern const bool& b; + constexpr bool fun1() { return b; } + constexpr bool fun2(const bool& b) { return b; } +} `` https://github.com/llvm/llvm-project/pull/149402 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/21.x: [clang] Fix potential constant expression checking with constexpr-unknown. (PR #149402)
efriedma-quic wrote: It looks like I triggered the wrong set of bots by opening the pull request with the wrong base branch. I'm going to close/reopen. https://github.com/llvm/llvm-project/pull/149402 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/21.x: [clang] Fix potential constant expression checking with constexpr-unknown. (PR #149402)
https://github.com/efriedma-quic closed https://github.com/llvm/llvm-project/pull/149402 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] release/21.x: [clang] Fix potential constant expression checking with constexpr-unknown. (PR #149402)
https://github.com/efriedma-quic reopened https://github.com/llvm/llvm-project/pull/149402 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [llvm] Introduce callee_type metadata (PR #87573)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87573 >From a8a5848885e12c771f12cfa33b4dbc6a0272e925 Mon Sep 17 00:00:00 2001 From: Prabhuk Date: Mon, 22 Apr 2024 11:34:04 -0700 Subject: [PATCH 01/24] Update clang/lib/CodeGen/CodeGenModule.cpp Cleaner if checks. Co-authored-by: Matt Arsenault --- clang/lib/CodeGen/CodeGenModule.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index e19bbee996f58..ff1586d2fa8ab 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2711,7 +2711,7 @@ void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, void CodeGenModule::CreateFunctionTypeMetadataForIcall(const QualType &QT, llvm::CallBase *CB) { // Only if needed for call graph section and only for indirect calls. - if (!(CodeGenOpts.CallGraphSection && CB && CB->isIndirectCall())) + if (!CodeGenOpts.CallGraphSection || !CB || !CB->isIndirectCall()) return; auto *MD = CreateMetadataIdentifierGeneralized(QT); >From 019b2ca5e1c263183ed114e0b967b4e77b4a17a8 Mon Sep 17 00:00:00 2001 From: Prabhuk Date: Mon, 22 Apr 2024 11:34:31 -0700 Subject: [PATCH 02/24] Update clang/lib/CodeGen/CodeGenModule.cpp Update the comments as suggested. Co-authored-by: Matt Arsenault --- clang/lib/CodeGen/CodeGenModule.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index ff1586d2fa8ab..5635a87d2358a 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2680,9 +2680,9 @@ void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, bool EmittedMDIdGeneralized = false; if (CodeGenOpts.CallGraphSection && (!F->hasLocalLinkage() || - F->getFunction().hasAddressTaken(nullptr, /* IgnoreCallbackUses */ true, -/* IgnoreAssumeLikeCalls */ true, -/* IgnoreLLVMUsed */ false))) { + F->getFunction().hasAddressTaken(nullptr, /*IgnoreCallbackUses=*/ true, +/*IgnoreAssumeLikeCalls=*/ true, +/*IgnoreLLVMUsed=*/ false))) { F->addTypeMetadata(0, CreateMetadataIdentifierGeneralized(FD->getType())); EmittedMDIdGeneralized = true; } >From 99242900c51778abd4b7e7f4361b09202b7abcda Mon Sep 17 00:00:00 2001 From: Prabhuk Date: Mon, 29 Apr 2024 11:53:40 -0700 Subject: [PATCH 03/24] dyn_cast to isa Created using spr 1.3.6-beta.1 --- clang/lib/CodeGen/CGCall.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 526a63b24ff83..45033ced1d834 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -5713,8 +5713,8 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, if (callOrInvoke && *callOrInvoke && (*callOrInvoke)->isIndirectCall()) { if (const FunctionDecl *FD = dyn_cast_or_null(TargetDecl)) { // Type id metadata is set only for C/C++ contexts. -if (dyn_cast(FD) || dyn_cast(FD) || -dyn_cast(FD)) { +if (isa(FD) || isa(FD) || +isa(FD)) { CGM.CreateFunctionTypeMetadataForIcall(FD->getType(), *callOrInvoke); } } >From 24882b15939b781bcf28d87fdf4f6e8834b6cfde Mon Sep 17 00:00:00 2001 From: prabhukr Date: Tue, 10 Dec 2024 14:54:27 -0800 Subject: [PATCH 04/24] Address review comments. Break llvm and clang patches. Created using spr 1.3.6-beta.1 --- llvm/lib/IR/Verifier.cpp | 7 +++ llvm/test/Verifier/operand-bundles.ll | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 0ad7ba555bfad..b72672e7b8e56 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -3707,10 +3707,9 @@ void Verifier::visitCallBase(CallBase &Call) { if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) visitIntrinsicCall(ID, Call); - // Verify that a callsite has at most one "deopt", at most one "funclet", at - // most one "gc-transition", at most one "cfguardtarget", at most one "type", - // at most one "preallocated" operand bundle, and at most one "ptrauth" - // operand bundle. + // Verify that a callsite has at most one operand bundle for each of the + // following: "deopt", "funclet", "gc-transition", "cfguardtarget", "type", + // "preallocated", and "ptrauth". bool FoundDeoptBundle = false, FoundFuncletBundle = false, FoundGCTransitionBundle = false, FoundCFGuardTargetBundle = false, FoundPreallocatedBundle = false, FoundGCLiveBundle = false, diff --git a/llvm/test/Verifier/operand-bundles.ll b/llvm/t
[llvm-branch-commits] [llvm] [llvm] Add option to emit `callgraph` section (PR #87574)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87574 >From 1d7ee612e408ee7e64e984eb08e6d7089a435d09 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Sun, 2 Feb 2025 00:58:49 + Subject: [PATCH 1/7] Simplify MIR test. Created using spr 1.3.6-beta.1 --- .../CodeGen/MIR/X86/call-site-info-typeid.mir | 21 ++- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir index 5ab797bfcc18f..a99ee50a608fb 100644 --- a/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir +++ b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir @@ -8,11 +8,6 @@ # CHECK-NEXT: 123456789 } --- | - ; ModuleID = 'test.ll' - source_filename = "test.ll" - target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - target triple = "x86_64-unknown-linux-gnu" - define dso_local void @foo(i8 signext %a) { entry: ret void @@ -21,10 +16,10 @@ define dso_local i32 @main() { entry: %retval = alloca i32, align 4 -%fp = alloca void (i8)*, align 8 -store i32 0, i32* %retval, align 4 -store void (i8)* @foo, void (i8)** %fp, align 8 -%0 = load void (i8)*, void (i8)** %fp, align 8 +%fp = alloca ptr, align 8 +store i32 0, ptr %retval, align 4 +store ptr @foo, ptr %fp, align 8 +%0 = load ptr, ptr %fp, align 8 call void %0(i8 signext 97) ret i32 0 } @@ -42,12 +37,8 @@ body: | name:main tracksRegLiveness: true stack: - - { id: 0, name: retval, type: default, offset: 0, size: 4, alignment: 4, - stack-id: default, callee-saved-register: '', callee-saved-restored: true, - debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } - - { id: 1, name: fp, type: default, offset: 0, size: 8, alignment: 8, - stack-id: default, callee-saved-register: '', callee-saved-restored: true, - debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } + - { id: 0, name: retval, size: 4, alignment: 4 } + - { id: 1, name: fp, size: 8, alignment: 8 } callSites: - { bb: 0, offset: 6, fwdArgRegs: [], typeId: 123456789 } >From 86e2c9dc37170499252ed50c6bbef2931e106fbb Mon Sep 17 00:00:00 2001 From: prabhukr Date: Thu, 13 Mar 2025 01:03:40 + Subject: [PATCH 2/7] Add requested tests part 1. Created using spr 1.3.6-beta.1 --- ...te-info-ambiguous-indirect-call-typeid.mir | 145 ++ .../call-site-info-direct-calls-typeid.mir| 145 ++ 2 files changed, 290 insertions(+) create mode 100644 llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir create mode 100644 llvm/test/CodeGen/MIR/X86/call-site-info-direct-calls-typeid.mir diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir new file mode 100644 index 0..9d1b099cc9093 --- /dev/null +++ b/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir @@ -0,0 +1,145 @@ +# Test MIR printer and parser for type id field in callSites. It is used +# for propogating call site type identifiers to emit in the call graph section. + +# RUN: llc --call-graph-section %s -run-pass=none -o - | FileCheck %s +# CHECK: name: main +# CHECK: callSites: +# CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [] +# CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: +# CHECK-NEXT: 1234567890 } + +--- | + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef i32 @_Z3addii(i32 noundef %a, i32 noundef %b) #0 !type !6 !type !6 { + entry: +%a.addr = alloca i32, align 4 +%b.addr = alloca i32, align 4 +store i32 %a, ptr %a.addr, align 4 +store i32 %b, ptr %b.addr, align 4 +%0 = load i32, ptr %a.addr, align 4 +%1 = load i32, ptr %b.addr, align 4 +%add = add nsw i32 %0, %1 +ret i32 %add + } + + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef i32 @_Z8multiplyii(i32 noundef %a, i32 noundef %b) #0 !type !6 !type !6 { + entry: +%a.addr = alloca i32, align 4 +%b.addr = alloca i32, align 4 +store i32 %a, ptr %a.addr, align 4 +store i32 %b, ptr %b.addr, align 4 +%0 = load i32, ptr %a.addr, align 4 +%1 = load i32, ptr %b.addr, align 4 +%mul = mul nsw i32 %0, %1 +ret i32 %mul + } + + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef ptr @_Z13get_operationb(i1 noundef zeroext %is_addition) #0 !type !7 !type !7 { + entry: +%is_addition.addr = alloca i8, align 1 +%storedv = zext i1 %is_addition to i8 +store i8 %storedv, ptr %is_addition.addr, align 1 +%0 = load i8, ptr %is_addition.addr, align 1 +%loadedv = trunc i8 %0 to i1 +br i1 %loade
[llvm-branch-commits] [llvm] [llvm] Add option to emit `callgraph` section (PR #87574)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87574 >From 1d7ee612e408ee7e64e984eb08e6d7089a435d09 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Sun, 2 Feb 2025 00:58:49 + Subject: [PATCH 1/7] Simplify MIR test. Created using spr 1.3.6-beta.1 --- .../CodeGen/MIR/X86/call-site-info-typeid.mir | 21 ++- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir index 5ab797bfcc18f..a99ee50a608fb 100644 --- a/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir +++ b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir @@ -8,11 +8,6 @@ # CHECK-NEXT: 123456789 } --- | - ; ModuleID = 'test.ll' - source_filename = "test.ll" - target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" - target triple = "x86_64-unknown-linux-gnu" - define dso_local void @foo(i8 signext %a) { entry: ret void @@ -21,10 +16,10 @@ define dso_local i32 @main() { entry: %retval = alloca i32, align 4 -%fp = alloca void (i8)*, align 8 -store i32 0, i32* %retval, align 4 -store void (i8)* @foo, void (i8)** %fp, align 8 -%0 = load void (i8)*, void (i8)** %fp, align 8 +%fp = alloca ptr, align 8 +store i32 0, ptr %retval, align 4 +store ptr @foo, ptr %fp, align 8 +%0 = load ptr, ptr %fp, align 8 call void %0(i8 signext 97) ret i32 0 } @@ -42,12 +37,8 @@ body: | name:main tracksRegLiveness: true stack: - - { id: 0, name: retval, type: default, offset: 0, size: 4, alignment: 4, - stack-id: default, callee-saved-register: '', callee-saved-restored: true, - debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } - - { id: 1, name: fp, type: default, offset: 0, size: 8, alignment: 8, - stack-id: default, callee-saved-register: '', callee-saved-restored: true, - debug-info-variable: '', debug-info-expression: '', debug-info-location: '' } + - { id: 0, name: retval, size: 4, alignment: 4 } + - { id: 1, name: fp, size: 8, alignment: 8 } callSites: - { bb: 0, offset: 6, fwdArgRegs: [], typeId: 123456789 } >From 86e2c9dc37170499252ed50c6bbef2931e106fbb Mon Sep 17 00:00:00 2001 From: prabhukr Date: Thu, 13 Mar 2025 01:03:40 + Subject: [PATCH 2/7] Add requested tests part 1. Created using spr 1.3.6-beta.1 --- ...te-info-ambiguous-indirect-call-typeid.mir | 145 ++ .../call-site-info-direct-calls-typeid.mir| 145 ++ 2 files changed, 290 insertions(+) create mode 100644 llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir create mode 100644 llvm/test/CodeGen/MIR/X86/call-site-info-direct-calls-typeid.mir diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir new file mode 100644 index 0..9d1b099cc9093 --- /dev/null +++ b/llvm/test/CodeGen/MIR/X86/call-site-info-ambiguous-indirect-call-typeid.mir @@ -0,0 +1,145 @@ +# Test MIR printer and parser for type id field in callSites. It is used +# for propogating call site type identifiers to emit in the call graph section. + +# RUN: llc --call-graph-section %s -run-pass=none -o - | FileCheck %s +# CHECK: name: main +# CHECK: callSites: +# CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [] +# CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: +# CHECK-NEXT: 1234567890 } + +--- | + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef i32 @_Z3addii(i32 noundef %a, i32 noundef %b) #0 !type !6 !type !6 { + entry: +%a.addr = alloca i32, align 4 +%b.addr = alloca i32, align 4 +store i32 %a, ptr %a.addr, align 4 +store i32 %b, ptr %b.addr, align 4 +%0 = load i32, ptr %a.addr, align 4 +%1 = load i32, ptr %b.addr, align 4 +%add = add nsw i32 %0, %1 +ret i32 %add + } + + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef i32 @_Z8multiplyii(i32 noundef %a, i32 noundef %b) #0 !type !6 !type !6 { + entry: +%a.addr = alloca i32, align 4 +%b.addr = alloca i32, align 4 +store i32 %a, ptr %a.addr, align 4 +store i32 %b, ptr %b.addr, align 4 +%0 = load i32, ptr %a.addr, align 4 +%1 = load i32, ptr %b.addr, align 4 +%mul = mul nsw i32 %0, %1 +ret i32 %mul + } + + ; Function Attrs: mustprogress noinline nounwind optnone uwtable + define dso_local noundef ptr @_Z13get_operationb(i1 noundef zeroext %is_addition) #0 !type !7 !type !7 { + entry: +%is_addition.addr = alloca i8, align 1 +%storedv = zext i1 %is_addition to i8 +store i8 %storedv, ptr %is_addition.addr, align 1 +%0 = load i8, ptr %is_addition.addr, align 1 +%loadedv = trunc i8 %0 to i1 +br i1 %loade
[llvm-branch-commits] [clang] [clang] Introduce CallGraphSection option (PR #117037)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/117037 >From 6a12be2c5b60a95a06875b0b2c4f14228d1fa882 Mon Sep 17 00:00:00 2001 From: prabhukr Date: Wed, 12 Mar 2025 23:30:01 + Subject: [PATCH] Fix EOF newlines. Created using spr 1.3.6-beta.1 --- clang/test/Driver/call-graph-section.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Driver/call-graph-section.c b/clang/test/Driver/call-graph-section.c index 108446729d857..5832aa6754137 100644 --- a/clang/test/Driver/call-graph-section.c +++ b/clang/test/Driver/call-graph-section.c @@ -2,4 +2,4 @@ // RUN: %clang -### -S -fcall-graph-section -fno-call-graph-section %s 2>&1 | FileCheck --check-prefix=NO-CALL-GRAPH-SECTION %s // CALL-GRAPH-SECTION: "-fcall-graph-section" -// NO-CALL-GRAPH-SECTION-NOT: "-fcall-graph-section" \ No newline at end of file +// NO-CALL-GRAPH-SECTION-NOT: "-fcall-graph-section" ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm][AsmPrinter] Emit call graph section (PR #87576)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87576 >From 6b67376bd5e1f21606017c83cc67f2186ba36a33 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Thu, 13 Mar 2025 01:41:04 + Subject: [PATCH 1/5] Updated the test as reviewers suggested. Created using spr 1.3.6-beta.1 --- llvm/test/CodeGen/X86/call-graph-section.ll | 66 +++ llvm/test/CodeGen/call-graph-section.ll | 73 - 2 files changed, 66 insertions(+), 73 deletions(-) create mode 100644 llvm/test/CodeGen/X86/call-graph-section.ll delete mode 100644 llvm/test/CodeGen/call-graph-section.ll diff --git a/llvm/test/CodeGen/X86/call-graph-section.ll b/llvm/test/CodeGen/X86/call-graph-section.ll new file mode 100644 index 0..a77a2b8051ed3 --- /dev/null +++ b/llvm/test/CodeGen/X86/call-graph-section.ll @@ -0,0 +1,66 @@ +;; Tests that we store the type identifiers in .callgraph section of the binary. + +; RUN: llc --call-graph-section -filetype=obj -o - < %s | \ +; RUN: llvm-readelf -x .callgraph - | FileCheck %s + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local void @foo() #0 !type !4 { +entry: + ret void +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local i32 @bar(i8 signext %a) #0 !type !5 { +entry: + %a.addr = alloca i8, align 1 + store i8 %a, ptr %a.addr, align 1 + ret i32 0 +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local ptr @baz(ptr %a) #0 !type !6 { +entry: + %a.addr = alloca ptr, align 8 + store ptr %a, ptr %a.addr, align 8 + ret ptr null +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local void @main() #0 !type !7 { +entry: + %retval = alloca i32, align 4 + %fp_foo = alloca ptr, align 8 + %a = alloca i8, align 1 + %fp_bar = alloca ptr, align 8 + %fp_baz = alloca ptr, align 8 + store i32 0, ptr %retval, align 4 + store ptr @foo, ptr %fp_foo, align 8 + %0 = load ptr, ptr %fp_foo, align 8 + call void (...) %0() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] + store ptr @bar, ptr %fp_bar, align 8 + %1 = load ptr, ptr %fp_bar, align 8 + %2 = load i8, ptr %a, align 1 + %call = call i32 %1(i8 signext %2) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] + store ptr @baz, ptr %fp_baz, align 8 + %3 = load ptr, ptr %fp_baz, align 8 + %call1 = call ptr %3(ptr %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] + call void @foo() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] + %4 = load i8, ptr %a, align 1 + %call2 = call i32 @bar(i8 signext %4) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] + %call3 = call ptr @baz(ptr %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] + ret void +} + +;; Check that the numeric type id (md5 hash) for the below type ids are emitted +;; to the callgraph section. + +; CHECK: Hex dump of section '.callgraph': + +; CHECK-DAG: 2444f731 f5eecb3e +!4 = !{i64 0, !"_ZTSFvE.generalized"} +; CHECK-DAG: 5486bc59 814b8e30 +!5 = !{i64 0, !"_ZTSFicE.generalized"} +; CHECK-DAG: 7ade6814 f897fd77 +!6 = !{i64 0, !"_ZTSFPvS_E.generalized"} +; CHECK-DAG: caaf769a 600968fa +!7 = !{i64 0, !"_ZTSFiE.generalized"} diff --git a/llvm/test/CodeGen/call-graph-section.ll b/llvm/test/CodeGen/call-graph-section.ll deleted file mode 100644 index bb158d11e82c9..0 --- a/llvm/test/CodeGen/call-graph-section.ll +++ /dev/null @@ -1,73 +0,0 @@ -; Tests that we store the type identifiers in .callgraph section of the binary. - -; RUN: llc --call-graph-section -filetype=obj -o - < %s | \ -; RUN: llvm-readelf -x .callgraph - | FileCheck %s - -target triple = "x86_64-unknown-linux-gnu" - -define dso_local void @foo() #0 !type !4 { -entry: - ret void -} - -define dso_local i32 @bar(i8 signext %a) #0 !type !5 { -entry: - %a.addr = alloca i8, align 1 - store i8 %a, i8* %a.addr, align 1 - ret i32 0 -} - -define dso_local i32* @baz(i8* %a) #0 !type !6 { -entry: - %a.addr = alloca i8*, align 8 - store i8* %a, i8** %a.addr, align 8 - ret i32* null -} - -define dso_local i32 @main() #0 !type !7 { -entry: - %retval = alloca i32, align 4 - %fp_foo = alloca void (...)*, align 8 - %a = alloca i8, align 1 - %fp_bar = alloca i32 (i8)*, align 8 - %fp_baz = alloca i32* (i8*)*, align 8 - store i32 0, i32* %retval, align 4 - store void (...)* bitcast (void ()* @foo to void (...)*), void (...)** %fp_foo, align 8 - %0 = load void (...)*, void (...)** %fp_foo, align 8 - call void (...) %0() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] - store i32 (i8)* @bar, i32 (i8)** %fp_bar, align 8 - %1 = load i32 (i8)*, i32 (i8)** %fp_bar, align 8 - %2 = load i8, i8* %a, align 1 - %call = call i32 %1(i8 signext %2) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] - store i32* (i8*)* @baz, i32* (i8*)** %fp_baz, align 8 - %3 = load i32* (i8*)*, i32* (i8*)** %fp_baz, align 8 - %call1 = call i32* %3(i8* %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] - call void @foo() [ "callee_type"(meta
[llvm-branch-commits] [clang] [clang] Introduce CallGraphSection option (PR #117037)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/117037 >From 6a12be2c5b60a95a06875b0b2c4f14228d1fa882 Mon Sep 17 00:00:00 2001 From: prabhukr Date: Wed, 12 Mar 2025 23:30:01 + Subject: [PATCH] Fix EOF newlines. Created using spr 1.3.6-beta.1 --- clang/test/Driver/call-graph-section.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Driver/call-graph-section.c b/clang/test/Driver/call-graph-section.c index 108446729d857..5832aa6754137 100644 --- a/clang/test/Driver/call-graph-section.c +++ b/clang/test/Driver/call-graph-section.c @@ -2,4 +2,4 @@ // RUN: %clang -### -S -fcall-graph-section -fno-call-graph-section %s 2>&1 | FileCheck --check-prefix=NO-CALL-GRAPH-SECTION %s // CALL-GRAPH-SECTION: "-fcall-graph-section" -// NO-CALL-GRAPH-SECTION-NOT: "-fcall-graph-section" \ No newline at end of file +// NO-CALL-GRAPH-SECTION-NOT: "-fcall-graph-section" ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [llvm] Extract and propagate indirect call type id (PR #87575)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87575 >From 1a8d810d352fbe84c0521c7614689b60ade693c8 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Tue, 19 Nov 2024 15:25:34 -0800 Subject: [PATCH 1/7] Fixed the tests and addressed most of the review comments. Created using spr 1.3.6-beta.1 --- llvm/include/llvm/CodeGen/MachineFunction.h | 15 +++-- .../CodeGen/AArch64/call-site-info-typeid.ll | 28 +++-- .../test/CodeGen/ARM/call-site-info-typeid.ll | 28 +++-- .../CodeGen/MIR/X86/call-site-info-typeid.ll | 58 --- .../CodeGen/MIR/X86/call-site-info-typeid.mir | 13 ++--- .../CodeGen/Mips/call-site-info-typeid.ll | 28 +++-- .../test/CodeGen/X86/call-site-info-typeid.ll | 28 +++-- 7 files changed, 71 insertions(+), 127 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h index bb0b87a3a04a3..44633df38a651 100644 --- a/llvm/include/llvm/CodeGen/MachineFunction.h +++ b/llvm/include/llvm/CodeGen/MachineFunction.h @@ -493,7 +493,7 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { /// Callee type id. ConstantInt *TypeId = nullptr; -CallSiteInfo() {} +CallSiteInfo() = default; /// Extracts the numeric type id from the CallBase's type operand bundle, /// and sets TypeId. This is used as type id for the indirect call in the @@ -503,12 +503,11 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { if (!CB.isIndirectCall()) return; - auto Opt = CB.getOperandBundle(LLVMContext::OB_type); - if (!Opt.has_value()) { -errs() << "warning: cannot find indirect call type operand bundle for " - "call graph section\n"; + std::optional Opt = + CB.getOperandBundle(LLVMContext::OB_type); + // Return if the operand bundle for call graph section cannot be found. + if (!Opt.has_value()) return; - } // Get generalized type id string auto OB = Opt.value(); @@ -520,9 +519,9 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { "invalid type identifier"); // Compute numeric type id from generalized type id string - uint64_t TypeIdVal = llvm::MD5Hash(TypeIdStr->getString()); + uint64_t TypeIdVal = MD5Hash(TypeIdStr->getString()); IntegerType *Int64Ty = Type::getInt64Ty(CB.getContext()); - TypeId = llvm::ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false); + TypeId = ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false); } }; diff --git a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll index f0a6b44755c5c..f3b98c2c7a395 100644 --- a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll @@ -1,14 +1,9 @@ -; Tests that call site type ids can be extracted and set from type operand -; bundles. +;; Tests that call site type ids can be extracted and set from type operand +;; bundles. -; Verify the exact typeId value to ensure it is not garbage but the value -; computed as the type id from the type operand bundle. -; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu %s -stop-before=finalize-isel -o - | FileCheck %s - -; ModuleID = 'test.c' -source_filename = "test.c" -target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" -target triple = "aarch64-unknown-linux-gnu" +;; Verify the exact typeId value to ensure it is not garbage but the value +;; computed as the type id from the type operand bundle. +; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu < %s -stop-before=finalize-isel -o - | FileCheck %s define dso_local void @foo(i8 signext %a) !type !3 { entry: @@ -19,10 +14,10 @@ entry: define dso_local i32 @main() !type !4 { entry: %retval = alloca i32, align 4 - %fp = alloca void (i8)*, align 8 - store i32 0, i32* %retval, align 4 - store void (i8)* @foo, void (i8)** %fp, align 8 - %0 = load void (i8)*, void (i8)** %fp, align 8 + %fp = alloca ptr, align 8 + store i32 0, ptr %retval, align 4 + store ptr @foo, ptr %fp, align 8 + %0 = load ptr, ptr %fp, align 8 ; CHECK: callSites: ; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: ; CHECK-NEXT: 7854600665770582568 } @@ -30,10 +25,5 @@ entry: ret i32 0 } -!llvm.module.flags = !{!0, !1, !2} - -!0 = !{i32 1, !"wchar_size", i32 4} -!1 = !{i32 7, !"uwtable", i32 1} -!2 = !{i32 7, !"frame-pointer", i32 2} !3 = !{i64 0, !"_ZTSFvcE.generalized"} !4 = !{i64 0, !"_ZTSFiE.generalized"} diff --git a/llvm/test/CodeGen/ARM/call-site-info-typeid.ll b/llvm/test/CodeGen/ARM/call-site-info-typeid.ll index ec7f8a425051b..9feeef9a564cc 100644 --- a/llvm/test/CodeGen/ARM/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/ARM/call-site-info-typeid.ll @@ -1,14 +1,9 @@ -; Tests that call site type ids can be extracted and set from type operand -; bundles. +;; Tests that ca
[llvm-branch-commits] [llvm] [llvm] Extract and propagate indirect call type id (PR #87575)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87575 >From 1a8d810d352fbe84c0521c7614689b60ade693c8 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Tue, 19 Nov 2024 15:25:34 -0800 Subject: [PATCH 1/7] Fixed the tests and addressed most of the review comments. Created using spr 1.3.6-beta.1 --- llvm/include/llvm/CodeGen/MachineFunction.h | 15 +++-- .../CodeGen/AArch64/call-site-info-typeid.ll | 28 +++-- .../test/CodeGen/ARM/call-site-info-typeid.ll | 28 +++-- .../CodeGen/MIR/X86/call-site-info-typeid.ll | 58 --- .../CodeGen/MIR/X86/call-site-info-typeid.mir | 13 ++--- .../CodeGen/Mips/call-site-info-typeid.ll | 28 +++-- .../test/CodeGen/X86/call-site-info-typeid.ll | 28 +++-- 7 files changed, 71 insertions(+), 127 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h index bb0b87a3a04a3..44633df38a651 100644 --- a/llvm/include/llvm/CodeGen/MachineFunction.h +++ b/llvm/include/llvm/CodeGen/MachineFunction.h @@ -493,7 +493,7 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { /// Callee type id. ConstantInt *TypeId = nullptr; -CallSiteInfo() {} +CallSiteInfo() = default; /// Extracts the numeric type id from the CallBase's type operand bundle, /// and sets TypeId. This is used as type id for the indirect call in the @@ -503,12 +503,11 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { if (!CB.isIndirectCall()) return; - auto Opt = CB.getOperandBundle(LLVMContext::OB_type); - if (!Opt.has_value()) { -errs() << "warning: cannot find indirect call type operand bundle for " - "call graph section\n"; + std::optional Opt = + CB.getOperandBundle(LLVMContext::OB_type); + // Return if the operand bundle for call graph section cannot be found. + if (!Opt.has_value()) return; - } // Get generalized type id string auto OB = Opt.value(); @@ -520,9 +519,9 @@ class LLVM_EXTERNAL_VISIBILITY MachineFunction { "invalid type identifier"); // Compute numeric type id from generalized type id string - uint64_t TypeIdVal = llvm::MD5Hash(TypeIdStr->getString()); + uint64_t TypeIdVal = MD5Hash(TypeIdStr->getString()); IntegerType *Int64Ty = Type::getInt64Ty(CB.getContext()); - TypeId = llvm::ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false); + TypeId = ConstantInt::get(Int64Ty, TypeIdVal, /*IsSigned=*/false); } }; diff --git a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll index f0a6b44755c5c..f3b98c2c7a395 100644 --- a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll @@ -1,14 +1,9 @@ -; Tests that call site type ids can be extracted and set from type operand -; bundles. +;; Tests that call site type ids can be extracted and set from type operand +;; bundles. -; Verify the exact typeId value to ensure it is not garbage but the value -; computed as the type id from the type operand bundle. -; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu %s -stop-before=finalize-isel -o - | FileCheck %s - -; ModuleID = 'test.c' -source_filename = "test.c" -target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128" -target triple = "aarch64-unknown-linux-gnu" +;; Verify the exact typeId value to ensure it is not garbage but the value +;; computed as the type id from the type operand bundle. +; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu < %s -stop-before=finalize-isel -o - | FileCheck %s define dso_local void @foo(i8 signext %a) !type !3 { entry: @@ -19,10 +14,10 @@ entry: define dso_local i32 @main() !type !4 { entry: %retval = alloca i32, align 4 - %fp = alloca void (i8)*, align 8 - store i32 0, i32* %retval, align 4 - store void (i8)* @foo, void (i8)** %fp, align 8 - %0 = load void (i8)*, void (i8)** %fp, align 8 + %fp = alloca ptr, align 8 + store i32 0, ptr %retval, align 4 + store ptr @foo, ptr %fp, align 8 + %0 = load ptr, ptr %fp, align 8 ; CHECK: callSites: ; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: ; CHECK-NEXT: 7854600665770582568 } @@ -30,10 +25,5 @@ entry: ret i32 0 } -!llvm.module.flags = !{!0, !1, !2} - -!0 = !{i32 1, !"wchar_size", i32 4} -!1 = !{i32 7, !"uwtable", i32 1} -!2 = !{i32 7, !"frame-pointer", i32 2} !3 = !{i64 0, !"_ZTSFvcE.generalized"} !4 = !{i64 0, !"_ZTSFiE.generalized"} diff --git a/llvm/test/CodeGen/ARM/call-site-info-typeid.ll b/llvm/test/CodeGen/ARM/call-site-info-typeid.ll index ec7f8a425051b..9feeef9a564cc 100644 --- a/llvm/test/CodeGen/ARM/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/ARM/call-site-info-typeid.ll @@ -1,14 +1,9 @@ -; Tests that call site type ids can be extracted and set from type operand -; bundles. +;; Tests that ca
[llvm-branch-commits] [llvm] [llvm][AsmPrinter] Emit call graph section (PR #87576)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/87576 >From 6b67376bd5e1f21606017c83cc67f2186ba36a33 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran Date: Thu, 13 Mar 2025 01:41:04 + Subject: [PATCH 1/5] Updated the test as reviewers suggested. Created using spr 1.3.6-beta.1 --- llvm/test/CodeGen/X86/call-graph-section.ll | 66 +++ llvm/test/CodeGen/call-graph-section.ll | 73 - 2 files changed, 66 insertions(+), 73 deletions(-) create mode 100644 llvm/test/CodeGen/X86/call-graph-section.ll delete mode 100644 llvm/test/CodeGen/call-graph-section.ll diff --git a/llvm/test/CodeGen/X86/call-graph-section.ll b/llvm/test/CodeGen/X86/call-graph-section.ll new file mode 100644 index 0..a77a2b8051ed3 --- /dev/null +++ b/llvm/test/CodeGen/X86/call-graph-section.ll @@ -0,0 +1,66 @@ +;; Tests that we store the type identifiers in .callgraph section of the binary. + +; RUN: llc --call-graph-section -filetype=obj -o - < %s | \ +; RUN: llvm-readelf -x .callgraph - | FileCheck %s + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local void @foo() #0 !type !4 { +entry: + ret void +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local i32 @bar(i8 signext %a) #0 !type !5 { +entry: + %a.addr = alloca i8, align 1 + store i8 %a, ptr %a.addr, align 1 + ret i32 0 +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local ptr @baz(ptr %a) #0 !type !6 { +entry: + %a.addr = alloca ptr, align 8 + store ptr %a, ptr %a.addr, align 8 + ret ptr null +} + +; Function Attrs: noinline nounwind optnone uwtable +define dso_local void @main() #0 !type !7 { +entry: + %retval = alloca i32, align 4 + %fp_foo = alloca ptr, align 8 + %a = alloca i8, align 1 + %fp_bar = alloca ptr, align 8 + %fp_baz = alloca ptr, align 8 + store i32 0, ptr %retval, align 4 + store ptr @foo, ptr %fp_foo, align 8 + %0 = load ptr, ptr %fp_foo, align 8 + call void (...) %0() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] + store ptr @bar, ptr %fp_bar, align 8 + %1 = load ptr, ptr %fp_bar, align 8 + %2 = load i8, ptr %a, align 1 + %call = call i32 %1(i8 signext %2) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] + store ptr @baz, ptr %fp_baz, align 8 + %3 = load ptr, ptr %fp_baz, align 8 + %call1 = call ptr %3(ptr %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] + call void @foo() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] + %4 = load i8, ptr %a, align 1 + %call2 = call i32 @bar(i8 signext %4) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] + %call3 = call ptr @baz(ptr %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] + ret void +} + +;; Check that the numeric type id (md5 hash) for the below type ids are emitted +;; to the callgraph section. + +; CHECK: Hex dump of section '.callgraph': + +; CHECK-DAG: 2444f731 f5eecb3e +!4 = !{i64 0, !"_ZTSFvE.generalized"} +; CHECK-DAG: 5486bc59 814b8e30 +!5 = !{i64 0, !"_ZTSFicE.generalized"} +; CHECK-DAG: 7ade6814 f897fd77 +!6 = !{i64 0, !"_ZTSFPvS_E.generalized"} +; CHECK-DAG: caaf769a 600968fa +!7 = !{i64 0, !"_ZTSFiE.generalized"} diff --git a/llvm/test/CodeGen/call-graph-section.ll b/llvm/test/CodeGen/call-graph-section.ll deleted file mode 100644 index bb158d11e82c9..0 --- a/llvm/test/CodeGen/call-graph-section.ll +++ /dev/null @@ -1,73 +0,0 @@ -; Tests that we store the type identifiers in .callgraph section of the binary. - -; RUN: llc --call-graph-section -filetype=obj -o - < %s | \ -; RUN: llvm-readelf -x .callgraph - | FileCheck %s - -target triple = "x86_64-unknown-linux-gnu" - -define dso_local void @foo() #0 !type !4 { -entry: - ret void -} - -define dso_local i32 @bar(i8 signext %a) #0 !type !5 { -entry: - %a.addr = alloca i8, align 1 - store i8 %a, i8* %a.addr, align 1 - ret i32 0 -} - -define dso_local i32* @baz(i8* %a) #0 !type !6 { -entry: - %a.addr = alloca i8*, align 8 - store i8* %a, i8** %a.addr, align 8 - ret i32* null -} - -define dso_local i32 @main() #0 !type !7 { -entry: - %retval = alloca i32, align 4 - %fp_foo = alloca void (...)*, align 8 - %a = alloca i8, align 1 - %fp_bar = alloca i32 (i8)*, align 8 - %fp_baz = alloca i32* (i8*)*, align 8 - store i32 0, i32* %retval, align 4 - store void (...)* bitcast (void ()* @foo to void (...)*), void (...)** %fp_foo, align 8 - %0 = load void (...)*, void (...)** %fp_foo, align 8 - call void (...) %0() [ "callee_type"(metadata !"_ZTSFvE.generalized") ] - store i32 (i8)* @bar, i32 (i8)** %fp_bar, align 8 - %1 = load i32 (i8)*, i32 (i8)** %fp_bar, align 8 - %2 = load i8, i8* %a, align 1 - %call = call i32 %1(i8 signext %2) [ "callee_type"(metadata !"_ZTSFicE.generalized") ] - store i32* (i8*)* @baz, i32* (i8*)** %fp_baz, align 8 - %3 = load i32* (i8*)*, i32* (i8*)** %fp_baz, align 8 - %call1 = call i32* %3(i8* %a) [ "callee_type"(metadata !"_ZTSFPvS_E.generalized") ] - call void @foo() [ "callee_type"(meta
[llvm-branch-commits] [clang] [llvm] [llvm] Introduce callee_type metadata (PR #87573)
https://github.com/nikic approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/87573 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [clang] callee_type metadata for indirect calls (PR #117036)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/117036 >From b7fbe09b32ff02d4f7c52d82fbf8b5cd28138852 Mon Sep 17 00:00:00 2001 From: prabhukr Date: Wed, 23 Apr 2025 04:05:47 + Subject: [PATCH] Address review comments. Created using spr 1.3.6-beta.1 --- clang/lib/CodeGen/CGCall.cpp| 8 clang/lib/CodeGen/CodeGenModule.cpp | 10 +- clang/lib/CodeGen/CodeGenModule.h | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 185ee1a970aac..d8ab7140f7943 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -5780,19 +5780,19 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, if (callOrInvoke) { *callOrInvoke = CI; if (CGM.getCodeGenOpts().CallGraphSection) { - assert((TargetDecl && TargetDecl->getFunctionType() || - Callee.getAbstractInfo().getCalleeFunctionProtoType()) && - "cannot find callsite type"); QualType CST; if (TargetDecl && TargetDecl->getFunctionType()) CST = QualType(TargetDecl->getFunctionType(), 0); else if (const auto *FPT = Callee.getAbstractInfo().getCalleeFunctionProtoType()) CST = QualType(FPT, 0); + else +llvm_unreachable( +"Cannot find the callee type to generate callee_type metadata."); // Set type identifier metadata of indirect calls for call graph section. if (!CST.isNull()) -CGM.CreateCalleeTypeMetadataForIcall(CST, *callOrInvoke); +CGM.createCalleeTypeMetadataForIcall(CST, *callOrInvoke); } } diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 43cd2405571cf..2fc99639a75cb 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2654,7 +2654,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, // Skip available_externally functions. They won't be codegen'ed in the // current module anyway. if (getContext().GetGVALinkageForFunction(FD) != GVA_AvailableExternally) -CreateFunctionTypeMetadataForIcall(FD, F); +createFunctionTypeMetadataForIcall(FD, F); } } @@ -2868,7 +2868,7 @@ static bool hasExistingGeneralizedTypeMD(llvm::Function *F) { return MD->hasGeneralizedMDString(); } -void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, +void CodeGenModule::createFunctionTypeMetadataForIcall(const FunctionDecl *FD, llvm::Function *F) { if (CodeGenOpts.CallGraphSection && !hasExistingGeneralizedTypeMD(F) && (!F->hasLocalLinkage() || @@ -2898,7 +2898,7 @@ void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, F->addTypeMetadata(0, llvm::ConstantAsMetadata::get(CrossDsoTypeId)); } -void CodeGenModule::CreateCalleeTypeMetadataForIcall(const QualType &QT, +void CodeGenModule::createCalleeTypeMetadataForIcall(const QualType &QT, llvm::CallBase *CB) { // Only if needed for call graph section and only for indirect calls. if (!CodeGenOpts.CallGraphSection || !CB->isIndirectCall()) @@ -2909,7 +2909,7 @@ void CodeGenModule::CreateCalleeTypeMetadataForIcall(const QualType &QT, getLLVMContext(), {llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( llvm::Type::getInt64Ty(getLLVMContext()), 0)), TypeIdMD}); - llvm::MDTuple *MDN = llvm::MDNode::get(getLLVMContext(), { TypeTuple }); + llvm::MDTuple *MDN = llvm::MDNode::get(getLLVMContext(), {TypeTuple}); CB->setMetadata(llvm::LLVMContext::MD_callee_type, MDN); } @@ -3041,7 +3041,7 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F, // jump table. if (!CodeGenOpts.SanitizeCfiCrossDso || !CodeGenOpts.SanitizeCfiCanonicalJumpTables) -CreateFunctionTypeMetadataForIcall(FD, F); +createFunctionTypeMetadataForIcall(FD, F); if (LangOpts.Sanitize.has(SanitizerKind::KCFI)) setKCFIType(FD, F); diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index dfbe4388349dd..4b53f0f241b52 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -1619,11 +1619,11 @@ class CodeGenModule : public CodeGenTypeCache { llvm::Metadata *CreateMetadataIdentifierGeneralized(QualType T); /// Create and attach type metadata to the given function. - void CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, + void createFunctionTypeMetadataForIcall(const FunctionDecl *FD, llvm::Function *F); /// Create and attach type metadata to the given call. - void CreateCalleeTypeMetadataForIcall(const QualType &QT, llvm::CallBase *CB); + void createCa
[llvm-branch-commits] [clang] [clang] callee_type metadata for indirect calls (PR #117036)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/117036 >From b7fbe09b32ff02d4f7c52d82fbf8b5cd28138852 Mon Sep 17 00:00:00 2001 From: prabhukr Date: Wed, 23 Apr 2025 04:05:47 + Subject: [PATCH] Address review comments. Created using spr 1.3.6-beta.1 --- clang/lib/CodeGen/CGCall.cpp| 8 clang/lib/CodeGen/CodeGenModule.cpp | 10 +- clang/lib/CodeGen/CodeGenModule.h | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 185ee1a970aac..d8ab7140f7943 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -5780,19 +5780,19 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, if (callOrInvoke) { *callOrInvoke = CI; if (CGM.getCodeGenOpts().CallGraphSection) { - assert((TargetDecl && TargetDecl->getFunctionType() || - Callee.getAbstractInfo().getCalleeFunctionProtoType()) && - "cannot find callsite type"); QualType CST; if (TargetDecl && TargetDecl->getFunctionType()) CST = QualType(TargetDecl->getFunctionType(), 0); else if (const auto *FPT = Callee.getAbstractInfo().getCalleeFunctionProtoType()) CST = QualType(FPT, 0); + else +llvm_unreachable( +"Cannot find the callee type to generate callee_type metadata."); // Set type identifier metadata of indirect calls for call graph section. if (!CST.isNull()) -CGM.CreateCalleeTypeMetadataForIcall(CST, *callOrInvoke); +CGM.createCalleeTypeMetadataForIcall(CST, *callOrInvoke); } } diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 43cd2405571cf..2fc99639a75cb 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2654,7 +2654,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, // Skip available_externally functions. They won't be codegen'ed in the // current module anyway. if (getContext().GetGVALinkageForFunction(FD) != GVA_AvailableExternally) -CreateFunctionTypeMetadataForIcall(FD, F); +createFunctionTypeMetadataForIcall(FD, F); } } @@ -2868,7 +2868,7 @@ static bool hasExistingGeneralizedTypeMD(llvm::Function *F) { return MD->hasGeneralizedMDString(); } -void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, +void CodeGenModule::createFunctionTypeMetadataForIcall(const FunctionDecl *FD, llvm::Function *F) { if (CodeGenOpts.CallGraphSection && !hasExistingGeneralizedTypeMD(F) && (!F->hasLocalLinkage() || @@ -2898,7 +2898,7 @@ void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, F->addTypeMetadata(0, llvm::ConstantAsMetadata::get(CrossDsoTypeId)); } -void CodeGenModule::CreateCalleeTypeMetadataForIcall(const QualType &QT, +void CodeGenModule::createCalleeTypeMetadataForIcall(const QualType &QT, llvm::CallBase *CB) { // Only if needed for call graph section and only for indirect calls. if (!CodeGenOpts.CallGraphSection || !CB->isIndirectCall()) @@ -2909,7 +2909,7 @@ void CodeGenModule::CreateCalleeTypeMetadataForIcall(const QualType &QT, getLLVMContext(), {llvm::ConstantAsMetadata::get(llvm::ConstantInt::get( llvm::Type::getInt64Ty(getLLVMContext()), 0)), TypeIdMD}); - llvm::MDTuple *MDN = llvm::MDNode::get(getLLVMContext(), { TypeTuple }); + llvm::MDTuple *MDN = llvm::MDNode::get(getLLVMContext(), {TypeTuple}); CB->setMetadata(llvm::LLVMContext::MD_callee_type, MDN); } @@ -3041,7 +3041,7 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F, // jump table. if (!CodeGenOpts.SanitizeCfiCrossDso || !CodeGenOpts.SanitizeCfiCanonicalJumpTables) -CreateFunctionTypeMetadataForIcall(FD, F); +createFunctionTypeMetadataForIcall(FD, F); if (LangOpts.Sanitize.has(SanitizerKind::KCFI)) setKCFIType(FD, F); diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index dfbe4388349dd..4b53f0f241b52 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -1619,11 +1619,11 @@ class CodeGenModule : public CodeGenTypeCache { llvm::Metadata *CreateMetadataIdentifierGeneralized(QualType T); /// Create and attach type metadata to the given function. - void CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, + void createFunctionTypeMetadataForIcall(const FunctionDecl *FD, llvm::Function *F); /// Create and attach type metadata to the given call. - void CreateCalleeTypeMetadataForIcall(const QualType &QT, llvm::CallBase *CB); + void createCa
[llvm-branch-commits] ELF: Introduce R_AARCH64_PATCHINST relocation type. (PR #133534)
https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/133534 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] release/21.x: Revert "Move python binding tests to lit framework" (#149012) (PR #149570)
llvmbot wrote: @llvm/pr-subscribers-clang Author: None (llvmbot) Changes Backport 7a9bef0166951a61bc7094514a20471ae45f6090 Requested by: @mgorny --- Full diff: https://github.com/llvm/llvm-project/pull/149570.diff 40 Files Affected: - (modified) .github/workflows/libclang-python-tests.yml (+2-2) - (modified) clang/CMakeLists.txt (+1) - (added) clang/bindings/python/tests/CMakeLists.txt (+66) - (renamed) clang/bindings/python/tests/__init__.py () - (renamed) clang/bindings/python/tests/cindex/INPUTS/a.inc () - (renamed) clang/bindings/python/tests/cindex/INPUTS/b.inc () - (renamed) clang/bindings/python/tests/cindex/INPUTS/compile_commands.json () - (renamed) clang/bindings/python/tests/cindex/INPUTS/header1.h () - (renamed) clang/bindings/python/tests/cindex/INPUTS/header2.h () - (renamed) clang/bindings/python/tests/cindex/INPUTS/header3.h () - (renamed) clang/bindings/python/tests/cindex/INPUTS/hello.cpp () - (renamed) clang/bindings/python/tests/cindex/INPUTS/include.cpp () - (renamed) clang/bindings/python/tests/cindex/INPUTS/parse_arguments.c () - (renamed) clang/bindings/python/tests/cindex/INPUTS/testfile.c () - (renamed) clang/bindings/python/tests/cindex/__init__.py () - (renamed) clang/bindings/python/tests/cindex/test_access_specifiers.py () - (renamed) clang/bindings/python/tests/cindex/test_cdb.py () - (renamed) clang/bindings/python/tests/cindex/test_code_completion.py () - (renamed) clang/bindings/python/tests/cindex/test_comment.py () - (renamed) clang/bindings/python/tests/cindex/test_cursor.py () - (renamed) clang/bindings/python/tests/cindex/test_cursor_kind.py () - (renamed) clang/bindings/python/tests/cindex/test_diagnostics.py () - (renamed) clang/bindings/python/tests/cindex/test_enums.py () - (renamed) clang/bindings/python/tests/cindex/test_exception_specification_kind.py () - (renamed) clang/bindings/python/tests/cindex/test_file.py () - (renamed) clang/bindings/python/tests/cindex/test_index.py () - (renamed) clang/bindings/python/tests/cindex/test_lib.py () - (renamed) clang/bindings/python/tests/cindex/test_linkage.py () - (renamed) clang/bindings/python/tests/cindex/test_location.py () - (renamed) clang/bindings/python/tests/cindex/test_rewrite.py () - (renamed) clang/bindings/python/tests/cindex/test_source_range.py () - (renamed) clang/bindings/python/tests/cindex/test_tls_kind.py () - (renamed) clang/bindings/python/tests/cindex/test_token_kind.py () - (renamed) clang/bindings/python/tests/cindex/test_tokens.py () - (renamed) clang/bindings/python/tests/cindex/test_translation_unit.py () - (renamed) clang/bindings/python/tests/cindex/test_type.py () - (renamed) clang/bindings/python/tests/cindex/util.py () - (modified) clang/test/CMakeLists.txt (-11) - (removed) clang/test/bindings/python/bindings.sh (-38) - (removed) clang/test/bindings/python/lit.local.cfg (-41) ``diff diff --git a/.github/workflows/libclang-python-tests.yml b/.github/workflows/libclang-python-tests.yml index 43b50cec61716..50ef4acf2feb1 100644 --- a/.github/workflows/libclang-python-tests.yml +++ b/.github/workflows/libclang-python-tests.yml @@ -10,15 +10,15 @@ on: - 'main' paths: - 'clang/bindings/python/**' - - 'clang/test/bindings/python/**' - 'clang/tools/libclang/**' + - 'clang/CMakeList.txt' - '.github/workflows/libclang-python-tests.yml' - '.github/workflows/llvm-project-tests.yml' pull_request: paths: - 'clang/bindings/python/**' - - 'clang/test/bindings/python/**' - 'clang/tools/libclang/**' + - 'clang/CMakeList.txt' - '.github/workflows/libclang-python-tests.yml' - '.github/workflows/llvm-project-tests.yml' diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt index f4c309f1b35c0..1bb73599970c1 100644 --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -536,6 +536,7 @@ if( CLANG_INCLUDE_TESTS ) clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg ) add_subdirectory(test) + add_subdirectory(bindings/python/tests) if(CLANG_BUILT_STANDALONE) umbrella_lit_testsuite_end(check-all) diff --git a/clang/bindings/python/tests/CMakeLists.txt b/clang/bindings/python/tests/CMakeLists.txt new file mode 100644 index 0..a0ddabc21bb41 --- /dev/null +++ b/clang/bindings/python/tests/CMakeLists.txt @@ -0,0 +1,66 @@ +# Test target to run Python test suite from main build. + +# Avoid configurations including '-include' from interfering with +# our tests by setting CLANG_NO_DEFAULT_CONFIG. +add_custom_target(check-clang-python +COMMAND ${CMAKE_COMMAND} -E env +CLANG_NO_DEFAULT_CONFIG=1 +CLANG_LIBRARY_PATH=$ +"${Python3_EXECUTABLE}" -m unittest discover +DEPENDS libclang +WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..) + +set(RUN_PYTHON_TESTS TRUE) +set_target_properties(check-clang-python PROPERTIES FOLDER "Clang/Tests") + +# Tests require lib
[llvm-branch-commits] [clang] [llvm] release/21.x: Revert "Move python binding tests to lit framework" (#149012) (PR #149570)
llvmbot wrote: @llvm/pr-subscribers-github-workflow Author: None (llvmbot) Changes Backport 7a9bef0166951a61bc7094514a20471ae45f6090 Requested by: @mgorny --- Full diff: https://github.com/llvm/llvm-project/pull/149570.diff 40 Files Affected: - (modified) .github/workflows/libclang-python-tests.yml (+2-2) - (modified) clang/CMakeLists.txt (+1) - (added) clang/bindings/python/tests/CMakeLists.txt (+66) - (renamed) clang/bindings/python/tests/__init__.py () - (renamed) clang/bindings/python/tests/cindex/INPUTS/a.inc () - (renamed) clang/bindings/python/tests/cindex/INPUTS/b.inc () - (renamed) clang/bindings/python/tests/cindex/INPUTS/compile_commands.json () - (renamed) clang/bindings/python/tests/cindex/INPUTS/header1.h () - (renamed) clang/bindings/python/tests/cindex/INPUTS/header2.h () - (renamed) clang/bindings/python/tests/cindex/INPUTS/header3.h () - (renamed) clang/bindings/python/tests/cindex/INPUTS/hello.cpp () - (renamed) clang/bindings/python/tests/cindex/INPUTS/include.cpp () - (renamed) clang/bindings/python/tests/cindex/INPUTS/parse_arguments.c () - (renamed) clang/bindings/python/tests/cindex/INPUTS/testfile.c () - (renamed) clang/bindings/python/tests/cindex/__init__.py () - (renamed) clang/bindings/python/tests/cindex/test_access_specifiers.py () - (renamed) clang/bindings/python/tests/cindex/test_cdb.py () - (renamed) clang/bindings/python/tests/cindex/test_code_completion.py () - (renamed) clang/bindings/python/tests/cindex/test_comment.py () - (renamed) clang/bindings/python/tests/cindex/test_cursor.py () - (renamed) clang/bindings/python/tests/cindex/test_cursor_kind.py () - (renamed) clang/bindings/python/tests/cindex/test_diagnostics.py () - (renamed) clang/bindings/python/tests/cindex/test_enums.py () - (renamed) clang/bindings/python/tests/cindex/test_exception_specification_kind.py () - (renamed) clang/bindings/python/tests/cindex/test_file.py () - (renamed) clang/bindings/python/tests/cindex/test_index.py () - (renamed) clang/bindings/python/tests/cindex/test_lib.py () - (renamed) clang/bindings/python/tests/cindex/test_linkage.py () - (renamed) clang/bindings/python/tests/cindex/test_location.py () - (renamed) clang/bindings/python/tests/cindex/test_rewrite.py () - (renamed) clang/bindings/python/tests/cindex/test_source_range.py () - (renamed) clang/bindings/python/tests/cindex/test_tls_kind.py () - (renamed) clang/bindings/python/tests/cindex/test_token_kind.py () - (renamed) clang/bindings/python/tests/cindex/test_tokens.py () - (renamed) clang/bindings/python/tests/cindex/test_translation_unit.py () - (renamed) clang/bindings/python/tests/cindex/test_type.py () - (renamed) clang/bindings/python/tests/cindex/util.py () - (modified) clang/test/CMakeLists.txt (-11) - (removed) clang/test/bindings/python/bindings.sh (-38) - (removed) clang/test/bindings/python/lit.local.cfg (-41) ``diff diff --git a/.github/workflows/libclang-python-tests.yml b/.github/workflows/libclang-python-tests.yml index 43b50cec61716..50ef4acf2feb1 100644 --- a/.github/workflows/libclang-python-tests.yml +++ b/.github/workflows/libclang-python-tests.yml @@ -10,15 +10,15 @@ on: - 'main' paths: - 'clang/bindings/python/**' - - 'clang/test/bindings/python/**' - 'clang/tools/libclang/**' + - 'clang/CMakeList.txt' - '.github/workflows/libclang-python-tests.yml' - '.github/workflows/llvm-project-tests.yml' pull_request: paths: - 'clang/bindings/python/**' - - 'clang/test/bindings/python/**' - 'clang/tools/libclang/**' + - 'clang/CMakeList.txt' - '.github/workflows/libclang-python-tests.yml' - '.github/workflows/llvm-project-tests.yml' diff --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt index f4c309f1b35c0..1bb73599970c1 100644 --- a/clang/CMakeLists.txt +++ b/clang/CMakeLists.txt @@ -536,6 +536,7 @@ if( CLANG_INCLUDE_TESTS ) clang_unit_site_config=${CMAKE_CURRENT_BINARY_DIR}/test/Unit/lit.site.cfg ) add_subdirectory(test) + add_subdirectory(bindings/python/tests) if(CLANG_BUILT_STANDALONE) umbrella_lit_testsuite_end(check-all) diff --git a/clang/bindings/python/tests/CMakeLists.txt b/clang/bindings/python/tests/CMakeLists.txt new file mode 100644 index 0..a0ddabc21bb41 --- /dev/null +++ b/clang/bindings/python/tests/CMakeLists.txt @@ -0,0 +1,66 @@ +# Test target to run Python test suite from main build. + +# Avoid configurations including '-include' from interfering with +# our tests by setting CLANG_NO_DEFAULT_CONFIG. +add_custom_target(check-clang-python +COMMAND ${CMAKE_COMMAND} -E env +CLANG_NO_DEFAULT_CONFIG=1 +CLANG_LIBRARY_PATH=$ +"${Python3_EXECUTABLE}" -m unittest discover +DEPENDS libclang +WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/..) + +set(RUN_PYTHON_TESTS TRUE) +set_target_properties(check-clang-python PROPERTIES FOLDER "Clang/Tests") + +# Tests r
[llvm-branch-commits] [clang] [llvm] release/21.x: Revert "Move python binding tests to lit framework" (#149012) (PR #149570)
https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/149570 Backport 7a9bef0166951a61bc7094514a20471ae45f6090 Requested by: @mgorny >From 7dce8934ebdc61a28653281e216631e2d3a6b1e2 Mon Sep 17 00:00:00 2001 From: Jannick Kremer Date: Wed, 16 Jul 2025 05:32:08 +0100 Subject: [PATCH] Revert "Move python binding tests to lit framework" (#149012) This reverts commit f8707f994af2582f6dc58190106946efeb43bf05. (cherry picked from commit 7a9bef0166951a61bc7094514a20471ae45f6090) --- .github/workflows/libclang-python-tests.yml | 4 +- clang/CMakeLists.txt | 1 + clang/bindings/python/tests/CMakeLists.txt| 66 +++ .../bindings/python/tests/__init__.py | 0 .../bindings/python/tests/cindex/INPUTS/a.inc | 0 .../bindings/python/tests/cindex/INPUTS/b.inc | 0 .../tests/cindex/INPUTS/compile_commands.json | 0 .../python/tests/cindex/INPUTS/header1.h | 0 .../python/tests/cindex/INPUTS/header2.h | 0 .../python/tests/cindex/INPUTS/header3.h | 0 .../python/tests/cindex/INPUTS/hello.cpp | 0 .../python/tests/cindex/INPUTS/include.cpp| 0 .../tests/cindex/INPUTS/parse_arguments.c | 0 .../python/tests/cindex/INPUTS/testfile.c | 0 .../bindings/python/tests/cindex/__init__.py | 0 .../tests/cindex/test_access_specifiers.py| 0 .../bindings/python/tests/cindex/test_cdb.py | 0 .../tests/cindex/test_code_completion.py | 0 .../python/tests/cindex/test_comment.py | 0 .../python/tests/cindex/test_cursor.py| 0 .../python/tests/cindex/test_cursor_kind.py | 0 .../python/tests/cindex/test_diagnostics.py | 0 .../python/tests/cindex/test_enums.py | 0 .../test_exception_specification_kind.py | 0 .../bindings/python/tests/cindex/test_file.py | 0 .../python/tests/cindex/test_index.py | 0 .../bindings/python/tests/cindex/test_lib.py | 0 .../python/tests/cindex/test_linkage.py | 0 .../python/tests/cindex/test_location.py | 0 .../python/tests/cindex/test_rewrite.py | 0 .../python/tests/cindex/test_source_range.py | 0 .../python/tests/cindex/test_tls_kind.py | 0 .../python/tests/cindex/test_token_kind.py| 0 .../python/tests/cindex/test_tokens.py| 0 .../tests/cindex/test_translation_unit.py | 0 .../bindings/python/tests/cindex/test_type.py | 0 .../bindings/python/tests/cindex/util.py | 0 clang/test/CMakeLists.txt | 11 clang/test/bindings/python/bindings.sh| 38 --- clang/test/bindings/python/lit.local.cfg | 41 40 files changed, 69 insertions(+), 92 deletions(-) create mode 100644 clang/bindings/python/tests/CMakeLists.txt rename clang/{test => }/bindings/python/tests/__init__.py (100%) rename clang/{test => }/bindings/python/tests/cindex/INPUTS/a.inc (100%) rename clang/{test => }/bindings/python/tests/cindex/INPUTS/b.inc (100%) rename clang/{test => }/bindings/python/tests/cindex/INPUTS/compile_commands.json (100%) rename clang/{test => }/bindings/python/tests/cindex/INPUTS/header1.h (100%) rename clang/{test => }/bindings/python/tests/cindex/INPUTS/header2.h (100%) rename clang/{test => }/bindings/python/tests/cindex/INPUTS/header3.h (100%) rename clang/{test => }/bindings/python/tests/cindex/INPUTS/hello.cpp (100%) rename clang/{test => }/bindings/python/tests/cindex/INPUTS/include.cpp (100%) rename clang/{test => }/bindings/python/tests/cindex/INPUTS/parse_arguments.c (100%) rename clang/{test => }/bindings/python/tests/cindex/INPUTS/testfile.c (100%) rename clang/{test => }/bindings/python/tests/cindex/__init__.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_access_specifiers.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_cdb.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_code_completion.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_comment.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_cursor.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_cursor_kind.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_diagnostics.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_enums.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_exception_specification_kind.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_file.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_index.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_lib.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_linkage.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_location.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_rewrite.py (100%) rename clang/{test => }/bindings/python/tests/cindex/test_source_range.py (100%) rename clang/{test => }/bindi
[llvm-branch-commits] [mlir] [mlir] Nominate MLIR Egress category maintainers (PR #149487)
https://github.com/matthias-springer approved this pull request. https://github.com/llvm/llvm-project/pull/149487 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [LifetimeSafety] Enhance benchmark script for ExpiredLoans analysis (PR #149577)
https://github.com/usx95 edited https://github.com/llvm/llvm-project/pull/149577 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] separate comments into categories (PR #149564)
@@ -210,12 +229,17 @@ serializeCommonAttributes(const Info &I, json::Object &Obj, } if (!I.Description.empty()) { -json::Value DescArray = json::Array(); -auto &DescArrayRef = *DescArray.getAsArray(); -DescArrayRef.reserve(I.Description.size()); -for (const auto &Comment : I.Description) - DescArrayRef.push_back(serializeComment(Comment)); -Obj["Description"] = DescArray; +Object Description = Object(); +// Skip straight to the FullComment's children +auto &Comments = I.Description.at(0).Children; +for (const auto &CommentInfo : Comments) { + json::Value Comment = serializeComment(*CommentInfo, Description); + // Paragraph comments might not be children + if (auto *ParagraphComment = + Comment.getAsObject()->get("ParagraphComment")) +insertComment(Description, *ParagraphComment, "ParagraphComments"); evelez7 wrote: Not really, because all paragraph comments were previously handled. This is meant to signal that there are top level `ParagraphComment`s that can be returned from `serializeComment` that need to be manually inserted into `Description` with this modified scheme. They can't be added like brief comments now are because we can't be sure if the `ParagraphComment` is nested (the text of a brief command is a paragraph comment). So, if the returned comment is a `ParagraphComment`, then it must be a top-level, standalone comment without a command. Maybe this comment could use a revision. https://github.com/llvm/llvm-project/pull/149564 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] ELF: Add --preferred-function-alignment option. (PR #149448)
https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149448 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] ELF: Add --preferred-function-alignment option. (PR #149448)
https://github.com/pcc edited https://github.com/llvm/llvm-project/pull/149448 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [lld] ELF: CFI jump table relaxation. (PR #147424)
https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/147424 >From 5bce06b0d8db161a2e09709bcfe15b4623e43d01 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Mon, 7 Jul 2025 16:41:10 -0700 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.6-beta.1 --- lld/ELF/Arch/X86_64.cpp | 95 + lld/ELF/Relocations.cpp | 2 +- lld/ELF/Target.h| 1 + 3 files changed, 97 insertions(+), 1 deletion(-) diff --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp index 488f4803b2cb4..04ca79befdc4a 100644 --- a/lld/ELF/Arch/X86_64.cpp +++ b/lld/ELF/Arch/X86_64.cpp @@ -318,6 +318,9 @@ bool X86_64::deleteFallThruJmpInsn(InputSection &is, InputFile *file, } bool X86_64::relaxOnce(int pass) const { + if (pass == 0) +relaxJumpTables(ctx); + uint64_t minVA = UINT64_MAX, maxVA = 0; for (OutputSection *osec : ctx.outputSections) { if (!(osec->flags & SHF_ALLOC)) @@ -1231,6 +1234,98 @@ void X86_64::applyBranchToBranchOpt() const { redirectControlTransferRelocations); } +void elf::relaxJumpTables(Ctx &ctx) { + // Relax CFI jump tables. + // - Split jump table into pieces and place target functions inside the jump + // table if small enough. + // - Move jump table before last called function and delete last branch + // instruction. + std::map> sectionReplacements; + SmallVector storage; + for (OutputSection *osec : ctx.outputSections) { +if (!(osec->flags & SHF_EXECINSTR)) + continue; +for (InputSection *sec : getInputSections(*osec, storage)) { + if (!sec->name.starts_with(".text..L.cfi.jumptable")) +continue; + std::vector replacements; + replacements.push_back(sec); + auto addSectionSlice = [&](size_t begin, size_t end, Relocation *rbegin, + Relocation *rend) { +if (begin == end) + return; +auto *slice = make( +sec->file, sec->name, sec->type, sec->flags, 1, sec->entsize, +sec->contentMaybeDecompress().slice(begin, end - begin)); +for (const Relocation &r : ArrayRef(rbegin, rend)) { + slice->relocations.push_back( + Relocation{r.expr, r.type, r.offset - begin, r.addend, r.sym}); +} +replacements.push_back(slice); + }; + auto getMovableSection = [&](Relocation &r) -> InputSection * { +auto *sym = dyn_cast_or_null(r.sym); +if (!sym || sym->isPreemptible || sym->isGnuIFunc() || sym->value != 0) + return nullptr; +auto *sec = dyn_cast_or_null(sym->section); +if (!sec || sectionReplacements.count(sec)) + return nullptr; +return sec; + }; + size_t begin = 0; + Relocation *rbegin = sec->relocs().begin(); + for (auto &r : sec->relocs().slice(0, sec->relocs().size() - 1)) { +auto entrySize = (&r + 1)->offset - r.offset; +InputSection *target = getMovableSection(r); +if (!target || target->size > entrySize) + continue; +target->addralign = 1; +addSectionSlice(begin, r.offset - 1, rbegin, &r); +replacements.push_back(target); +sectionReplacements[target] = {}; +begin = r.offset - 1 + target->size; +rbegin = &r + 1; + } + InputSection *lastSec = getMovableSection(sec->relocs().back()); + if (lastSec) { +lastSec->addralign = 1; +addSectionSlice(begin, sec->relocs().back().offset - 1, rbegin, +&sec->relocs().back()); +replacements.push_back(lastSec); +sectionReplacements[sec] = {}; +sectionReplacements[lastSec] = replacements; +for (auto *s : replacements) + s->parent = lastSec->parent; + } else { +addSectionSlice(begin, sec->size, rbegin, sec->relocs().end()); +sectionReplacements[sec] = replacements; +for (auto *s : replacements) + s->parent = sec->parent; + } + sec->relocations.clear(); + sec->size = 0; +} + } + for (OutputSection *osec : ctx.outputSections) { +if (!(osec->flags & SHF_EXECINSTR)) + continue; +for (SectionCommand *cmd : osec->commands) { + auto *isd = dyn_cast(cmd); + if (!isd) +continue; + SmallVector newSections; + for (auto *sec : isd->sections) { +auto i = sectionReplacements.find(sec); +if (i == sectionReplacements.end()) + newSections.push_back(sec); +else + newSections.append(i->second.begin(), i->second.end()); + } + isd->sections = std::move(newSections); +} + } +} + // If Intel Indirect Branch Tracking is enabled, we have to emit special PLT // entries containing endbr64 instructions. A PLT entry will be split into two // parts,
[llvm-branch-commits] [lld] ELF: CFI jump table relaxation. (PR #147424)
https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/147424 >From 5bce06b0d8db161a2e09709bcfe15b4623e43d01 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Mon, 7 Jul 2025 16:41:10 -0700 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.6-beta.1 --- lld/ELF/Arch/X86_64.cpp | 95 + lld/ELF/Relocations.cpp | 2 +- lld/ELF/Target.h| 1 + 3 files changed, 97 insertions(+), 1 deletion(-) diff --git a/lld/ELF/Arch/X86_64.cpp b/lld/ELF/Arch/X86_64.cpp index 488f4803b2cb4..04ca79befdc4a 100644 --- a/lld/ELF/Arch/X86_64.cpp +++ b/lld/ELF/Arch/X86_64.cpp @@ -318,6 +318,9 @@ bool X86_64::deleteFallThruJmpInsn(InputSection &is, InputFile *file, } bool X86_64::relaxOnce(int pass) const { + if (pass == 0) +relaxJumpTables(ctx); + uint64_t minVA = UINT64_MAX, maxVA = 0; for (OutputSection *osec : ctx.outputSections) { if (!(osec->flags & SHF_ALLOC)) @@ -1231,6 +1234,98 @@ void X86_64::applyBranchToBranchOpt() const { redirectControlTransferRelocations); } +void elf::relaxJumpTables(Ctx &ctx) { + // Relax CFI jump tables. + // - Split jump table into pieces and place target functions inside the jump + // table if small enough. + // - Move jump table before last called function and delete last branch + // instruction. + std::map> sectionReplacements; + SmallVector storage; + for (OutputSection *osec : ctx.outputSections) { +if (!(osec->flags & SHF_EXECINSTR)) + continue; +for (InputSection *sec : getInputSections(*osec, storage)) { + if (!sec->name.starts_with(".text..L.cfi.jumptable")) +continue; + std::vector replacements; + replacements.push_back(sec); + auto addSectionSlice = [&](size_t begin, size_t end, Relocation *rbegin, + Relocation *rend) { +if (begin == end) + return; +auto *slice = make( +sec->file, sec->name, sec->type, sec->flags, 1, sec->entsize, +sec->contentMaybeDecompress().slice(begin, end - begin)); +for (const Relocation &r : ArrayRef(rbegin, rend)) { + slice->relocations.push_back( + Relocation{r.expr, r.type, r.offset - begin, r.addend, r.sym}); +} +replacements.push_back(slice); + }; + auto getMovableSection = [&](Relocation &r) -> InputSection * { +auto *sym = dyn_cast_or_null(r.sym); +if (!sym || sym->isPreemptible || sym->isGnuIFunc() || sym->value != 0) + return nullptr; +auto *sec = dyn_cast_or_null(sym->section); +if (!sec || sectionReplacements.count(sec)) + return nullptr; +return sec; + }; + size_t begin = 0; + Relocation *rbegin = sec->relocs().begin(); + for (auto &r : sec->relocs().slice(0, sec->relocs().size() - 1)) { +auto entrySize = (&r + 1)->offset - r.offset; +InputSection *target = getMovableSection(r); +if (!target || target->size > entrySize) + continue; +target->addralign = 1; +addSectionSlice(begin, r.offset - 1, rbegin, &r); +replacements.push_back(target); +sectionReplacements[target] = {}; +begin = r.offset - 1 + target->size; +rbegin = &r + 1; + } + InputSection *lastSec = getMovableSection(sec->relocs().back()); + if (lastSec) { +lastSec->addralign = 1; +addSectionSlice(begin, sec->relocs().back().offset - 1, rbegin, +&sec->relocs().back()); +replacements.push_back(lastSec); +sectionReplacements[sec] = {}; +sectionReplacements[lastSec] = replacements; +for (auto *s : replacements) + s->parent = lastSec->parent; + } else { +addSectionSlice(begin, sec->size, rbegin, sec->relocs().end()); +sectionReplacements[sec] = replacements; +for (auto *s : replacements) + s->parent = sec->parent; + } + sec->relocations.clear(); + sec->size = 0; +} + } + for (OutputSection *osec : ctx.outputSections) { +if (!(osec->flags & SHF_EXECINSTR)) + continue; +for (SectionCommand *cmd : osec->commands) { + auto *isd = dyn_cast(cmd); + if (!isd) +continue; + SmallVector newSections; + for (auto *sec : isd->sections) { +auto i = sectionReplacements.find(sec); +if (i == sectionReplacements.end()) + newSections.push_back(sec); +else + newSections.append(i->second.begin(), i->second.end()); + } + isd->sections = std::move(newSections); +} + } +} + // If Intel Indirect Branch Tracking is enabled, we have to emit special PLT // entries containing endbr64 instructions. A PLT entry will be split into two // parts,
[llvm-branch-commits] IR: Introduce !elf_section_properties for setting section properties. (PR #149260)
https://github.com/pcc updated https://github.com/llvm/llvm-project/pull/149260 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-doc] enable comments in class templates (PR #149565)
@@ -60,6 +60,17 @@ HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: HTML-SHAPE: class Shape +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Abstract base class for shapes. +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: +HTML-SHAPE: Provides a common interface for different types of shapes. +HTML-SHAPE: +HTML-SHAPE: ilovepi wrote: Can you file a bug about this and CC me? you can tag it w/ clang-doc for now, even though its an issue w/ mustache lib. I can try to fix that maybe next week. https://github.com/llvm/llvm-project/pull/149565 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits