Repository navigation
[Mips] Remove unused function templates (NFC) - #202971
Conversation
A few function templates in the Mips MC layer have no callers anywhere, so they never get instantiated and trip `-Wunused-template`. They all live in `.cpp` files, so this is plain dead-code removal. `MipsELFObjectWriter.cpp`: `copy_if_else` and `find_best` lost their only user when `sortRelocs` was rewritten in llvm#104723. The `FindBestPredicateResult` enum existed only for `find_best`, so it goes too. `MipsDisassembler.cpp`: `DecodeDAHIDATIMMR6` isn't referenced by any `DecoderMethod`. The r6 DAHI/DATI instructions decode through its sibling `DecodeDAHIDATI`, which is what the generated tables actually call. NFC: removes uninstantiated templates only. Part of llvm#202945.
|
@llvm/pr-subscribers-backend-mips Author: Aditya Medhane (flash1729) ChangesA few function templates in the Mips MC layer have no callers anywhere, so they never get instantiated and trip
NFC: removes uninstantiated templates only. Part of #202945. 2 Files Affected:
diff --git a/llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp b/llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp
index 808ff67428c12..bbd614fc64423 100644
--- a/llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp
+++ b/llvm/lib/Target/Mips/Disassembler/MipsDisassembler.cpp
@@ -338,21 +338,6 @@ static DecodeStatus DecodeINSVE_DF(MCInst &MI, InsnType insn, uint64_t Address,
return MCDisassembler::Success;
}
-template <typename InsnType>
-static DecodeStatus DecodeDAHIDATIMMR6(MCInst &MI, InsnType insn,
- uint64_t Address,
- const MCDisassembler *Decoder) {
- InsnType Rs = fieldFromInstruction(insn, 16, 5);
- InsnType Imm = fieldFromInstruction(insn, 0, 16);
- MI.addOperand(MCOperand::createReg(getReg(Decoder, Mips::GPR64RegClassID,
- Rs)));
- MI.addOperand(MCOperand::createReg(getReg(Decoder, Mips::GPR64RegClassID,
- Rs)));
- MI.addOperand(MCOperand::createImm(Imm));
-
- return MCDisassembler::Success;
-}
-
template <typename InsnType>
static DecodeStatus DecodeDAHIDATI(MCInst &MI, InsnType insn, uint64_t Address,
const MCDisassembler *Decoder) {
diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
index 680d27927ba36..4defb4f12db69 100644
--- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
+++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp
@@ -54,63 +54,8 @@ class MipsELFObjectWriter : public MCELFObjectTargetWriter {
void sortRelocs(std::vector<ELFRelocationEntry> &Relocs) override;
};
-/// The possible results of the Predicate function used by find_best.
-enum FindBestPredicateResult {
- FindBest_NoMatch = 0, ///< The current element is not a match.
- FindBest_Match, ///< The current element is a match but better ones are
- /// possible.
- FindBest_PerfectMatch, ///< The current element is an unbeatable match.
-};
-
} // end anonymous namespace
-/// Copy elements in the range [First, Last) to d1 when the predicate is true or
-/// d2 when the predicate is false. This is essentially both std::copy_if and
-/// std::remove_copy_if combined into a single pass.
-template <class InputIt, class OutputIt1, class OutputIt2, class UnaryPredicate>
-static std::pair<OutputIt1, OutputIt2> copy_if_else(InputIt First, InputIt Last,
- OutputIt1 d1, OutputIt2 d2,
- UnaryPredicate Predicate) {
- for (InputIt I = First; I != Last; ++I) {
- if (Predicate(*I)) {
- *d1 = *I;
- d1++;
- } else {
- *d2 = *I;
- d2++;
- }
- }
-
- return std::make_pair(d1, d2);
-}
-
-/// Find the best match in the range [First, Last).
-///
-/// An element matches when Predicate(X) returns FindBest_Match or
-/// FindBest_PerfectMatch. A value of FindBest_PerfectMatch also terminates
-/// the search. BetterThan(A, B) is a comparator that returns true when A is a
-/// better match than B. The return value is the position of the best match.
-///
-/// This is similar to std::find_if but finds the best of multiple possible
-/// matches.
-template <class InputIt, class UnaryPredicate, class Comparator>
-static InputIt find_best(InputIt First, InputIt Last, UnaryPredicate Predicate,
- Comparator BetterThan) {
- InputIt Best = Last;
-
- for (InputIt I = First; I != Last; ++I) {
- unsigned Matched = Predicate(*I);
- if (Matched != FindBest_NoMatch) {
- if (Best == Last || BetterThan(*I, *Best))
- Best = I;
- }
- if (Matched == FindBest_PerfectMatch)
- break;
- }
-
- return Best;
-}
-
/// Determine the low relocation that matches the given relocation.
/// If the relocation does not need a low relocation then the return value
/// is ELF::R_MIPS_NONE.
|
🪟 Windows x64 Test Results
✅ The build succeeded and all tests passed. |
|
LGTM. |
A few function templates in the Mips MC layer have no callers anywhere, so they never get instantiated and trip `-Wunused-template`. They all live in `.cpp` files, so this is plain dead-code removal. `MipsELFObjectWriter.cpp`: `copy_if_else` and `find_best` lost their only user when `sortRelocs` was rewritten in llvm#104723. The `FindBestPredicateResult` enum existed only for `find_best`, so it goes too. `MipsDisassembler.cpp`: `DecodeDAHIDATIMMR6` isn't referenced by any `DecoderMethod`. The r6 DAHI/DATI instructions decode through its sibling `DecodeDAHIDATI`, which is what the generated tables actually call. NFC: removes uninstantiated templates only. Part of llvm#202945.
A few function templates in the Mips MC layer have no callers anywhere, so they never get instantiated and trip `-Wunused-template`. They all live in `.cpp` files, so this is plain dead-code removal. `MipsELFObjectWriter.cpp`: `copy_if_else` and `find_best` lost their only user when `sortRelocs` was rewritten in llvm#104723. The `FindBestPredicateResult` enum existed only for `find_best`, so it goes too. `MipsDisassembler.cpp`: `DecodeDAHIDATIMMR6` isn't referenced by any `DecoderMethod`. The r6 DAHI/DATI instructions decode through its sibling `DecodeDAHIDATI`, which is what the generated tables actually call. NFC: removes uninstantiated templates only. Part of llvm#202945.
Uncomment `UnusedTemplate` in the `Unused` diagnostic group so `-Wunused-template` becomes part of `-Wall`. `-Wunused-template` flags unused function and variable templates with internal linkage. In a header, such a template gives every translation unit its own internal-linkage copy, which is a latent ODR violation (ill-formed, no diagnostic required), so enabling this surfaces a real class of bugs and keeps the pattern from reappearing. ### Depends on The in-tree occurrences were cleaned up first in a series of NFC PRs tracked by #202945. This change only builds clean once those land, so CI will be red on any area whose cleanup is not yet merged. Remaining prerequisites: Approved - #202969 - #202971 - #202973 - #202974 - #206309 - #206312 Needs to be reviewed - #202988 - #206308 Closes #202945 cc @AaronBallman @vgvassilev
Uncomment `UnusedTemplate` in the `Unused` diagnostic group so `-Wunused-template` becomes part of `-Wall`. `-Wunused-template` flags unused function and variable templates with internal linkage. In a header, such a template gives every translation unit its own internal-linkage copy, which is a latent ODR violation (ill-formed, no diagnostic required), so enabling this surfaces a real class of bugs and keeps the pattern from reappearing. ### Depends on The in-tree occurrences were cleaned up first in a series of NFC PRs tracked by #202945. This change only builds clean once those land, so CI will be red on any area whose cleanup is not yet merged. Remaining prerequisites: Approved - #202969 - #202971 - #202973 - #202974 - #206309 - #206312 Needs to be reviewed - #202988 - #206308 Closes #202945 cc @AaronBallman @vgvassilev
A few function templates in the Mips MC layer have no callers anywhere, so they never get instantiated and trip
-Wunused-template. They all live in.cppfiles, so this is plain dead-code removal.MipsELFObjectWriter.cpp:copy_if_elseandfind_bestlost their only user whensortRelocswas rewritten in #104723. TheFindBestPredicateResultenum existed only forfind_best, so it goes too.MipsDisassembler.cpp:DecodeDAHIDATIMMR6isn't referenced by anyDecoderMethod. The r6 DAHI/DATI instructions decode through its siblingDecodeDAHIDATI, which is what the generated tables actually call.NFC: removes uninstantiated templates only.
Part of #202945.