1//===- DirectXTargetTransformInfo.h - DirectX TTI ---------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9//===----------------------------------------------------------------------===//
10
11#ifndef LLVM_DIRECTX_DIRECTXTARGETTRANSFORMINFO_H
12#define LLVM_DIRECTX_DIRECTXTARGETTRANSFORMINFO_H
13
14#include "DirectXSubtarget.h"
15#include "DirectXTargetMachine.h"
16#include "llvm/CodeGen/BasicTTIImpl.h"
17#include "llvm/IR/Constants.h"
18#include "llvm/IR/Function.h"
19#include "llvm/IR/Metadata.h"
20#include "llvm/IR/Module.h"
21
22namespace llvm {
23class DirectXTTIImpl final : public BasicTTIImplBase<DirectXTTIImpl> {
24 using BaseT = BasicTTIImplBase<DirectXTTIImpl>;
25 using TTI = TargetTransformInfo;
26
27 friend BaseT;
28
29 const DirectXSubtarget *ST;
30 const DirectXTargetLowering *TLI;
31 // True when native 16-bit types are enabled (i.e. -enable-16bit-types was
32 // passed), indicated by the dx.nativelowprec module flag.
33 const bool HasNativeLowPrecision;
34
35 const DirectXSubtarget *getST() const { return ST; }
36 const DirectXTargetLowering *getTLI() const { return TLI; }
37
38 static bool readNativeLowPrecisionFlag(const Function &F) {
39 if (auto *Flag = mdconst::extract_or_null<ConstantInt>(
40 MD: F.getParent()->getModuleFlag(Key: "dx.nativelowprec")))
41 return Flag->getValue().getBoolValue();
42 return false;
43 }
44
45public:
46 explicit DirectXTTIImpl(const DirectXTargetMachine *TM, const Function &F)
47 : BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),
48 TLI(ST->getTargetLowering()),
49 HasNativeLowPrecision(readNativeLowPrecisionFlag(F)) {}
50 unsigned getMinVectorRegisterBitWidth() const override { return 32; }
51 bool isTargetIntrinsicWithScalarOpAtArg(Intrinsic::ID ID,
52 unsigned ScalarOpdIdx) const override;
53 bool isTargetIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID,
54 int OpdIdx) const override;
55 unsigned getMinimumLookupTableEntryBitWidth() const override;
56
57 InstructionCost getPartialReductionCost(
58 unsigned Opcode, Type *InputTypeA, Type *InputTypeB, Type *AccumType,
59 ElementCount VF, TTI::PartialReductionExtendKind OpAExtend,
60 TTI::PartialReductionExtendKind OpBExtend, std::optional<unsigned> BinOp,
61 TTI::TargetCostKind CostKind,
62 std::optional<FastMathFlags> FMF) const override {
63 return InstructionCost::getInvalid();
64 }
65};
66} // namespace llvm
67
68#endif // LLVM_DIRECTX_DIRECTXTARGETTRANSFORMINFO_H
69