|
| 1 | +//===------ BPFTargetTransformInfo.h - BPF specific 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 | +// This file uses the target's specific information to |
| 10 | +// provide more precise answers to certain TTI queries, while letting the |
| 11 | +// target independent and default TTI implementations handle the rest. |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +#ifndef LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H |
| 16 | +#define LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H |
| 17 | + |
| 18 | +#include "BPFTargetMachine.h" |
| 19 | +#include "llvm/Analysis/TargetTransformInfo.h" |
| 20 | +#include "llvm/CodeGen/BasicTTIImpl.h" |
| 21 | + |
| 22 | +namespace llvm { |
| 23 | +class BPFTTIImpl : public BasicTTIImplBase<BPFTTIImpl> { |
| 24 | + typedef BasicTTIImplBase<BPFTTIImpl> BaseT; |
| 25 | + typedef TargetTransformInfo TTI; |
| 26 | + friend BaseT; |
| 27 | + |
| 28 | + const BPFSubtarget *ST; |
| 29 | + const BPFTargetLowering *TLI; |
| 30 | + |
| 31 | + const BPFSubtarget *getST() const { return ST; } |
| 32 | + const BPFTargetLowering *getTLI() const { return TLI; } |
| 33 | + |
| 34 | +public: |
| 35 | + explicit BPFTTIImpl(const BPFTargetMachine *TM, const Function &F) |
| 36 | + : BaseT(TM, F.getParent()->getDataLayout()), ST(TM->getSubtargetImpl(F)), |
| 37 | + TLI(ST->getTargetLowering()) {} |
| 38 | + |
| 39 | + int getIntImmCost(const APInt &Imm, Type *Ty, TTI::TargetCostKind CostKind) { |
| 40 | + if (Imm.getBitWidth() <= 64 && isInt<32>(Imm.getSExtValue())) |
| 41 | + return TTI::TCC_Free; |
| 42 | + |
| 43 | + return TTI::TCC_Basic; |
| 44 | + } |
| 45 | +}; |
| 46 | + |
| 47 | +} // end namespace llvm |
| 48 | + |
| 49 | +#endif // LLVM_LIB_TARGET_BPF_BPFTARGETTRANSFORMINFO_H |
0 commit comments