llvm-project/llvm/lib/Target/DirectX/DirectXTargetMachine.h
Nikita Popov 5cd0ba30f5
Reapply [IR] Lazily initialize the class to pass name mapping (NFC) (#96321) (#96462)
On MSVC the `this` uses inside `decltype` require a lambda capture. On
clang they result in an unused capture warning instead. Add the capture
and suppress the warning with `(void)this`.

-----

Initializing this map is somewhat expensive (especially for O0), so we
currently only do it if certain flags are used. I would like to make use
of it for crash dumps (#96078), where we don't know in advance whether
it will be needed or not.

This patch changes the initialization to a lazy approach, where a
callback is registered that does the actual initialization. The
callbacks will be run the first time the pass name is requested.

This way there is no compile-time impact if the mapping is not used.
2024-06-24 15:00:11 +02:00

55 lines
2.0 KiB
C++

//===- DirectXTargetMachine.h - DirectX Target Implementation ---*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
//===----------------------------------------------------------------------===//
#ifndef LLVM_DIRECTX_DIRECTXTARGETMACHINE_H
#define LLVM_DIRECTX_DIRECTXTARGETMACHINE_H
#include "DirectXSubtarget.h"
#include "llvm/Target/TargetMachine.h"
#include <optional>
namespace llvm {
class Function;
class DirectXTargetMachine : public LLVMTargetMachine {
std::unique_ptr<TargetLoweringObjectFile> TLOF;
std::unique_ptr<DirectXSubtarget> Subtarget;
public:
DirectXTargetMachine(const Target &T, const Triple &TT, StringRef CPU,
StringRef FS, const TargetOptions &Options,
std::optional<Reloc::Model> RM,
std::optional<CodeModel::Model> CM, CodeGenOptLevel OL,
bool JIT);
~DirectXTargetMachine() override;
bool addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream &Out,
raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
bool DisableVerify,
MachineModuleInfoWrapperPass *MMIWP) override;
bool addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
raw_pwrite_stream &Out, bool DisableVerify) override;
const DirectXSubtarget *getSubtargetImpl(const Function &) const override;
TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
TargetLoweringObjectFile *getObjFileLowering() const override {
return TLOF.get();
}
TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
void registerPassBuilderCallbacks(PassBuilder &PB) override;
};
} // namespace llvm
#endif // LLVM_DIRECTX_DIRECTXTARGETMACHINE_H