[llvm] [RISCV] Defer creating RISCVInsertVSETVLI to avoid leak with -stop-after (PR #92303)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Wed May 15 12:04:55 PDT 2024
https://github.com/lukel97 created https://github.com/llvm/llvm-project/pull/92303
As noted in https://github.com/llvm/llvm-project/pull/91440#discussion_r1601976425, if the pass pipeline stops early because of -stop-after any allocated passes added with insertPass will not be freed if they haven't already been added.
This was showing up as a failure on the address sanitizer buildbots. We can fix it by instead passing the pass ID instead so that allocation is deferred.
>From 1707137193f085431eb7784ce9eddbfca6eaf871 Mon Sep 17 00:00:00 2001
From: Luke Lau <luke at igalia.com>
Date: Thu, 16 May 2024 03:00:45 +0800
Subject: [PATCH] [RISCV] Defer creating RISCVInsertVSETVLI to avoid leak with
-stop-after
As noted in https://github.com/llvm/llvm-project/pull/91440#discussion_r1601976425, if the pass pipeline stops early because of -stop-after any allocated passes added with insertPass will not be freed if they haven't already been added.
This was showing up as a failure on the address sanitizer buildbots. We can fix it by instead passing the pass ID instead so that allocation is deferred.
---
llvm/lib/Target/RISCV/RISCV.h | 1 +
llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp | 1 +
llvm/lib/Target/RISCV/RISCVTargetMachine.cpp | 4 ++--
3 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCV.h b/llvm/lib/Target/RISCV/RISCV.h
index d405395dcf9ec..2b8688c5de61f 100644
--- a/llvm/lib/Target/RISCV/RISCV.h
+++ b/llvm/lib/Target/RISCV/RISCV.h
@@ -60,6 +60,7 @@ void initializeRISCVExpandAtomicPseudoPass(PassRegistry &);
FunctionPass *createRISCVInsertVSETVLIPass();
void initializeRISCVInsertVSETVLIPass(PassRegistry &);
+extern char &RISCVInsertVSETVLIID;
FunctionPass *createRISCVCoalesceVSETVLIPass();
void initializeRISCVCoalesceVSETVLIPass(PassRegistry &);
diff --git a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
index 363007d7b68b1..324ce5cb5ed7d 100644
--- a/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp
@@ -868,6 +868,7 @@ class RISCVCoalesceVSETVLI : public MachineFunctionPass {
} // end anonymous namespace
char RISCVInsertVSETVLI::ID = 0;
+char &llvm::RISCVInsertVSETVLIID = RISCVInsertVSETVLI::ID;
INITIALIZE_PASS(RISCVInsertVSETVLI, DEBUG_TYPE, RISCV_INSERT_VSETVLI_NAME,
false, false)
diff --git a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
index 5d598a275a008..5aab138dae408 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
@@ -548,9 +548,9 @@ void RISCVPassConfig::addPreRegAlloc() {
// Run RISCVInsertVSETVLI after PHI elimination. On O1 and above do it after
// register coalescing so needVSETVLIPHI doesn't need to look through COPYs.
if (TM->getOptLevel() == CodeGenOptLevel::None)
- insertPass(&PHIEliminationID, createRISCVInsertVSETVLIPass());
+ insertPass(&PHIEliminationID, &RISCVInsertVSETVLIID);
else
- insertPass(&RegisterCoalescerID, createRISCVInsertVSETVLIPass());
+ insertPass(&RegisterCoalescerID, &RISCVInsertVSETVLIID);
}
void RISCVPassConfig::addFastRegAlloc() {
More information about the llvm-commits
mailing list