Skip to content

Commit

Permalink
[Backend] Add clearSubtargetMap API for TargetMachine. (llvm#112383)
Browse files Browse the repository at this point in the history
- [x] Add `clearSubtargetInfo` API to TargetMachine and each backend to
make it possible to release memory used in each backend's
`SubtargetInfo` map if needed. Keep this API as `protected` so that it
will be used with precautions.
  • Loading branch information
weiweichen authored Nov 7, 2024
1 parent 3ad0148 commit c8a7f14
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions llvm/include/llvm/Target/TargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,9 @@ class LLVMTargetMachine : public TargetMachine {

void initAsmInfo();

/// Reset internal state.
virtual void reset() {};

public:
/// Get a TargetTransformInfo implementation for the target.
///
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeAArch64Target() {
initializeAArch64GlobalsTaggingPass(*PR);
}

void AArch64TargetMachine::reset() { SubtargetMap.clear(); }

//===----------------------------------------------------------------------===//
// AArch64 Lowering public interface.
//===----------------------------------------------------------------------===//
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/AArch64/AArch64TargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class AArch64TargetMachine : public LLVMTargetMachine {
std::unique_ptr<TargetLoweringObjectFile> TLOF;
mutable StringMap<std::unique_ptr<AArch64Subtarget>> SubtargetMap;

/// Reset internal state.
void reset() override;

public:
AArch64TargetMachine(const Target &T, const Triple &TT, StringRef CPU,
StringRef FS, const TargetOptions &Options,
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/ARM/ARMTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,3 +642,5 @@ bool ARMBaseTargetMachine::parseMachineFunctionInfo(
MF.getInfo<ARMFunctionInfo>()->initializeBaseYamlFields(YamlMFI);
return false;
}

void ARMBaseTargetMachine::reset() { SubtargetMap.clear(); }
3 changes: 3 additions & 0 deletions llvm/lib/Target/ARM/ARMTargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class ARMBaseTargetMachine : public LLVMTargetMachine {
bool isLittle;
mutable StringMap<std::unique_ptr<ARMSubtarget>> SubtargetMap;

/// Reset internal state.
void reset() override;

public:
ARMBaseTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
StringRef FS, const TargetOptions &Options,
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/X86/X86TargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ bool X86TargetMachine::isNoopAddrSpaceCast(unsigned SrcAS,
return SrcAS < 256 && DestAS < 256;
}

void X86TargetMachine::reset() { SubtargetMap.clear(); }

//===----------------------------------------------------------------------===//
// X86 TTI query.
//===----------------------------------------------------------------------===//
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/X86/X86TargetMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class X86TargetMachine final : public LLVMTargetMachine {
// True if this is used in JIT.
bool IsJIT;

/// Reset internal state.
void reset() override;

public:
X86TargetMachine(const Target &T, const Triple &TT, StringRef CPU,
StringRef FS, const TargetOptions &Options,
Expand Down

0 comments on commit c8a7f14

Please sign in to comment.