This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] Emit a warning for unused template args
ClosedPublic

Authored by c-rhodes on Sep 7 2021, 5:37 AM.

Details

Summary

Add a warning to TableGen for unused template arguments in classes and
multiclasses, for example:

multiclass Foo<int x> {
  def bar;
}

$ llvm-tblgen foo.td

foo.td:1:20: warning: unused template argument: Foo::x
multiclass Foo<int x> {
                   ^

A flag '--no-warn-on-unused-template-args' is added to disable the
warning. The warning is disabled for LLVM and sub-projects if
'LLVM_ENABLE_WARNINGS=OFF'.

Diff Detail

Event Timeline

c-rhodes created this revision.Sep 7 2021, 5:37 AM
c-rhodes requested review of this revision.Sep 7 2021, 5:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 7 2021, 5:37 AM

I've attached the output from make when building all targets (LLVM + Clang) with this flag turned on,

.

~3500 warnings are emitted:

grep "warning: unused template argument" unused-args-warnings.txt | wc -l
3528

but most of them are repeats:

grep "warning: unused template argument" unused-args-warnings.txt | sort -u | wc -l
178

so there's 178 in total:

llvm/include/llvm/IR/IntrinsicsAArch64.td:1368:30: warning: unused template argument: Builtin_SVCVT:name
llvm/include/llvm/IR/IntrinsicsNVVM.td:317:28: warning: unused template argument: NVVM_MMA_OPS:_
llvm/include/llvm/IR/IntrinsicsSystemZ.td:147:38: warning: unused template argument: SystemZCompareBHFG::name
llvm/include/llvm/Option/OptParser.td:217:91: warning: unused template argument: MarshallingInfoBooleanFlag:name
llvm/include/llvm/Target/TargetSelectionDAG.td:1475:40: warning: unused template argument: binary_atomic_op_ord::atomic_op
llvm/include/llvm/Target/TargetSelectionDAG.td:1503:41: warning: unused template argument: ternary_atomic_op_ord::atomic_op
llvm/lib/Target/AArch64/AArch64InstrFormats.td:10877:42: warning: unused template argument: SIMDIndexedTiedComplexHSD::U
llvm/lib/Target/AArch64/AArch64InstrFormats.td:10878:68: warning: unused template argument: SIMDIndexedTiedComplexHSD::OpNode
llvm/lib/Target/AArch64/AArch64InstrFormats.td:1709:58: warning: unused template argument: BaseAuthLoad:opr
llvm/lib/Target/AArch64/AArch64InstrFormats.td:2199:51: warning: unused template argument: MulAccum::AccNode
llvm/lib/Target/AArch64/AArch64InstrFormats.td:3427:63: warning: unused template argument: LoadStore8RO:regtype
llvm/lib/Target/AArch64/AArch64InstrFormats.td:3505:64: warning: unused template argument: LoadStore16RO:regtype
llvm/lib/Target/AArch64/AArch64InstrFormats.td:3577:64: warning: unused template argument: LoadStore32RO:regtype
llvm/lib/Target/AArch64/AArch64InstrFormats.td:3649:64: warning: unused template argument: LoadStore64RO:regtype
llvm/lib/Target/AArch64/AArch64InstrFormats.td:3721:65: warning: unused template argument: LoadStore128RO:regtype
llvm/lib/Target/AArch64/AArch64InstrFormats.td:3769:45: warning: unused template argument: Store128RO::Ty
llvm/lib/Target/AArch64/AArch64InstrFormats.td:3769:67: warning: unused template argument: Store128RO::storeop
llvm/lib/Target/AArch64/AArch64InstrFormats.td:6824:61: warning: unused template argument: SIMDThreeScalarHSTied::OpNode
llvm/lib/Target/AArch64/AArch64InstrFormats.td:7242:36: warning: unused template argument: SIMDDupFromElement:elttype
llvm/lib/Target/AArch64/AArch64InstrFormats.td:7684:33: warning: unused template argument: SIMDScalarCPY::asm
llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td:1123:125: warning: unused template argument: sve_prefetch::scale
llvm/lib/Target/AArch64/SMEInstrFormats.td:481:64: warning: unused template argument: sme_vector_to_tile_aliases::imm_ty
llvm/lib/Target/AArch64/SVEInstrFormats.td:1941:50: warning: unused template argument: sve_fp_3op_p_zds_zx::op
llvm/lib/Target/AArch64/SVEInstrFormats.td:1941:72: warning: unused template argument: sve_fp_3op_p_zds_zx::rev_op
llvm/lib/Target/AArch64/SVEInstrFormats.td:5099:59: warning: unused template argument: sve_int_index_ri::step_vector
llvm/lib/Target/AArch64/SVEInstrFormats.td:5133:59: warning: unused template argument: sve_int_index_rr::step_vector
llvm/lib/Target/AMDGPU/BUFInstructions.td:226:62: warning: unused template argument: MTBUF_Pseudo_Loads::load_vt
llvm/lib/Target/AMDGPU/BUFInstructions.td:227:54: warning: unused template argument: MTBUF_Pseudo_Loads::ld
llvm/lib/Target/AMDGPU/BUFInstructions.td:268:64: warning: unused template argument: MTBUF_Pseudo_Stores::store_vt
llvm/lib/Target/AMDGPU/BUFInstructions.td:269:55: warning: unused template argument: MTBUF_Pseudo_Stores::st
llvm/lib/Target/AMDGPU/BUFInstructions.td:544:54: warning: unused template argument: MUBUF_Pseudo_Loads::ld
llvm/lib/Target/AMDGPU/BUFInstructions.td:58:31: warning: unused template argument: getMTBUFElements:Op
llvm/lib/Target/AMDGPU/BUFInstructions.td:745:59: warning: unused template argument: MUBUF_Pseudo_Atomics_NO_RTN::atomic
llvm/lib/Target/AMDGPU/EvergreenInstructions.td:306:34: warning: unused template argument: AtomicPat::inst_ret
llvm/lib/Target/AMDGPU/EvergreenInstructions.td:307:40: warning: unused template argument: AtomicPat::node_ret
llvm/lib/Target/AMDGPU/EvergreenInstructions.td:314:40: warning: unused template argument: AtomicIncDecPat::inst_ret
llvm/lib/Target/AMDGPU/EvergreenInstructions.td:315:40: warning: unused template argument: AtomicIncDecPat::node_ret
llvm/lib/Target/AMDGPU/FLATInstructions.td:206:48: warning: unused template argument: FLAT_Global_Load_AddTid_Pseudo:HasSignedOffset
llvm/lib/Target/AMDGPU/FLATInstructions.td:244:25: warning: unused template argument: FLAT_Global_Store_AddTid_Pseudo:HasSignedOffset
llvm/lib/Target/AMDGPU/FLATInstructions.td:415:30: warning: unused template argument: FLAT_Global_Atomic_Pseudo_NO_RTN::atomic
llvm/lib/Target/AMDGPU/R600Instructions.td:213:32: warning: unused template argument: R600_REDUCTION:inst
llvm/lib/Target/AMDGPU/R600Instructions.td:816:26: warning: unused template argument: MOV_IMM:vt
llvm/lib/Target/AMDGPU/SIInstrInfo.td:1859:24: warning: unused template argument: getAsmVOP3P:HasDst
llvm/lib/Target/AMDGPU/SIInstrInfo.td:1860:52: warning: unused template argument: getAsmVOP3P:DstVT
llvm/lib/Target/AMDGPU/SIInstrInfo.td:1878:28: warning: unused template argument: getAsmVOP3OpSel:HasOMod
llvm/lib/Target/AMDGPU/SIInstrInfo.td:2021:52: warning: unused template argument: getHasDPP:DstVT
llvm/lib/Target/AMDGPU/SIInstrInfo.td:2021:76: warning: unused template argument: getHasDPP:Src0VT
llvm/lib/Target/AMDGPU/SIInstrInfo.td:2022:37: warning: unused template argument: getHasDPP:Src1VT
llvm/lib/Target/AMDGPU/SIRegisterInfo.td:129:68: warning: unused template argument: SIRegWithSubRegs:regIdx
llvm/lib/Target/AMDGPU/SOPInstructions.td:1110:25: warning: unused template argument: SOPP_Real:op
llvm/lib/Target/AMDGPU/SOPInstructions.td:716:25: warning: unused template argument: SOPK_Real:op
llvm/lib/Target/AMDGPU/VOP2Instructions.td:157:51: warning: unused template argument: VOP2Inst_sdwa::node
llvm/lib/Target/AMDGPU/VOP2Instructions.td:158:41: warning: unused template argument: VOP2Inst_sdwa::revOp
llvm/lib/Target/AMDGPU/VOP2Instructions.td:930:33: warning: unused template argument: VOP2_DPP8:opName
llvm/lib/Target/AMDGPU/VOP3Instructions.td:531:66: warning: unused template argument: Ternary_i16_Pats::op3
llvm/lib/Target/AMDGPU/VOP3Instructions.td:547:70: warning: unused template argument: Ternary_i16_Pats_gfx9::op3
llvm/lib/Target/AMDGPU/VOP3PInstructions.td:116:38: warning: unused template argument: MadFmaMixPats::mix_inst
llvm/lib/Target/AMDGPU/VOP3PInstructions.td:54:52: warning: unused template argument: VOP3_VOP3PInst::node
llvm/lib/Target/AMDGPU/VOPInstructions.td:61:34: warning: unused template argument: VOP3Common:VOP3Only
llvm/lib/Target/AMDGPU/VOPInstructions.td:86:35: warning: unused template argument: VOP3_Pseudo:VOP3Only
llvm/lib/Target/ARM/ARMInstrInfo.td:1592:54: warning: unused template argument: AsI1_rbin_irs::Commutable
llvm/lib/Target/ARM/ARMInstrInfo.td:1696:62: warning: unused template argument: AsI1_rbin_s_is::iir
llvm/lib/Target/ARM/ARMInstrInfo.td:1698:44: warning: unused template argument: AsI1_rbin_s_is::Commutable
llvm/lib/Target/ARM/ARMInstrMVE.td:2920:49: warning: unused template argument: MVE_VxSHRN:pattern
llvm/lib/Target/ARM/ARMInstrMVE.td:2963:52: warning: unused template argument: MVE_VxQRSHRUN:pattern
llvm/lib/Target/ARM/ARMInstrMVE.td:3014:51: warning: unused template argument: MVE_VxQRSHRN:pattern
llvm/lib/Target/ARM/ARMInstrMVE.td:3615:45: warning: unused template argument: MVE_VMULT_fp_m::bit_21
llvm/lib/Target/ARM/ARMInstrMVE.td:5141:54: warning: unused template argument: MVE_qr_base:itin
llvm/lib/Target/ARM/ARMInstrMVE.td:6175:32: warning: unused template argument: MVE_VLDRSTR_cs:im
llvm/lib/Target/ARM/ARMInstrNEON.td:2734:33: warning: unused template argument: N3VDIntnp:f
llvm/lib/Target/ARM/ARMInstrNEON.td:2736:46: warning: unused template argument: N3VDIntnp:Commutable
llvm/lib/Target/ARM/ARMInstrNEON.td:2789:46: warning: unused template argument: N3VQIntnp:Commutable
llvm/lib/Target/ARM/ARMInstrNEON.td:2798:46: warning: unused template argument: N3VQInt3np:Commutable
llvm/lib/Target/ARM/ARMInstrNEON.td:3118:46: warning: unused template argument: N3VLIntnp:Commutable
llvm/lib/Target/ARM/ARMInstrNEON.td:4044:31: warning: unused template argument: N2VShR_QHSD::baseOpc
llvm/lib/Target/ARM/ARMInstrNEON.td:4990:60: warning: unused template argument: N3VCP8ComplexTied::Op
llvm/lib/Target/ARM/ARMInstrNEON.td:5010:60: warning: unused template argument: N3VCP8ComplexOdd::Op
llvm/lib/Target/ARM/ARMInstrNEON.td:5036:52: warning: unused template argument: N3VCP8ComplexTiedLane::Op
llvm/lib/Target/ARM/ARMInstrNEON.td:7075:64: warning: unused template argument: VEXTq:immTy
llvm/lib/Target/Hexagon/HexagonInstrFormats.td:271:54: warning: unused template argument: InstDuplex:pattern
llvm/lib/Target/Hexagon/HexagonPseudo.td:201:34: warning: unused template argument: Call_nr:isPred
llvm/lib/Target/Hexagon/HexagonPseudo.td:270:39: warning: unused template argument: JumpOpcStr:New
llvm/lib/Target/Lanai/LanaiInstrInfo.td:272:57: warning: unused template argument: ALUbase::OpNode
llvm/lib/Target/Mips/MicroMips32r6InstrFormats.td:961:39: warning: unused template argument: CMP_BRANCH_OFF21_FM_MMR6:opstr
llvm/lib/Target/Mips/MicroMips32r6InstrInfo.td:1200:71: warning: unused template argument: SB16_MMR6_DESC_BASE:RO
llvm/lib/Target/Mips/MicroMips32r6InstrInfo.td:1201:45: warning: unused template argument: SB16_MMR6_DESC_BASE:OpNode
llvm/lib/Target/Mips/MicroMips32r6InstrInfo.td:409:44: warning: unused template argument: CACHE_HINT_MMR6_DESC:GPROpnd
llvm/lib/Target/Mips/MicroMipsDSPInstrInfo.td:284:63: warning: unused template argument: EXT_MM_2R_DESC_BASE:OpNode
llvm/lib/Target/Mips/MicroMipsDSPInstrInfo.td:291:63: warning: unused template argument: EXT_MM_1R_DESC_BASE:OpNode
llvm/lib/Target/Mips/MicroMipsInstrInfo.td:198:62: warning: unused template argument: CompactBranchMM:cond_op
llvm/lib/Target/Mips/MicroMipsInstrInfo.td:243:55: warning: unused template argument: StorePairMM:Addr
llvm/lib/Target/Mips/MicroMipsInstrInfo.td:251:54: warning: unused template argument: LoadPairMM:Addr
llvm/lib/Target/Mips/MicroMipsInstrInfo.td:335:63: warning: unused template argument: LoadMM16:OpNode
llvm/lib/Target/Mips/MicroMipsInstrInfo.td:344:61: warning: unused template argument: StoreMM16:RO
llvm/lib/Target/Mips/MicroMipsInstrInfo.td:345:35: warning: unused template argument: StoreMM16:OpNode
llvm/lib/Target/Mips/MicroMipsInstrInfo.td:503:58: warning: unused template argument: LoadWordIndexedScaledMM:OpNode
llvm/lib/Target/Mips/MicroMipsInstrInfo.td:544:70: warning: unused template argument: StoreMultMM:Addr
llvm/lib/Target/Mips/MicroMipsInstrInfo.td:552:70: warning: unused template argument: LoadMultMM:Addr
llvm/lib/Target/Mips/MicroMipsInstrInfo.td:561:43: warning: unused template argument: StoreMultMM16:Addr
llvm/lib/Target/Mips/MicroMipsInstrInfo.td:570:42: warning: unused template argument: LoadMultMM16:Addr
llvm/lib/Target/Mips/Mips16InstrInfo.td:307:49: warning: unused template argument: FMULT16_ins:itin
llvm/lib/Target/Mips/Mips16InstrInfo.td:314:52: warning: unused template argument: FMULT16_LO_ins:itin
llvm/lib/Target/Mips/Mips32r6InstrInfo.td:704:39: warning: unused template argument: CACHE_HINT_DESC:GPROpnd
llvm/lib/Target/Mips/MipsDSPInstrInfo.td:401:67: warning: unused template argument: EXTR_W_TY1_R2_DESC_BASE:OpNode
llvm/lib/Target/Mips/MipsDSPInstrInfo.td:410:67: warning: unused template argument: EXTR_W_TY1_R1_DESC_BASE:OpNode
llvm/lib/Target/Mips/MipsDSPInstrInfo.td:525:74: warning: unused template argument: BPOSGE32_PSEUDO_DESC_BASE:itin
llvm/lib/Target/Mips/MipsEVAInstrInfo.td:73:54: warning: unused template argument: STORE_EVA_DESC_BASE:OpNode
llvm/lib/Target/Mips/MipsMSAInstrInfo.td:1311:41: warning: unused template argument: MSA_2R_FILL_PSEUDO_BASE:VT
llvm/lib/Target/Mips/MipsMSAInstrInfo.td:3759:58: warning: unused template argument: MSA_CBRANCH_PSEUDO_DESC_BASE:itin
llvm/lib/Target/NVPTX/NVPTXIntrinsics.td:1235:11: warning: unused template argument: F_ATOMIC_2_NEG_imp::IMMType
llvm/lib/Target/PowerPC/PPCInstrFormats.td:892:64: warning: unused template argument: XForm_htm0:pattern
llvm/lib/Target/PowerPC/PPCInstrFormats.td:906:64: warning: unused template argument: XForm_htm1:pattern
llvm/lib/Target/PowerPC/PPCInstrFormats.td:919:46: warning: unused template argument: XForm_htm2:pattern
llvm/lib/Target/PowerPC/PPCInstrFormats.td:933:46: warning: unused template argument: XForm_htm3:pattern
llvm/lib/Target/PowerPC/PPCInstrInfo.td:1275:55: warning: unused template argument: XOForm_1rx::oe
llvm/lib/Target/PowerPC/PPCInstrPrefix.td:624:48: warning: unused template argument: 8LS_DForm_R_XTp5_SI34_MEM_p::pref
llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td:2385:35: warning: unused template argument: VPatTernaryNoMask:mask_type
llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td:2408:45: warning: unused template argument: VPatTernaryNoMaskWithPolicy:mask_type
llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td:106:37: warning: unused template argument: VPatBinarySDNode_VV:mask_type
llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td:110:32: warning: unused template argument: VPatBinarySDNode_VV:RetClass
llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td:125:37: warning: unused template argument: VPatBinarySDNode_XI:mask_type
llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td:129:32: warning: unused template argument: VPatBinarySDNode_XI:RetClass
llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td:170:37: warning: unused template argument: VPatBinarySDNode_VF:mask_type
llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td:174:32: warning: unused template argument: VPatBinarySDNode_VF:RetClass
llvm/lib/Target/RISCV/RISCVInstrInfoV.td:670:75: warning: unused template argument: VCMP_IV_V_X::optype
llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td:276:33: warning: unused template argument: VPatBinaryVL_VV::RetClass
llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td:307:33: warning: unused template argument: VPatBinaryVL_XI::RetClass
llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td:377:28: warning: unused template argument: VPatBinaryVL_VF:RetClass
llvm/lib/Target/RISCV/RISCVRegisterInfo.td:375:35: warning: unused template argument: SubRegSet:LIn
llvm/lib/Target/RISCV/RISCVRegisterInfo.td:375:44: warning: unused template argument: SubRegSet:start
llvm/lib/Target/Sparc/SparcInstrInfo.td:372:64: warning: unused template argument: LoadASI:OpNode
llvm/lib/Target/Sparc/SparcInstrInfo.td:373:43: warning: unused template argument: LoadASI:Ty
llvm/lib/Target/Sparc/SparcInstrInfo.td:373:69: warning: unused template argument: LoadASI:itin
llvm/lib/Target/Sparc/SparcInstrInfo.td:415:34: warning: unused template argument: StoreASI:OpNode
llvm/lib/Target/Sparc/SparcInstrInfo.td:415:70: warning: unused template argument: StoreASI:Ty
llvm/lib/Target/WebAssembly/WebAssemblyInstrAtomics.td:662:58: warning: unused template argument: BinRMWTruncExtPattern::rmw_64
llvm/lib/Target/WebAssembly/WebAssemblyInstrAtomics.td:898:58: warning: unused template argument: TerRMWTruncExtPattern::rmw_64
llvm/lib/Target/X86/X86InstrAVX512.td:10164:18: warning: unused template argument: WriteShuffle256_BQ::OpNode
llvm/lib/Target/X86/X86InstrAVX512.td:11488:72: warning: unused template argument: avx512_movddup_common::OpNode
llvm/lib/Target/X86/X86InstrAVX512.td:11674:64: warning: unused template argument: avx512_shufp::VTInfo_I
llvm/lib/Target/X86/X86InstrAVX512.td:1189:44: warning: unused template argument: avx512_broadcast_scalar::opc
llvm/lib/Target/X86/X86InstrAVX512.td:1189:56: warning: unused template argument: avx512_broadcast_scalar::OpcodeStr
llvm/lib/Target/X86/X86InstrAVX512.td:1211:45: warning: unused template argument: avx512_broadcast_rm_split::Name
llvm/lib/Target/X86/X86InstrAVX512.td:5590:54: warning: unused template argument: avx512_fp_scalar_round::IsCommutable
llvm/lib/Target/X86/X86InstrAVX512.td:5842:55: warning: unused template argument: avx512_fp_binop_ph::IsPD128Commutable
llvm/lib/Target/X86/X86InstrAVX512.td:6026:33: warning: unused template argument: avx512_vptest::Name
llvm/lib/Target/X86/X86InstrAVX512.td:6766:58: warning: unused template argument: avx512_fma3p_213_rm::Suff
llvm/lib/Target/X86/X86InstrAVX512.td:6797:60: warning: unused template argument: avx512_fma3_213_round::Suff
llvm/lib/Target/X86/X86InstrAVX512.td:6859:58: warning: unused template argument: avx512_fma3p_231_rm::Suff
llvm/lib/Target/X86/X86InstrAVX512.td:6892:60: warning: unused template argument: avx512_fma3_231_round::Suff
llvm/lib/Target/X86/X86InstrAVX512.td:6953:58: warning: unused template argument: avx512_fma3p_132_rm::Suff
llvm/lib/Target/X86/X86InstrAVX512.td:6988:60: warning: unused template argument: avx512_fma3_132_round::Suff
llvm/lib/Target/X86/X86InstrAVX512.td:7647:32: warning: unused template argument: avx512_cvt_s::aliasStr
llvm/lib/Target/X86/X86InstrAVX512.td:8110:48: warning: unused template argument: avx512_cvt_trunc::bcast256
llvm/lib/Target/X86/X86InstrAVX512.td:8111:48: warning: unused template argument: avx512_cvt_trunc::bcast512
llvm/lib/Target/X86/X86InstrAVX512.td:8113:49: warning: unused template argument: avx512_cvt_trunc::loadVT256
llvm/lib/Target/X86/X86InstrAVX512.td:8114:49: warning: unused template argument: avx512_cvt_trunc::loadVT512
llvm/lib/Target/X86/X86InstrAVX512.td:8116:55: warning: unused template argument: avx512_cvt_trunc::maskRC256
llvm/lib/Target/X86/X86InstrAVX512.td:8117:55: warning: unused template argument: avx512_cvt_trunc::maskRC512
llvm/lib/Target/X86/X86InstrAVX512.td:9240:54: warning: unused template argument: avx512_ord_cmp_sae::d
llvm/lib/Target/X86/X86InstrAVX512.td:9864:53: warning: unused template argument: avx512_trunc_mr_lowering::DestInfo
llvm/lib/Target/X86/X86InstrAVX512.td:9909:66: warning: unused template argument: avx512_trunc_qb::OpNode
llvm/lib/Target/X86/X86InstrAVX512.td:9910:46: warning: unused template argument: avx512_trunc_qb::MaskNode
llvm/lib/Target/X86/X86InstrFMA.td:430:32: warning: unused template argument: fma4s_int::VT
llvm/lib/Target/X86/X86InstrFMA.td:606:56: warning: unused template argument: scalar_fma4_patterns::EltVT
llvm/lib/Target/X86/X86InstrSSE.td:191:40: warning: unused template argument: sse12_move_rr::x86memop
llvm/lib/Target/X86/X86InstrSSE.td:2269:43: warning: unused template argument: sse12_fp_packed_logical::OpNode
llvm/lib/Target/X86/X86InstrSSE.td:2793:37: warning: unused template argument: sse_fp_unop_s::ScalarVT
llvm/lib/Target/X86/X86InstrSSE.td:2821:45: warning: unused template argument: sse_fp_unop_s_intr::RC
llvm/lib/Target/X86/X86InstrSSE.td:2823:56: warning: unused template argument: sse_fp_unop_s_intr::Suffix
llvm/lib/Target/X86/X86InstrSSE.td:2844:45: warning: unused template argument: avx_fp_unop_s_intr::RC
llvm/lib/Target/X86/X86InstrSSE.td:2975:40: warning: unused template argument: sse1_fp_unop_s_intr::opc
llvm/lib/Target/X86/X86InstrSSE.td:2975:70: warning: unused template argument: sse1_fp_unop_s_intr::OpNode
llvm/lib/Target/X86/X86InstrSSE.td:2976:47: warning: unused template argument: sse1_fp_unop_s_intr::sched
llvm/lib/Target/X86/X86InstrSSE.td:43:52: warning: unused template argument: sse12_fp_scalar_int::OpcodeStr
llvm/lib/Target/X86/X86InstrSSE.td:7895:40: warning: unused template argument: avx2_gather::MTx
llvm/lib/Target/X86/X86InstrSSE.td:7895:61: warning: unused template argument: avx2_gather::MTy
llvm/lib/Target/X86/X86InstrVecCompiler.td:115:60: warning: unused template argument: subvec_zero_lowering::ZeroTy

this llvm/lib/Target/AArch64/SMEInstrFormats.td:481:64: warning: unused template argument: sme_vector_to_tile_aliases::imm_ty diagnoses a bug I recently discovered and was the reason I thought this warning would be useful.

(I've been scarce due to summer holidays and, sadly, real work.)

This is a great feature. Do we also need to add an 'unused' declaration that acknowledges the non-use of a template argument and suppresses the warning? Are there legitimate cases where an argument is passed but not used?

I think the test should include a couple of cases where the argument is used, to be sure that no warning is produced.

All the X86 cases look pretty trivial - I'll clear those up this afternoon

(I've been scarce due to summer holidays and, sadly, real work.)

This is a great feature. Do we also need to add an 'unused' declaration that acknowledges the non-use of a template argument and suppresses the warning?

I'm not really sure what an unused declaration would look like in TableGen, in C I think prefixing unused args with (void) is the usual way of suppressing these kind of errors. One existing way to suppress the warning could be:

class Foo<int x> {
  int x = x;
}

but that's not particularly pretty.

Are there legitimate cases where an argument is passed but not used?

Good question, I haven't looked at all the warnings but I've not observed this for AArch64.

I think the test should include a couple of cases where the argument is used, to be sure that no warning is produced.

Good point I'll add a test for that.

This is a great feature. Do we also need to add an 'unused' declaration that acknowledges the non-use of a template argument and suppresses the warning?

I'm not really sure what an unused declaration would look like in TableGen, in C I think prefixing unused args with (void) is the usual way of suppressing these kind of errors. One existing way to suppress the warning could be:

class Foo<int x> {
  int x = x;
}

but that's not particularly pretty.

scratch that, that example results in a recursion / self-assignment forbidden error.

c-rhodes updated this revision to Diff 371066.Sep 7 2021, 7:28 AM

Test no warning is emitted for a used arg.

I would propose something radical like a new statement:

unused id, ... ;

Maybe eventually a -strict option that checks various invariants?

I would propose something radical like a new statement:

unused id, ... ;

Given the flag is optional is it necessary to have support for this right now? It think it would also be good to see some examples where an unused template argument makes sense before preemptively adding a new statement.

Maybe eventually a -strict option that checks various invariants?

That would be nice, do you have any other invariants in mind?

@craig.topper the RISCV warnings (see first comment) might be of interest to you

@c-rhodes Oh, absolutely, no need for a new statement until we determine whether there are legitimate reasons for unused template arguments. In fact, if we determine that there are none, we could make the new option on by default.

@craig.topper the RISCV warnings (see first comment) might be of interest to you

Should be fixed now.

This is a really great feature, my suggestions:

  1. We should clean up the existing warnings before landing this patch.
  2. This should be on for LLVM when it lands, and we should remove the -W flag that controls it after the rest of the ecosystem (MLIR etc) has a chance to adapt to this.

I love this!

This is a really great feature, my suggestions:

  1. We should clean up the existing warnings before landing this patch.
  2. This should be on for LLVM when it lands, and we should remove the -W flag that controls it after the rest of the ecosystem (MLIR etc) has a chance to adapt to this.

I love this!

Thanks for the comments! I think that's a sensible way to move forward, I'll ping the owners of the backends that still have warnings and fix up what I can.

c-rhodes added a subscriber: arsenm.Sep 8 2021, 1:08 PM

@arsenm the AMDGPU warnings (see first comment) might be of interest to you

@atanasyan the MIPS warnings (see first comment) might be of interest to you

Patches fixing warnings have either landed or are in review for all but AMDGPU and MIPS now. @tstellar please could you take a look at the warnings in the AMDGPU backend or tag another contributor? Understand you might be busy with the 13 release.

Patches fixing warnings have either landed or are in review for all but AMDGPU and MIPS now. @tstellar please could you take a look at the warnings in the AMDGPU backend or tag another contributor? Understand you might be busy with the 13 release.

BTW I'm going to fix MIPS warnings in a few days.

Patches fixing warnings have either landed or are in review for all but AMDGPU and MIPS now. @tstellar please could you take a look at the warnings in the AMDGPU backend or tag another contributor? Understand you might be busy with the 13 release.

BTW I'm going to fix MIPS warnings in a few days.

awesome, thanks @atanasyan

foad added a subscriber: foad.Sep 15 2021, 6:41 AM

AMDGPU fixes: D109826

Just an update on this patch, the only remaining warnings are in the Sparc backend, D109712 fixes them but still waiting on review. I plan to update this patch soon to turn the flag on by default for LLVM and Clang.

c-rhodes updated this revision to Diff 376181.Sep 30 2021, 6:44 AM
c-rhodes retitled this revision from [TableGen] Optionally emit a warning for unused template args to [TableGen] Emit a warning for unused template args.
c-rhodes edited the summary of this revision. (Show Details)

I built all projects that use TableGen (llvm clang, libc, lld, lldb, mlir) for all targets and apart from the Sparc warnings in LLVM that are outstanding (D109712) I only found 2 warnings in MLIR, which are addressed in D110805. Once these outstanding warnings are addressed I think this can be enabled for the whole ecosystem, so I've updated the patch to enable flag for LLVM and sub-projects, if LLVM_ENABLE_WARNINGS=On.

Are there any more show stoppers for this?

c-rhodes updated this revision to Diff 383777.Nov 1 2021, 4:47 AM
c-rhodes edited the summary of this revision. (Show Details)
  • Emit warning by default in TableGen.
  • Change --warn-on-unused-template-args to --no-warn-on-unused-template-args to disable warning.
  • Warning is disabled for LLVM and sub-projects if LLVM_ENABLE_WARNINGS=OFF.
  • Disable warning for existing TableGen tests with unused template args.

Are there any more show stoppers for this?

I don't believe so, as of yesterday all warnings have now been fixed. I've updated the patch to enable the warning by default in TableGen with a flag to explicitly disable it. Compiled/tested for projects clang;llvm;libc;lld;lldb;mlir on all targets.

RKSimon accepted this revision.Nov 1 2021, 5:00 AM

LGTM with one optional minor

llvm/lib/TableGen/Record.cpp
2666

(style) Use for-range loop?

This revision is now accepted and ready to land.Nov 1 2021, 5:00 AM
c-rhodes updated this revision to Diff 383795.Nov 1 2021, 6:57 AM

Use range-based for loop for template args.

c-rhodes marked an inline comment as done.Nov 1 2021, 6:57 AM

LGTM with one optional minor

Done, thanks for reviewing!

This revision was landed with ongoing or failed builds.Nov 3 2021, 5:09 AM
This revision was automatically updated to reflect the committed changes.

I'm seeing warnings from this in my downstream project. The template argument is currently unused because there's a TODO to add additional restrictions based on it https://github.com/google/iree/blob/f06c804f9ec79e16da7dcee1af81afd7b95a8bb1/iree/compiler/Dialect/Util/IR/UtilBase.td#L186. I don't see in the thread that there was any conclusion for how to suppress this warning. The argument that it's optional doesn't really apply anymore, since it's on by default. Do we have a way to do the equivalent of casting to void to suppress this warning locally?

I suggested an 'unused' statement above. With it, we should be able to make this option on by default.

I don't think it's a good idea to completely disallow unused arguments.

I suggested an 'unused' statement above.

Yeah something like that seems fine to me. Also fine with a useless assignment, if such a thing is possible

With it, we should be able to make this option on by default.

It appears to already be on by default :-(

I don't think it's a good idea to completely disallow unused arguments.

Agreed.

foad added a comment.Nov 4 2021, 10:29 AM

I'm seeing warnings from this in my downstream project. The template argument is currently unused because there's a TODO to add additional restrictions based on it https://github.com/google/iree/blob/f06c804f9ec79e16da7dcee1af81afd7b95a8bb1/iree/compiler/Dialect/Util/IR/UtilBase.td#L186. I don't see in the thread that there was any conclusion for how to suppress this warning. The argument that it's optional doesn't really apply anymore, since it's on by default. Do we have a way to do the equivalent of casting to void to suppress this warning locally?

Can you put something like defvar unused = !size(types); inside your class?

Can you put something like defvar unused = !size(types); inside your class?

Thanks for the suggestion, but apparently not :-(

iree/compiler/Dialect/Util/IR/UtilBase.td:187:25: error: Variable not defined: 'types'
  defvar unused = !size(types);

Can you put something like defvar unused = !size(types); inside your class?

Thanks for the suggestion, but apparently not :-(

iree/compiler/Dialect/Util/IR/UtilBase.td:187:25: error: Variable not defined: 'types'
  defvar unused = !size(types);

I can add a random extra "unused" field though int unused = !size(types);

I vote for something explicit. An unused field seems like a hack, no?

I vote for something explicit. An unused field seems like a hack, no?

I mean so does casting to void :-) I agree that something explicit would be better. I don't love adding unused fields. If it's just some trick, I much prefer an approach that doesn't have any side-effects, like the defvar suggestion (I don't understand why that doesn't work).

I mean something really explicit, like a statement especially designed for this.

unused foo, bar;

I mean something really explicit, like a statement especially designed for this.

unused foo, bar;

Yup I understand that and agree. I'm saying that barring that, my second choice would be something that has no visible effect. I don't like my current workaround which adds a useless field to the record.

Doesn't C++ allow unnamed parameters? That would be another way to do it. And that would make it impossible to reference the template argument name.