llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
26.19k stars 10.72k forks source link

[RISCV] Defer creating RISCVInsertVSETVLI to avoid leak with -stop-after #92303

Closed lukel97 closed 2 weeks ago

lukel97 commented 2 weeks ago

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.

llvmbot commented 2 weeks ago

@llvm/pr-subscribers-backend-risc-v

Author: Luke Lau (lukel97)

Changes 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. --- Full diff: https://github.com/llvm/llvm-project/pull/92303.diff 3 Files Affected: - (modified) llvm/lib/Target/RISCV/RISCV.h (+1) - (modified) llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp (+1) - (modified) llvm/lib/Target/RISCV/RISCVTargetMachine.cpp (+2-2) ``````````diff 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() { ``````````