xref: /freebsd-src/contrib/llvm-project/llvm/lib/Target/NVPTX/NVPTXSubtarget.h (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
10b57cec5SDimitry Andric //=====-- NVPTXSubtarget.h - Define Subtarget for the NVPTX ---*- C++ -*--====//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file declares the NVPTX specific subclass of TargetSubtarget.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_NVPTX_NVPTXSUBTARGET_H
140b57cec5SDimitry Andric #define LLVM_LIB_TARGET_NVPTX_NVPTXSUBTARGET_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "NVPTX.h"
170b57cec5SDimitry Andric #include "NVPTXFrameLowering.h"
180b57cec5SDimitry Andric #include "NVPTXISelLowering.h"
190b57cec5SDimitry Andric #include "NVPTXInstrInfo.h"
200b57cec5SDimitry Andric #include "NVPTXRegisterInfo.h"
210b57cec5SDimitry Andric #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
220b57cec5SDimitry Andric #include "llvm/CodeGen/TargetSubtargetInfo.h"
230b57cec5SDimitry Andric #include "llvm/IR/DataLayout.h"
240b57cec5SDimitry Andric #include <string>
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric #define GET_SUBTARGETINFO_HEADER
270b57cec5SDimitry Andric #include "NVPTXGenSubtargetInfo.inc"
280b57cec5SDimitry Andric 
290b57cec5SDimitry Andric namespace llvm {
300b57cec5SDimitry Andric 
310b57cec5SDimitry Andric class NVPTXSubtarget : public NVPTXGenSubtargetInfo {
320b57cec5SDimitry Andric   virtual void anchor();
330b57cec5SDimitry Andric   std::string TargetName;
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric   // PTX version x.y is represented as 10*x+y, e.g. 3.1 == 31
360b57cec5SDimitry Andric   unsigned PTXVersion;
370b57cec5SDimitry Andric 
38*5f757f3fSDimitry Andric   // Full SM version x.y is represented as 100*x+10*y+feature, e.g. 3.1 == 310
39*5f757f3fSDimitry Andric   // sm_90a == 901
40*5f757f3fSDimitry Andric   unsigned int FullSmVersion;
41*5f757f3fSDimitry Andric 
42*5f757f3fSDimitry Andric   // SM version x.y is represented as 10*x+y, e.g. 3.1 == 31. Derived from
43*5f757f3fSDimitry Andric   // FullSmVersion.
440b57cec5SDimitry Andric   unsigned int SmVersion;
450b57cec5SDimitry Andric 
460b57cec5SDimitry Andric   const NVPTXTargetMachine &TM;
470b57cec5SDimitry Andric   NVPTXInstrInfo InstrInfo;
480b57cec5SDimitry Andric   NVPTXTargetLowering TLInfo;
490b57cec5SDimitry Andric   SelectionDAGTargetInfo TSInfo;
500b57cec5SDimitry Andric 
510b57cec5SDimitry Andric   // NVPTX does not have any call stack frame, but need a NVPTX specific
520b57cec5SDimitry Andric   // FrameLowering class because TargetFrameLowering is abstract.
530b57cec5SDimitry Andric   NVPTXFrameLowering FrameLowering;
540b57cec5SDimitry Andric 
550b57cec5SDimitry Andric public:
560b57cec5SDimitry Andric   /// This constructor initializes the data members to match that
570b57cec5SDimitry Andric   /// of the specified module.
580b57cec5SDimitry Andric   ///
590b57cec5SDimitry Andric   NVPTXSubtarget(const Triple &TT, const std::string &CPU,
600b57cec5SDimitry Andric                  const std::string &FS, const NVPTXTargetMachine &TM);
610b57cec5SDimitry Andric 
getFrameLowering()620b57cec5SDimitry Andric   const TargetFrameLowering *getFrameLowering() const override {
630b57cec5SDimitry Andric     return &FrameLowering;
640b57cec5SDimitry Andric   }
getInstrInfo()650b57cec5SDimitry Andric   const NVPTXInstrInfo *getInstrInfo() const override { return &InstrInfo; }
getRegisterInfo()660b57cec5SDimitry Andric   const NVPTXRegisterInfo *getRegisterInfo() const override {
670b57cec5SDimitry Andric     return &InstrInfo.getRegisterInfo();
680b57cec5SDimitry Andric   }
getTargetLowering()690b57cec5SDimitry Andric   const NVPTXTargetLowering *getTargetLowering() const override {
700b57cec5SDimitry Andric     return &TLInfo;
710b57cec5SDimitry Andric   }
getSelectionDAGInfo()720b57cec5SDimitry Andric   const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
730b57cec5SDimitry Andric     return &TSInfo;
740b57cec5SDimitry Andric   }
750b57cec5SDimitry Andric 
hasAtomAddF64()760b57cec5SDimitry Andric   bool hasAtomAddF64() const { return SmVersion >= 60; }
hasAtomScope()770b57cec5SDimitry Andric   bool hasAtomScope() const { return SmVersion >= 60; }
hasAtomBitwise64()780b57cec5SDimitry Andric   bool hasAtomBitwise64() const { return SmVersion >= 32; }
hasAtomMinMax64()790b57cec5SDimitry Andric   bool hasAtomMinMax64() const { return SmVersion >= 32; }
hasLDG()800b57cec5SDimitry Andric   bool hasLDG() const { return SmVersion >= 32; }
hasHWROT32()810b57cec5SDimitry Andric   inline bool hasHWROT32() const { return SmVersion >= 32; }
820b57cec5SDimitry Andric   bool hasImageHandles() const;
hasFP16Math()830b57cec5SDimitry Andric   bool hasFP16Math() const { return SmVersion >= 53; }
hasBF16Math()8406c3fb27SDimitry Andric   bool hasBF16Math() const { return SmVersion >= 80; }
850b57cec5SDimitry Andric   bool allowFP16Math() const;
hasMaskOperator()86fcaf7f86SDimitry Andric   bool hasMaskOperator() const { return PTXVersion >= 71; }
hasNoReturn()87bdd1243dSDimitry Andric   bool hasNoReturn() const { return SmVersion >= 30 && PTXVersion >= 64; }
getFullSmVersion()88*5f757f3fSDimitry Andric   unsigned int getFullSmVersion() const { return FullSmVersion; }
getSmVersion()89*5f757f3fSDimitry Andric   unsigned int getSmVersion() const { return getFullSmVersion() / 10; }
90*5f757f3fSDimitry Andric   // GPUs with "a" suffix have include architecture-accelerated features that
91*5f757f3fSDimitry Andric   // are supported on the specified architecture only, hence such targets do not
92*5f757f3fSDimitry Andric   // follow the onion layer model. hasAAFeatures() allows distinguishing such
93*5f757f3fSDimitry Andric   // GPU variants from the base GPU architecture.
94*5f757f3fSDimitry Andric   // - 0 represents base GPU model,
95*5f757f3fSDimitry Andric   // - non-zero value identifies particular architecture-accelerated variant.
hasAAFeatures()96*5f757f3fSDimitry Andric   bool hasAAFeatures() const { return getFullSmVersion() % 10; }
getTargetName()970b57cec5SDimitry Andric   std::string getTargetName() const { return TargetName; }
980b57cec5SDimitry Andric 
99bdd1243dSDimitry Andric   // Get maximum value of required alignments among the supported data types.
100bdd1243dSDimitry Andric   // From the PTX ISA doc, section 8.2.3:
101bdd1243dSDimitry Andric   //  The memory consistency model relates operations executed on memory
102bdd1243dSDimitry Andric   //  locations with scalar data-types, which have a maximum size and alignment
103bdd1243dSDimitry Andric   //  of 64 bits. Memory operations with a vector data-type are modelled as a
104bdd1243dSDimitry Andric   //  set of equivalent memory operations with a scalar data-type, executed in
105bdd1243dSDimitry Andric   //  an unspecified order on the elements in the vector.
getMaxRequiredAlignment()106bdd1243dSDimitry Andric   unsigned getMaxRequiredAlignment() const { return 8; }
107bdd1243dSDimitry Andric 
getPTXVersion()1080b57cec5SDimitry Andric   unsigned getPTXVersion() const { return PTXVersion; }
1090b57cec5SDimitry Andric 
1100b57cec5SDimitry Andric   NVPTXSubtarget &initializeSubtargetDependencies(StringRef CPU, StringRef FS);
111e8d8bef9SDimitry Andric   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
1120b57cec5SDimitry Andric };
1130b57cec5SDimitry Andric 
1140b57cec5SDimitry Andric } // End llvm namespace
1150b57cec5SDimitry Andric 
1160b57cec5SDimitry Andric #endif
117