[llvm] 48e65fc - MachineFunction: Copy call site info when duplicating insts
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 8 11:06:51 PDT 2020
Author: Vedant Kumar
Date: 2020-04-08T11:06:14-07:00
New Revision: 48e65fc63076eec4fa527ab7b22fdcb4d8cdbb50
URL: https://github.com/llvm/llvm-project/commit/48e65fc63076eec4fa527ab7b22fdcb4d8cdbb50
DIFF: https://github.com/llvm/llvm-project/commit/48e65fc63076eec4fa527ab7b22fdcb4d8cdbb50.diff
LOG: MachineFunction: Copy call site info when duplicating insts
Summary:
Preserve call site info for duplicated instructions. We copy over the
call site info in CloneMachineInstrBundle to avoid repeated calls to
copyCallSiteInfo in CloneMachineInstr.
(Alternatively, we could copy call site info higher up the stack, e.g.
into TargetInstrInfo::duplicate, or even into individual backend passes.
However, I don't see how that would be safer or more general than the
current approach.)
Reviewers: aprantl, djtodoro, dstenb
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77685
Added:
llvm/test/CodeGen/X86/taildup-callsiteinfo.mir
Modified:
llvm/lib/CodeGen/MachineFunction.cpp
llvm/unittests/CodeGen/MFCommon.inc
llvm/unittests/CodeGen/MachineInstrTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp
index 271fc8c8edbf..1b89333b98f3 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -426,6 +426,11 @@ MachineInstr &MachineFunction::CloneMachineInstrBundle(MachineBasicBlock &MBB,
break;
++I;
}
+ // Copy over call site info to the cloned instruction if needed. If Orig is in
+ // a bundle, copyCallSiteInfo takes care of finding the call instruction in
+ // the bundle.
+ if (Orig.shouldUpdateCallSiteInfo())
+ copyCallSiteInfo(&Orig, FirstClone);
return *FirstClone;
}
diff --git a/llvm/test/CodeGen/X86/taildup-callsiteinfo.mir b/llvm/test/CodeGen/X86/taildup-callsiteinfo.mir
new file mode 100644
index 000000000000..9a1f23a9a498
--- /dev/null
+++ b/llvm/test/CodeGen/X86/taildup-callsiteinfo.mir
@@ -0,0 +1,75 @@
+# RUN: llc %s -emit-call-site-info -run-pass=block-placement -tail-dup-placement-threshold=4 -o - | FileCheck %s
+#
+# Test case adapted from test/CodeGen/X86/taildup-heapallocsite.ll.
+
+# CHECK-LABEL: callSites:
+# CHECK-NEXT: - { bb: 1, offset: 1, fwdArgRegs:
+# CHECK-NEXT: - { arg: 0, reg: '$rcx' } }
+# CHECK-NEXT: - { bb: 2, offset: 1, fwdArgRegs:
+# CHECK-NEXT: - { arg: 0, reg: '$rcx' } }
+
+--- |
+ target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+ target triple = "x86_64-pc-windows-msvc19.22.27905"
+
+ define dso_local void @taildupit(i32* readonly %size_ptr) {
+ entry:
+ %tobool = icmp eq i32* %size_ptr, null
+ br i1 %tobool, label %cond.end, label %cond.true
+
+ cond.true: ; preds = %entry
+ %0 = load i32, i32* %size_ptr, align 4
+ br label %cond.end
+
+ cond.end: ; preds = %cond.true, %entry
+ %cond = phi i32 [ %0, %cond.true ], [ 1, %entry ]
+ %call = tail call i8* @alloc(i32 %cond)
+ tail call void @f2()
+ ret void
+ }
+
+ declare dso_local i8* @alloc(i32)
+
+ declare dso_local void @f2()
+
+...
+---
+name: taildupit
+tracksRegLiveness: true
+liveins:
+ - { reg: '$rcx', virtual-reg: '' }
+callSites:
+ - { bb: 3, offset: 0, fwdArgRegs:
+ - { arg: 0, reg: '$rcx' } }
+body: |
+ bb.0.entry:
+ successors: %bb.1(0x30000000), %bb.2(0x50000000)
+ liveins: $rcx
+
+ $rsp = frame-setup SUB64ri8 $rsp, 40, implicit-def dead $eflags
+ frame-setup SEH_StackAlloc 40
+ frame-setup SEH_EndPrologue
+ TEST64rr renamable $rcx, renamable $rcx, implicit-def $eflags
+ JCC_1 %bb.2, 5, implicit killed $eflags
+
+ bb.1:
+ successors: %bb.3(0x80000000)
+
+ renamable $ecx = MOV32ri 1
+ JMP_1 %bb.3
+
+ bb.2.cond.true:
+ successors: %bb.3(0x80000000)
+ liveins: $rcx
+
+ renamable $ecx = MOV32rm killed renamable $rcx, 1, $noreg, 0, $noreg :: (load 4 from %ir.size_ptr)
+
+ bb.3.cond.end:
+ liveins: $ecx
+
+ CALL64pcrel32 @alloc, csr_win64, implicit $rsp, implicit $ssp, implicit $ecx, implicit-def $rsp, implicit-def $ssp, implicit-def dead $rax
+ SEH_Epilogue
+ $rsp = frame-destroy ADD64ri8 $rsp, 40, implicit-def dead $eflags
+ TAILJMPd64 @f2, csr_win64, implicit $rsp, implicit $ssp, implicit $rsp, implicit $ssp
+
+...
diff --git a/llvm/unittests/CodeGen/MFCommon.inc b/llvm/unittests/CodeGen/MFCommon.inc
index 7468ff28fa94..6a31312cd6df 100644
--- a/llvm/unittests/CodeGen/MFCommon.inc
+++ b/llvm/unittests/CodeGen/MFCommon.inc
@@ -92,11 +92,18 @@ private:
TargetInstrInfo TII;
};
+static TargetOptions getTargetOptionsForBogusMachine() {
+ TargetOptions Opts;
+ Opts.EmitCallSiteInfo = true;
+ return Opts;
+}
+
class BogusTargetMachine : public LLVMTargetMachine {
public:
BogusTargetMachine()
- : LLVMTargetMachine(Target(), "", Triple(""), "", "", TargetOptions(),
- Reloc::Static, CodeModel::Small, CodeGenOpt::Default),
+ : LLVMTargetMachine(Target(), "", Triple(""), "", "",
+ getTargetOptionsForBogusMachine(), Reloc::Static,
+ CodeModel::Small, CodeGenOpt::Default),
ST(*this) {}
~BogusTargetMachine() override {}
diff --git a/llvm/unittests/CodeGen/MachineInstrTest.cpp b/llvm/unittests/CodeGen/MachineInstrTest.cpp
index 33baaf62efdf..71c4b8e17f39 100644
--- a/llvm/unittests/CodeGen/MachineInstrTest.cpp
+++ b/llvm/unittests/CodeGen/MachineInstrTest.cpp
@@ -383,6 +383,26 @@ TEST(MachineInstrExtraInfo, RemoveExtraInfo) {
ASSERT_FALSE(MI->getHeapAllocMarker());
}
+TEST(MachineInstrClone, CopyCallSiteInfo) {
+ LLVMContext Ctx;
+ Module Mod("Module", Ctx);
+ auto MF = createMachineFunction(Ctx, Mod);
+ auto MBB = MF->CreateMachineBasicBlock();
+ auto MII = MBB->begin();
+
+ MCInstrDesc MCID = {0, 0, 0, 0, 0, (1ULL << MCID::Call),
+ 0, nullptr, nullptr, nullptr};
+
+ MachineFunction::CallSiteInfo CSInfo;
+ auto MI = MF->CreateMachineInstr(MCID, DebugLoc());
+ ASSERT_TRUE(MI->isCandidateForCallSiteEntry());
+ MBB->insert(MII, MI);
+ MF->addCallArgsForwardingRegs(MI, std::move(CSInfo));
+ EXPECT_EQ(MF->getCallSitesInfo().size(), 1u);
+ MF->CloneMachineInstrBundle(*MBB, MBB->end(), *MI);
+ EXPECT_EQ(MF->getCallSitesInfo().size(), 2u);
+}
+
static_assert(is_trivially_copyable<MCOperand>::value, "trivially copyable");
} // end namespace
More information about the llvm-commits
mailing list