Replace "concept based polymorphism" with simpler PImpl idiom. This pursues two goals: * Enforce static type checking. Previously, target implementations hid base class methods and type checking was impossible. Now that they override the methods, the compiler will complain on mismatched signatures. * Make the code easier to navigate. Previously, if you asked your favorite LSP server to show a method (e.g. `getInstructionCost()`), it would show you methods from `TTI`, `TTI::Concept`, `TTI::Model`, `TTIImplBase`, and target overrides. Now it is two less :) There are three commits to hopefully simplify the review. The first commit removes `TTI::Model`. This is done by deriving `TargetTransformInfoImplBase` from `TTI::Concept`. This is possible because they implement the same set of interfaces with identical signatures. The first commit makes `TargetTransformImplBase` polymorphic, which means all derived classes should `override` its methods. This is done in second commit to make the first one smaller. It appeared infeasible to extract this into a separate PR because the first commit landed separately would result in tons of `-Woverloaded-virtual` warnings (and break `-Werror` builds). The third commit eliminates `TTI::Concept` by merging it with the only derived class `TargetTransformImplBase`. This commit could be extracted into a separate PR, but it touches the same lines in `TargetTransformInfoImpl.h` (removes `override` added by the second commit and adds `virtual`), so I thought it may make sense to land these two commits together. Pull Request: https://github.com/llvm/llvm-project/pull/136674
56 lines
2.1 KiB
C++
56 lines
2.1 KiB
C++
//===- SPIRVTargetTransformInfo.h - SPIR-V specific TTI ---------*- 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
// \file
|
|
// This file contains a TargetTransformInfoImplBase conforming object specific
|
|
// to the SPIRV target machine. It uses the target's detailed information to
|
|
// provide more precise answers to certain TTI queries, while letting the
|
|
// target independent and default TTI implementations handle the rest.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVTARGETTRANSFORMINFO_H
|
|
#define LLVM_LIB_TARGET_SPIRV_SPIRVTARGETTRANSFORMINFO_H
|
|
|
|
#include "SPIRV.h"
|
|
#include "SPIRVTargetMachine.h"
|
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
|
#include "llvm/CodeGen/BasicTTIImpl.h"
|
|
|
|
namespace llvm {
|
|
class SPIRVTTIImpl : public BasicTTIImplBase<SPIRVTTIImpl> {
|
|
using BaseT = BasicTTIImplBase<SPIRVTTIImpl>;
|
|
using TTI = TargetTransformInfo;
|
|
|
|
friend BaseT;
|
|
|
|
const SPIRVSubtarget *ST;
|
|
const SPIRVTargetLowering *TLI;
|
|
|
|
const TargetSubtargetInfo *getST() const { return ST; }
|
|
const SPIRVTargetLowering *getTLI() const { return TLI; }
|
|
|
|
public:
|
|
explicit SPIRVTTIImpl(const SPIRVTargetMachine *TM, const Function &F)
|
|
: BaseT(TM, F.getDataLayout()), ST(TM->getSubtargetImpl(F)),
|
|
TLI(ST->getTargetLowering()) {}
|
|
|
|
TTI::PopcntSupportKind getPopcntSupport(unsigned TyWidth) const override {
|
|
// SPIR-V natively supports OpBitcount, per 3.53.14 in the spec, as such it
|
|
// is reasonable to assume the Op is fast / preferable to the expanded loop.
|
|
// Furthermore, this prevents information being lost if transforms are
|
|
// applied to SPIR-V before lowering to a concrete target.
|
|
if (!isPowerOf2_32(TyWidth) || TyWidth > 64)
|
|
return TTI::PSK_Software; // Arbitrary bit-width INT is not core SPIR-V.
|
|
return TTI::PSK_FastHardware;
|
|
}
|
|
};
|
|
|
|
} // namespace llvm
|
|
|
|
#endif // LLVM_LIB_TARGET_SPIRV_SPIRVTARGETTRANSFORMINFO_H
|