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 <ne...@google.com> Date: Tue, 19 Nov 2024 15:25:34 -0800 Subject: [PATCH 1/5] 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<OperandBundleUse> 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 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 arm-linux-gnu %s -stop-before=finalize-isel -o - | FileCheck %s - -; ModuleID = 'test.c' -source_filename = "test.c" -target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" -target triple = "armv4t-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 arm-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/MIR/X86/call-site-info-typeid.ll b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.ll index b769a721cac06..a8b2de8d8f8cf 100644 --- a/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.ll @@ -1,16 +1,16 @@ -; Test MIR printer and parser for type id field in call site info. Test that -; it works well with/without --emit-call-site-info. +;; Test MIR printer and parser for type id field in call site info. Test that +;; it works well with/without --emit-call-site-info. -; Multiplex --call-graph-section and -emit-call-site-info as both utilize -; CallSiteInfo and callSites. +;; Multiplex --call-graph-section and -emit-call-site-info as both utilize +;; CallSiteInfo and callSites. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Test printer and parser with --call-graph-section only. -; Test printer. -; Verify that fwdArgRegs is not set, typeId is set. -; Verify the exact typeId value to ensure it is not garbage but the value -; computed as the type id from the type operand bundle. +;; Test printer. +;; Verify that fwdArgRegs is not set, typeId is set. +;; 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 %s -stop-before=finalize-isel -o %t1.mir ; RUN: cat %t1.mir | FileCheck %s --check-prefix=PRINTER_CGS ; PRINTER_CGS: name: main @@ -19,8 +19,8 @@ ; PRINTER_CGS-NEXT: 7854600665770582568 } -; Test parser. -; Verify that we get the same result. +;; Test parser. +;; Verify that we get the same result. ; RUN: llc --call-graph-section %t1.mir -run-pass=finalize-isel -o - \ ; RUN: | FileCheck %s --check-prefix=PARSER_CGS ; PARSER_CGS: name: main @@ -31,8 +31,8 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Test printer and parser with -emit-call-site-info only. -; Test printer. -; Verify that fwdArgRegs is set, typeId is not set. +;; Test printer. +;; Verify that fwdArgRegs is set, typeId is not set. ; RUN: llc -emit-call-site-info %s -stop-before=finalize-isel -o %t2.mir ; RUN: cat %t2.mir | FileCheck %s --check-prefix=PRINTER_CSI ; PRINTER_CSI: name: main @@ -42,8 +42,8 @@ ; PRINTER_CSI-NOT: typeId: -; Test parser. -; Verify that we get the same result. +;; Test parser. +;; Verify that we get the same result. ; RUN: llc -emit-call-site-info %t2.mir -run-pass=finalize-isel -o - \ ; RUN: | FileCheck %s --check-prefix=PARSER_CSI ; PARSER_CSI: name: main @@ -55,10 +55,10 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Test printer and parser with both -emit-call-site-info and --call-graph-section. -; Test printer. -; Verify both fwdArgRegs and typeId are set. -; Verify the exact typeId value to ensure it is not garbage but the value -; computed as the type id from the type operand bundle. +;; Test printer. +;; Verify both fwdArgRegs and typeId are set. +;; 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 -emit-call-site-info %s -stop-before=finalize-isel -o %t2.mir ; RUN: cat %t2.mir | FileCheck %s --check-prefix=PRINTER_CGS_CSI ; PRINTER_CGS_CSI: name: main @@ -68,8 +68,8 @@ ; PRINTER_CGS_CSI-NEXT: 7854600665770582568 } -; Test parser. -; Verify that we get the same result. +;; Test parser. +;; Verify that we get the same result. ; RUN: llc --call-graph-section -emit-call-site-info %t2.mir -run-pass=finalize-isel -o - \ ; RUN: | FileCheck %s --check-prefix=PARSER_CGS_CSI ; PARSER_CGS_CSI: name: main @@ -80,11 +80,6 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; ModuleID = 'test.c' -source_filename = "test.c" -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" - ; Function Attrs: noinline nounwind optnone uwtable define dso_local void @foo(i8 signext %a) !type !3 { entry: @@ -95,18 +90,13 @@ 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 call void %0(i8 signext 97) [ "type"(metadata !"_ZTSFvcE.generalized") ] 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/MIR/X86/call-site-info-typeid.mir b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.mir index 5ab797bfcc18f..dd21246e5dedc 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 } diff --git a/llvm/test/CodeGen/Mips/call-site-info-typeid.ll b/llvm/test/CodeGen/Mips/call-site-info-typeid.ll index 8596ebb5aa094..91de6a83524e5 100644 --- a/llvm/test/CodeGen/Mips/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/Mips/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=mips-linux-gnu %s -stop-before=finalize-isel -o - | FileCheck %s - -; ModuleID = 'test.c' -source_filename = "test.c" -target datalayout = "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64" -target triple = "mips-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=mips-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/X86/call-site-info-typeid.ll b/llvm/test/CodeGen/X86/call-site-info-typeid.ll index 61777b770155d..6fbdce4f3c206 100644 --- a/llvm/test/CodeGen/X86/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/X86/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=x86_64-unknown-linux %s -stop-before=finalize-isel -o - | FileCheck %s - -; ModuleID = 'test.c' -source_filename = "test.c" -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" +;; 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=x86_64-unknown-linux < %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"} >From 80f879e029ebf571699e75e38d50bd46eb30f3b3 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran <ne...@google.com> Date: Tue, 11 Feb 2025 22:34:05 +0000 Subject: [PATCH 2/5] Update IR verifier. Created using spr 1.3.6-beta.1 --- llvm/lib/IR/Verifier.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 34c751e6357c6..e01a59908ad80 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -3794,6 +3794,11 @@ void Verifier::visitCallBase(CallBase &Call) { } else if (Tag == LLVMContext::OB_callee_type) { Check(!FoundCalleeTypeBundle, "Multiple \"callee_type\" operand bundles", Call); + auto *OBVal = BU.Inputs.front().get(); + auto *TypeIdMD = cast<MetadataAsValue>(OBVal)->getMetadata(); + auto *TypeIdStr = cast<MDString>(TypeIdMD); + Check(TypeIdStr->getString().ends_with(".generalized"), + "Invalid \"callee_type\" type identifier", Call); FoundCalleeTypeBundle = true; } } >From 5e97695febf5a8c00e680084ff5e1925f358de70 Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran <ne...@google.com> Date: Thu, 13 Mar 2025 17:34:26 +0000 Subject: [PATCH 3/5] Remove unnecessary asserts. Remove autos for better readability. Created using spr 1.3.6-beta.1 --- llvm/include/llvm/CodeGen/MachineFunction.h | 15 ++++++--------- llvm/lib/IR/Verifier.cpp | 7 ++++--- llvm/lib/Target/AArch64/AArch64ISelLowering.cpp | 2 +- llvm/lib/Target/ARM/ARMISelLowering.cpp | 2 +- llvm/lib/Target/Mips/MipsISelLowering.cpp | 2 +- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineFunction.h b/llvm/include/llvm/CodeGen/MachineFunction.h index cdbdd12ef54fc..ef8586dda1040 100644 --- a/llvm/include/llvm/CodeGen/MachineFunction.h +++ b/llvm/include/llvm/CodeGen/MachineFunction.h @@ -513,20 +513,17 @@ class LLVM_ABI MachineFunction { if (!CB.isIndirectCall()) return; - std::optional<OperandBundleUse> Opt = + std::optional<OperandBundleUse> CalleeTypeOB = CB.getOperandBundle(LLVMContext::OB_callee_type); // Return if the operand bundle for call graph section cannot be found. - if (!Opt) + if (!CalleeTypeOB) return; // Get generalized type id string - auto OB = *Opt; - assert(OB.Inputs.size() == 1 && "invalid input size"); - auto *OBVal = OB.Inputs.front().get(); - auto *TypeIdMD = cast<MetadataAsValue>(OBVal)->getMetadata(); - auto *TypeIdStr = cast<MDString>(TypeIdMD); - assert(TypeIdStr->getString().ends_with(".generalized") && - "invalid type identifier"); + Value *CalleeTypeOBVal = CalleeTypeOB->Inputs.front().get(); + Metadata *TypeIdMD = + cast<MetadataAsValue>(CalleeTypeOBVal)->getMetadata(); + MDString *TypeIdStr = cast<MDString>(TypeIdMD); // Compute numeric type id from generalized type id string uint64_t TypeIdVal = MD5Hash(TypeIdStr->getString()); diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index e01a59908ad80..b0a34488909f8 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -3794,9 +3794,10 @@ void Verifier::visitCallBase(CallBase &Call) { } else if (Tag == LLVMContext::OB_callee_type) { Check(!FoundCalleeTypeBundle, "Multiple \"callee_type\" operand bundles", Call); - auto *OBVal = BU.Inputs.front().get(); - auto *TypeIdMD = cast<MetadataAsValue>(OBVal)->getMetadata(); - auto *TypeIdStr = cast<MDString>(TypeIdMD); + Value *CalleeTypeOBVal = BU.Inputs.front().get(); + Metadata *TypeIdMD = + cast<MetadataAsValue>(CalleeTypeOBVal)->getMetadata(); + MDString *TypeIdStr = cast<MDString>(TypeIdMD); Check(TypeIdStr->getString().ends_with(".generalized"), "Invalid \"callee_type\" type identifier", Call); FoundCalleeTypeBundle = true; diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp index 82b3543583f9b..6d6b279f41948 100644 --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -8915,7 +8915,7 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI, bool &IsTailCall = CLI.IsTailCall; CallingConv::ID &CallConv = CLI.CallConv; bool IsVarArg = CLI.IsVarArg; - const auto *CB = CLI.CB; + const CallBase *CB = CLI.CB; MachineFunction &MF = DAG.getMachineFunction(); MachineFunction::CallSiteInfo CSInfo; diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp index d00d4443dfbfc..95853d9503b8b 100644 --- a/llvm/lib/Target/ARM/ARMISelLowering.cpp +++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp @@ -2439,7 +2439,7 @@ ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, CallingConv::ID CallConv = CLI.CallConv; bool doesNotRet = CLI.DoesNotReturn; bool isVarArg = CLI.IsVarArg; - const auto *CB = CLI.CB; + const CallBase *CB = CLI.CB; MachineFunction &MF = DAG.getMachineFunction(); ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp b/llvm/lib/Target/Mips/MipsISelLowering.cpp index ef9e4040d5717..2279870ebf955 100644 --- a/llvm/lib/Target/Mips/MipsISelLowering.cpp +++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp @@ -3264,7 +3264,7 @@ MipsTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, bool &IsTailCall = CLI.IsTailCall; CallingConv::ID CallConv = CLI.CallConv; bool IsVarArg = CLI.IsVarArg; - const auto *CB = CLI.CB; + const CallBase *CB = CLI.CB; MachineFunction &MF = DAG.getMachineFunction(); MachineFrameInfo &MFI = MF.getFrameInfo(); >From 1429f1dd47fe69300a99530c0e8ba1fa7c0478da Mon Sep 17 00:00:00 2001 From: Necip Fazil Yildiran <ne...@google.com> Date: Fri, 14 Mar 2025 04:10:20 +0000 Subject: [PATCH 4/5] Add RISC-V support. Clean up test files. Created using spr 1.3.6-beta.1 --- llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 13 ++++++++ .../CodeGen/AArch64/call-site-info-typeid.ll | 12 ++++---- .../test/CodeGen/ARM/call-site-info-typeid.ll | 12 ++++---- .../CodeGen/Mips/call-site-info-typeid.ll | 12 ++++---- .../CodeGen/RISCV/call-site-info-typeid.ll | 30 +++++++++++++++++++ .../test/CodeGen/X86/call-site-info-typeid.ll | 12 ++++---- 6 files changed, 67 insertions(+), 24 deletions(-) create mode 100644 llvm/test/CodeGen/RISCV/call-site-info-typeid.ll diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index ff44ff5249973..e21b2e615b223 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -20845,8 +20845,14 @@ SDValue RISCVTargetLowering::LowerCall(CallLoweringInfo &CLI, bool IsVarArg = CLI.IsVarArg; EVT PtrVT = getPointerTy(DAG.getDataLayout()); MVT XLenVT = Subtarget.getXLenVT(); + const CallBase *CB = CLI.CB; MachineFunction &MF = DAG.getMachineFunction(); + MachineFunction::CallSiteInfo CSInfo; + + // Set type id for call site info. + if (MF.getTarget().Options.EmitCallGraphSection && CB && CB->isIndirectCall()) + CSInfo = MachineFunction::CallSiteInfo(*CB); // Analyze the operands of the call, assigning locations to each operand. SmallVector<CCValAssign, 16> ArgLocs; @@ -21104,6 +21110,9 @@ SDValue RISCVTargetLowering::LowerCall(CallLoweringInfo &CLI, if (CLI.CFIType) Ret.getNode()->setCFIType(CLI.CFIType->getZExtValue()); DAG.addNoMergeSiteInfo(Ret.getNode(), CLI.NoMerge); + if (MF.getTarget().Options.EmitCallGraphSection && CB && + CB->isIndirectCall()) + DAG.addCallSiteInfo(Ret.getNode(), std::move(CSInfo)); return Ret; } @@ -21111,6 +21120,10 @@ SDValue RISCVTargetLowering::LowerCall(CallLoweringInfo &CLI, Chain = DAG.getNode(CallOpc, DL, NodeTys, Ops); if (CLI.CFIType) Chain.getNode()->setCFIType(CLI.CFIType->getZExtValue()); + + if (MF.getTarget().Options.EmitCallGraphSection && CB && CB->isIndirectCall()) + DAG.addCallSiteInfo(Chain.getNode(), std::move(CSInfo)); + DAG.addNoMergeSiteInfo(Chain.getNode(), CLI.NoMerge); Glue = Chain.getValue(1); diff --git a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll index b0d4855c72997..1bad6c25dc39a 100644 --- a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll @@ -5,25 +5,25 @@ ;; 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 { +define dso_local void @foo(i8 signext %a) !type !0 { entry: ret void } ; CHECK: name: main -define dso_local i32 @main() !type !4 { +define dso_local i32 @main() !type !1 { entry: %retval = alloca i32, align 4 %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 + %fp_val = load ptr, ptr %fp, align 8 ; CHECK: callSites: ; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: ; CHECK-NEXT: 7854600665770582568 } - call void %0(i8 signext 97) [ "callee_type"(metadata !"_ZTSFvcE.generalized") ] + call void %fp_val(i8 signext 97) [ "callee_type"(metadata !"_ZTSFvcE.generalized") ] ret i32 0 } -!3 = !{i64 0, !"_ZTSFvcE.generalized"} -!4 = !{i64 0, !"_ZTSFiE.generalized"} +!0 = !{i64 0, !"_ZTSFvcE.generalized"} +!1 = !{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 7eb5c3e434fd5..4af6f25c7622a 100644 --- a/llvm/test/CodeGen/ARM/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/ARM/call-site-info-typeid.ll @@ -5,25 +5,25 @@ ;; computed as the type id from the type operand bundle. ; RUN: llc --call-graph-section -mtriple arm-linux-gnu < %s -stop-before=finalize-isel -o - | FileCheck %s -define dso_local void @foo(i8 signext %a) !type !3 { +define dso_local void @foo(i8 signext %a) !type !0 { entry: ret void } ; CHECK: name: main -define dso_local i32 @main() !type !4 { +define dso_local i32 @main() !type !1 { entry: %retval = alloca i32, align 4 %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 + %fp_val = load ptr, ptr %fp, align 8 ; CHECK: callSites: ; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: ; CHECK-NEXT: 7854600665770582568 } - call void %0(i8 signext 97) [ "callee_type"(metadata !"_ZTSFvcE.generalized") ] + call void %fp_val(i8 signext 97) [ "callee_type"(metadata !"_ZTSFvcE.generalized") ] ret i32 0 } -!3 = !{i64 0, !"_ZTSFvcE.generalized"} -!4 = !{i64 0, !"_ZTSFiE.generalized"} +!0 = !{i64 0, !"_ZTSFvcE.generalized"} +!1 = !{i64 0, !"_ZTSFiE.generalized"} diff --git a/llvm/test/CodeGen/Mips/call-site-info-typeid.ll b/llvm/test/CodeGen/Mips/call-site-info-typeid.ll index 74faa774d78de..05b7fb022eb34 100644 --- a/llvm/test/CodeGen/Mips/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/Mips/call-site-info-typeid.ll @@ -5,25 +5,25 @@ ;; computed as the type id from the type operand bundle. ; RUN: llc --call-graph-section -mtriple=mips-linux-gnu < %s -stop-before=finalize-isel -o - | FileCheck %s -define dso_local void @foo(i8 signext %a) !type !3 { +define dso_local void @foo(i8 signext %a) !type !0 { entry: ret void } ; CHECK: name: main -define dso_local i32 @main() !type !4 { +define dso_local i32 @main() !type !1 { entry: %retval = alloca i32, align 4 %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 + %fp_val = load ptr, ptr %fp, align 8 ; CHECK: callSites: ; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: ; CHECK-NEXT: 7854600665770582568 } - call void %0(i8 signext 97) [ "callee_type"(metadata !"_ZTSFvcE.generalized") ] + call void %fp_val(i8 signext 97) [ "callee_type"(metadata !"_ZTSFvcE.generalized") ] ret i32 0 } -!3 = !{i64 0, !"_ZTSFvcE.generalized"} -!4 = !{i64 0, !"_ZTSFiE.generalized"} +!0 = !{i64 0, !"_ZTSFvcE.generalized"} +!1 = !{i64 0, !"_ZTSFiE.generalized"} diff --git a/llvm/test/CodeGen/RISCV/call-site-info-typeid.ll b/llvm/test/CodeGen/RISCV/call-site-info-typeid.ll new file mode 100644 index 0000000000000..e0dac6b40a41f --- /dev/null +++ b/llvm/test/CodeGen/RISCV/call-site-info-typeid.ll @@ -0,0 +1,30 @@ +;; 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 riscv64 < %s -stop-before=finalize-isel -o - | FileCheck %s +; RUN: llc --call-graph-section -mtriple riscv32 < %s -stop-before=finalize-isel -o - | FileCheck %s + +define dso_local void @foo(i8 signext %a) !type !0 { +entry: + ret void +} + +; CHECK: name: main +define dso_local i32 @main() !type !1 { +entry: + %retval = alloca i32, align 4 + %fp = alloca ptr, align 8 + store i32 0, ptr %retval, align 4 + store ptr @foo, ptr %fp, align 8 + %fp_val = load ptr, ptr %fp, align 8 + ; CHECK: callSites: + ; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: + ; CHECK-NEXT: 7854600665770582568 } + call void %fp_val(i8 signext 97) [ "callee_type"(metadata !"_ZTSFvcE.generalized") ] + ret i32 0 +} + +!0 = !{i64 0, !"_ZTSFvcE.generalized"} +!1 = !{i64 0, !"_ZTSFiE.generalized"} diff --git a/llvm/test/CodeGen/X86/call-site-info-typeid.ll b/llvm/test/CodeGen/X86/call-site-info-typeid.ll index 0463bf8627853..57d4bc78275d3 100644 --- a/llvm/test/CodeGen/X86/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/X86/call-site-info-typeid.ll @@ -5,25 +5,25 @@ ;; computed as the type id from the type operand bundle. ; RUN: llc --call-graph-section -mtriple=x86_64-unknown-linux < %s -stop-before=finalize-isel -o - | FileCheck %s -define dso_local void @foo(i8 signext %a) !type !3 { +define dso_local void @foo(i8 signext %a) !type !0 { entry: ret void } ; CHECK: name: main -define dso_local i32 @main() !type !4 { +define dso_local i32 @main() !type !1 { entry: %retval = alloca i32, align 4 %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 + %fp_val = load ptr, ptr %fp, align 8 ; CHECK: callSites: ; CHECK-NEXT: - { bb: {{.*}}, offset: {{.*}}, fwdArgRegs: [], typeId: ; CHECK-NEXT: 7854600665770582568 } - call void %0(i8 signext 97) [ "callee_type"(metadata !"_ZTSFvcE.generalized") ] + call void %fp_val(i8 signext 97) [ "callee_type"(metadata !"_ZTSFvcE.generalized") ] ret i32 0 } -!3 = !{i64 0, !"_ZTSFvcE.generalized"} -!4 = !{i64 0, !"_ZTSFiE.generalized"} +!0 = !{i64 0, !"_ZTSFvcE.generalized"} +!1 = !{i64 0, !"_ZTSFiE.generalized"} >From 3eee130e6367b8eaa8a9c5098b56ad0cdd9e307f Mon Sep 17 00:00:00 2001 From: prabhukr <prabh...@google.com> Date: Sat, 19 Apr 2025 03:07:19 +0000 Subject: [PATCH 5/5] Address review comments. Created using spr 1.3.6-beta.1 --- .../CodeGen/AArch64/call-site-info-typeid.ll | 2 +- llvm/test/CodeGen/ARM/call-site-info-typeid.ll | 2 +- .../CodeGen/MIR/X86/call-site-info-typeid.ll | 16 ++++++++-------- llvm/test/CodeGen/Mips/call-site-info-typeid.ll | 2 +- llvm/test/CodeGen/RISCV/call-site-info-typeid.ll | 6 +++--- llvm/test/CodeGen/X86/call-site-info-typeid.ll | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll index e72ba58328f51..48cf7268d5215 100644 --- a/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/AArch64/call-site-info-typeid.ll @@ -3,7 +3,7 @@ ;; Verify the exact calleeTypeId value to ensure it is not garbage but the value ;; computed as the type id from the callee_type metadata. -; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu < %s -stop-before=finalize-isel -o - | FileCheck %s +; RUN: llc --call-graph-section -mtriple aarch64-linux-gnu < %s -stop-after=finalize-isel -o - | FileCheck %s declare !type !0 void @foo(i8 signext %a) diff --git a/llvm/test/CodeGen/ARM/call-site-info-typeid.ll b/llvm/test/CodeGen/ARM/call-site-info-typeid.ll index aebcf918eb1bc..0aadcdb46a4a4 100644 --- a/llvm/test/CodeGen/ARM/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/ARM/call-site-info-typeid.ll @@ -3,7 +3,7 @@ ;; Verify the exact calleeTypeId value to ensure it is not garbage but the value ;; computed as the type id from the callee_type metadata. -; RUN: llc --call-graph-section -mtriple arm-linux-gnu < %s -stop-before=finalize-isel -o - | FileCheck %s +; RUN: llc --call-graph-section -mtriple arm-linux-gnu < %s -stop-after=finalize-isel -o - | FileCheck %s declare !type !0 void @foo(i8 signext %a) diff --git a/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.ll b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.ll index fed4fc81c88b0..4823d2212df1a 100644 --- a/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/MIR/X86/call-site-info-typeid.ll @@ -11,7 +11,7 @@ ;; Verify that fwdArgRegs is not set, calleeTypeIds is set. ;; Verify the exact calleeTypeIds value to ensure it is not garbage but the value ;; computed as the type id from the callee_type metadata. -; RUN: llc --call-graph-section %s -stop-before=finalize-isel -o %t1.mir +; RUN: llc --call-graph-section %s -stop-after=finalize-isel -o %t1.mir ; RUN: cat %t1.mir | FileCheck %s --check-prefix=PRINTER_CGS ; PRINTER_CGS: name: main ; PRINTER_CGS: callSites: @@ -32,8 +32,8 @@ ;; Test printer and parser with -emit-call-site-info only. ;; Test printer. -;; Verify that fwdArgRegs is set, calleeTypeId is not set. -; RUN: llc -emit-call-site-info %s -stop-before=finalize-isel -o %t2.mir +;; Verify that fwdArgRegs is set, calleeTypeIds is not set. +; RUN: llc -emit-call-site-info %s -stop-after=finalize-isel -o %t2.mir ; RUN: cat %t2.mir | FileCheck %s --check-prefix=PRINTER_CSI ; PRINTER_CSI: name: main ; PRINTER_CSI: callSites: @@ -56,10 +56,10 @@ ;; Test printer and parser with both -emit-call-site-info and --call-graph-section. ;; Test printer. -;; Verify both fwdArgRegs and calleeTypeId are set. -;; Verify the exact calleeTypeId value to ensure it is not garbage but the value +;; Verify both fwdArgRegs and calleeTypeIds are set. +;; Verify the exact calleeTypeIds value to ensure it is not garbage but the value ;; computed as the type id from the callee_type metadata. -; RUN: llc --call-graph-section -emit-call-site-info %s -stop-before=finalize-isel -o %t2.mir +; RUN: llc --call-graph-section -emit-call-site-info %s -stop-after=finalize-isel -o %t2.mir ; RUN: cat %t2.mir | FileCheck %s --check-prefix=PRINTER_CGS_CSI ; PRINTER_CGS_CSI: name: main ; PRINTER_CGS_CSI: callSites: @@ -93,8 +93,8 @@ entry: %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), !callee_type !5 + %fp_val = load ptr, ptr %fp, align 8 + call void %fp_val(i8 signext 97), !callee_type !5 ret i32 0 } diff --git a/llvm/test/CodeGen/Mips/call-site-info-typeid.ll b/llvm/test/CodeGen/Mips/call-site-info-typeid.ll index 826be8121d183..a6d1969136a85 100644 --- a/llvm/test/CodeGen/Mips/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/Mips/call-site-info-typeid.ll @@ -3,7 +3,7 @@ ;; Verify the exact calleeTypeId value to ensure it is not garbage but the value ;; computed as the type id from the callee_type metadata. -; RUN: llc --call-graph-section -mtriple=mips-linux-gnu < %s -stop-before=finalize-isel -o - | FileCheck %s +; RUN: llc --call-graph-section -mtriple=mips-linux-gnu < %s -stop-after=finalize-isel -o - | FileCheck %s declare !type !0 void @foo(i8 signext %a) diff --git a/llvm/test/CodeGen/RISCV/call-site-info-typeid.ll b/llvm/test/CodeGen/RISCV/call-site-info-typeid.ll index 10fdd15547ec0..46cc0eaebbcee 100644 --- a/llvm/test/CodeGen/RISCV/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/RISCV/call-site-info-typeid.ll @@ -1,10 +1,10 @@ ;; Tests that call site callee type ids can be extracted and set from ;; callee_type metadata. -;; Verify the exact calleeTypeId value to ensure it is not garbage but the value +;; Verify the exact calleeTypeIds value to ensure it is not garbage but the value ;; computed as the type id from the callee_type operand bundle. -; RUN: llc --call-graph-section -mtriple riscv64 < %s -stop-before=finalize-isel -o - | FileCheck %s -; RUN: llc --call-graph-section -mtriple riscv32 < %s -stop-before=finalize-isel -o - | FileCheck %s +; RUN: llc --call-graph-section -mtriple riscv64 < %s -stop-after=finalize-isel -o - | FileCheck %s +; RUN: llc --call-graph-section -mtriple riscv32 < %s -stop-after=finalize-isel -o - | FileCheck %s declare !type !0 void @foo(i8 signext %a) diff --git a/llvm/test/CodeGen/X86/call-site-info-typeid.ll b/llvm/test/CodeGen/X86/call-site-info-typeid.ll index c785cd636732a..6f0890de3ed37 100644 --- a/llvm/test/CodeGen/X86/call-site-info-typeid.ll +++ b/llvm/test/CodeGen/X86/call-site-info-typeid.ll @@ -1,9 +1,9 @@ ;; Tests that call site callee type ids can be extracted and set from ;; callee_type metadata. -;; Verify the exact calleeTypeId value to ensure it is not garbage but the value +;; Verify the exact calleeTypeIds value to ensure it is not garbage but the value ;; computed as the type id from the callee_type metadata. -; RUN: llc --call-graph-section -mtriple=x86_64-unknown-linux < %s -stop-before=finalize-isel -o - | FileCheck %s +; RUN: llc --call-graph-section -mtriple=x86_64-unknown-linux < %s -stop-after=finalize-isel -o - | FileCheck %s declare !type !0 void @foo(i8 signext %a) _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits