Skip to content

Commit 2538c60

Browse files
authored
[CodeGen] Prune headers and move code out of line for build efficiency, NFC (#135622)
I noticed these destructors taking time with -ftime-trace and moved some of them for minor build efficiency improvements. The main impact of moving destructors out of line is that it avoids requiring container fields containing other types from being complete, i.e. one can have uptr<T> or vector<T> as a field with an incomplete type T, and that means we can reduce transitive includes, as with LegalizerInfo.h. Move expensive getDebugOperandsForReg template out-of-line. The std::function instantiation shows up in time trace even if you don't use the function.
1 parent 01c1c78 commit 2538c60

File tree

10 files changed

+51
-25
lines changed

10 files changed

+51
-25
lines changed

llvm/include/llvm/CodeGen/MachineInstr.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -612,26 +612,12 @@ class MachineInstr
612612

613613
/// Returns a range of all of the operands that correspond to a debug use of
614614
/// \p Reg.
615-
template <typename Operand, typename Instruction>
616-
static iterator_range<
617-
filter_iterator<Operand *, std::function<bool(Operand &Op)>>>
618-
getDebugOperandsForReg(Instruction *MI, Register Reg) {
619-
std::function<bool(Operand & Op)> OpUsesReg(
620-
[Reg](Operand &Op) { return Op.isReg() && Op.getReg() == Reg; });
621-
return make_filter_range(MI->debug_operands(), OpUsesReg);
622-
}
623615
iterator_range<filter_iterator<const MachineOperand *,
624616
std::function<bool(const MachineOperand &Op)>>>
625-
getDebugOperandsForReg(Register Reg) const {
626-
return MachineInstr::getDebugOperandsForReg<const MachineOperand,
627-
const MachineInstr>(this, Reg);
628-
}
617+
getDebugOperandsForReg(Register Reg) const;
629618
iterator_range<filter_iterator<MachineOperand *,
630619
std::function<bool(MachineOperand &Op)>>>
631-
getDebugOperandsForReg(Register Reg) {
632-
return MachineInstr::getDebugOperandsForReg<MachineOperand, MachineInstr>(
633-
this, Reg);
634-
}
620+
getDebugOperandsForReg(Register Reg);
635621

636622
bool isDebugOperand(const MachineOperand *Op) const {
637623
return Op >= adl_begin(debug_operands()) && Op <= adl_end(debug_operands());

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,9 +329,6 @@ class TargetLoweringBase {
329329
};
330330
using ArgListTy = std::vector<ArgListEntry>;
331331

332-
virtual void markLibCallAttributes(MachineFunction *MF, unsigned CC,
333-
ArgListTy &Args) const {};
334-
335332
static ISD::NodeType getExtendForContent(BooleanContent Content) {
336333
switch (Content) {
337334
case UndefinedBooleanContent:
@@ -350,7 +347,7 @@ class TargetLoweringBase {
350347
explicit TargetLoweringBase(const TargetMachine &TM);
351348
TargetLoweringBase(const TargetLoweringBase &) = delete;
352349
TargetLoweringBase &operator=(const TargetLoweringBase &) = delete;
353-
virtual ~TargetLoweringBase() = default;
350+
virtual ~TargetLoweringBase();
354351

355352
/// Return true if the target support strict float operation
356353
bool isStrictFPEnabled() const {
@@ -3866,6 +3863,7 @@ class TargetLowering : public TargetLoweringBase {
38663863
TargetLowering &operator=(const TargetLowering &) = delete;
38673864

38683865
explicit TargetLowering(const TargetMachine &TM);
3866+
~TargetLowering() override;
38693867

38703868
bool isPositionIndependent() const;
38713869

@@ -4592,6 +4590,9 @@ class TargetLowering : public TargetLoweringBase {
45924590
llvm_unreachable("Not Implemented");
45934591
}
45944592

4593+
virtual void markLibCallAttributes(MachineFunction *MF, unsigned CC,
4594+
ArgListTy &Args) const {}
4595+
45954596
/// This structure contains the information necessary for lowering
45964597
/// pointer-authenticating indirect calls. It is equivalent to the "ptrauth"
45974598
/// operand bundle found on the call instruction, if any.

llvm/include/llvm/Target/TargetMachine.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "llvm/ADT/StringRef.h"
1717
#include "llvm/IR/DataLayout.h"
1818
#include "llvm/IR/PassManager.h"
19-
#include "llvm/MC/MCStreamer.h"
2019
#include "llvm/Support/Allocator.h"
2120
#include "llvm/Support/CodeGen.h"
2221
#include "llvm/Support/CommandLine.h"
@@ -45,6 +44,7 @@ class MCAsmInfo;
4544
class MCContext;
4645
class MCInstrInfo;
4746
class MCRegisterInfo;
47+
class MCStreamer;
4848
class MCSubtargetInfo;
4949
class MCSymbol;
5050
class raw_pwrite_stream;
@@ -490,9 +490,7 @@ class TargetMachine {
490490

491491
virtual Expected<std::unique_ptr<MCStreamer>>
492492
createMCStreamer(raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
493-
CodeGenFileType FileType, MCContext &Ctx) {
494-
return nullptr;
495-
}
493+
CodeGenFileType FileType, MCContext &Ctx);
496494

497495
/// True if the target uses physical regs (as nearly all targets do). False
498496
/// for stack machines such as WebAssembly and other virtual-register

llvm/lib/CodeGen/MachineInstr.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,28 @@ bool MachineInstr::shouldUpdateAdditionalCallInfo() const {
794794
return isCandidateForAdditionalCallInfo();
795795
}
796796

797+
template <typename Operand, typename Instruction>
798+
static iterator_range<
799+
filter_iterator<Operand *, std::function<bool(Operand &Op)>>>
800+
getDebugOperandsForRegHelper(Instruction *MI, Register Reg) {
801+
std::function<bool(Operand & Op)> OpUsesReg(
802+
[Reg](Operand &Op) { return Op.isReg() && Op.getReg() == Reg; });
803+
return make_filter_range(MI->debug_operands(), OpUsesReg);
804+
}
805+
806+
iterator_range<filter_iterator<const MachineOperand *,
807+
std::function<bool(const MachineOperand &Op)>>>
808+
MachineInstr::getDebugOperandsForReg(Register Reg) const {
809+
return getDebugOperandsForRegHelper<const MachineOperand, const MachineInstr>(
810+
this, Reg);
811+
}
812+
813+
iterator_range<
814+
filter_iterator<MachineOperand *, std::function<bool(MachineOperand &Op)>>>
815+
MachineInstr::getDebugOperandsForReg(Register Reg) {
816+
return getDebugOperandsForRegHelper<MachineOperand, MachineInstr>(this, Reg);
817+
}
818+
797819
unsigned MachineInstr::getNumExplicitOperands() const {
798820
unsigned NumOperands = MCID->getNumOperands();
799821
if (!MCID->isVariadic())

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ using namespace llvm;
4141
TargetLowering::TargetLowering(const TargetMachine &tm)
4242
: TargetLoweringBase(tm) {}
4343

44+
// Define the virtual destructor out-of-line for build efficiency.
45+
TargetLowering::~TargetLowering() = default;
46+
4447
const char *TargetLowering::getTargetNodeName(unsigned Opcode) const {
4548
return nullptr;
4649
}

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,10 @@ TargetLoweringBase::TargetLoweringBase(const TargetMachine &tm)
668668
RTLIB::initCmpLibcallCCs(CmpLibcallCCs);
669669
}
670670

671+
// Define the virtual destructor out-of-line to act as a key method to anchor
672+
// debug info (see coding standards).
673+
TargetLoweringBase::~TargetLoweringBase() = default;
674+
671675
void TargetLoweringBase::initActions() {
672676
// All operations default to being supported.
673677
memset(OpActions, 0, sizeof(OpActions));

llvm/lib/Target/TargetMachine.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/MC/MCContext.h"
2222
#include "llvm/MC/MCInstrInfo.h"
2323
#include "llvm/MC/MCRegisterInfo.h"
24+
#include "llvm/MC/MCStreamer.h"
2425
#include "llvm/MC/MCSubtargetInfo.h"
2526
#include "llvm/Support/CodeGen.h"
2627
#include "llvm/Target/TargetLoweringObjectFile.h"
@@ -45,6 +46,13 @@ TargetMachine::TargetMachine(const Target &T, StringRef DataLayoutString,
4546

4647
TargetMachine::~TargetMachine() = default;
4748

49+
Expected<std::unique_ptr<MCStreamer>>
50+
TargetMachine::createMCStreamer(raw_pwrite_stream &Out,
51+
raw_pwrite_stream *DwoOut,
52+
CodeGenFileType FileType, MCContext &Ctx) {
53+
return nullptr;
54+
}
55+
4856
bool TargetMachine::isLargeGlobalValue(const GlobalValue *GVal) const {
4957
if (getTargetTriple().getArch() != Triple::x86_64)
5058
return false;

llvm/lib/Target/X86/X86Subtarget.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,9 @@ X86Subtarget::X86Subtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU,
361361
InstSelector.reset(createX86InstructionSelector(TM, *this, *RBI));
362362
}
363363

364+
// Define the virtual destructor out-of-line for build efficiency.
365+
X86Subtarget::~X86Subtarget() = default;
366+
364367
const CallLowering *X86Subtarget::getCallLowering() const {
365368
return CallLoweringInfo.get();
366369
}

llvm/lib/Target/X86/X86Subtarget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "X86ISelLowering.h"
1818
#include "X86InstrInfo.h"
1919
#include "X86SelectionDAGInfo.h"
20-
#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
2120
#include "llvm/CodeGen/TargetSubtargetInfo.h"
2221
#include "llvm/IR/CallingConv.h"
2322
#include "llvm/TargetParser/Triple.h"
@@ -114,6 +113,7 @@ class X86Subtarget final : public X86GenSubtargetInfo {
114113
const X86TargetMachine &TM, MaybeAlign StackAlignOverride,
115114
unsigned PreferVectorWidthOverride,
116115
unsigned RequiredVectorWidth);
116+
~X86Subtarget() override;
117117

118118
const X86TargetLowering *getTargetLowering() const override {
119119
return &TLInfo;

llvm/lib/Target/X86/X86TargetTransformInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
//===----------------------------------------------------------------------===//
5050

5151
#include "X86TargetTransformInfo.h"
52+
#include "llvm/ADT/SmallBitVector.h"
5253
#include "llvm/Analysis/TargetTransformInfo.h"
5354
#include "llvm/CodeGen/BasicTTIImpl.h"
5455
#include "llvm/CodeGen/CostTable.h"

0 commit comments

Comments
 (0)