LLVM 19.0.0git
LoongArchTargetTransformInfo.cpp
Go to the documentation of this file.
1//===-- LoongArchTargetTransformInfo.cpp - LoongArch specific TTI ---------===//
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/// \file
9/// This file implements a TargetTransformInfo analysis pass specific to the
10/// LoongArch target machine. It uses the target's detailed information to
11/// provide more precise answers to certain TTI queries, while letting the
12/// target independent and default TTI implementations handle the rest.
13///
14//===----------------------------------------------------------------------===//
15
17
18using namespace llvm;
19
20#define DEBUG_TYPE "loongarchtti"
21
25 switch (K) {
27 return TypeSize::getFixed(ST->is64Bit() ? 64 : 32);
29 if (!ST->hasExpAutoVec())
30 return DefSize;
31 if (ST->hasExtLASX())
32 return TypeSize::getFixed(256);
33 if (ST->hasExtLSX())
34 return TypeSize::getFixed(128);
35 [[fallthrough]];
37 return DefSize;
38 }
39
40 llvm_unreachable("Unsupported register kind");
41}
42
43unsigned LoongArchTTIImpl::getNumberOfRegisters(unsigned ClassID) const {
44 switch (ClassID) {
45 case LoongArchRegisterClass::GPRRC:
46 // 30 = 32 GPRs - r0 (zero register) - r21 (non-allocatable)
47 return 30;
48 case LoongArchRegisterClass::FPRRC:
49 return ST->hasBasicF() ? 32 : 0;
50 case LoongArchRegisterClass::VRRC:
51 return ST->hasExtLSX() ? 32 : 0;
52 }
53 llvm_unreachable("unknown register class");
54}
55
57 Type *Ty) const {
58 if (Vector)
59 return LoongArchRegisterClass::VRRC;
60 if (!Ty)
61 return LoongArchRegisterClass::GPRRC;
62
63 Type *ScalarTy = Ty->getScalarType();
64 if ((ScalarTy->isFloatTy() && ST->hasBasicF()) ||
65 (ScalarTy->isDoubleTy() && ST->hasBasicD())) {
66 return LoongArchRegisterClass::FPRRC;
67 }
68
69 return LoongArchRegisterClass::GPRRC;
70}
71
72const char *LoongArchTTIImpl::getRegisterClassName(unsigned ClassID) const {
73 switch (ClassID) {
74 case LoongArchRegisterClass::GPRRC:
75 return "LoongArch::GPRRC";
76 case LoongArchRegisterClass::FPRRC:
77 return "LoongArch::FPRRC";
78 case LoongArchRegisterClass::VRRC:
79 return "LoongArch::VRRC";
80 }
81 llvm_unreachable("unknown register class");
82}
83
84// TODO: Implement more hooks to provide TTI machinery for LoongArch.
This file a TargetTransformInfo::Concept conforming object specific to the LoongArch target machine.
unsigned getRegisterClassForType(bool Vector, Type *Ty=nullptr) const
unsigned getNumberOfRegisters(unsigned ClassID) const
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const
const char * getRegisterClassName(unsigned ClassID) const
TypeSize getRegisterBitWidth(TargetTransformInfo::RegisterKind K) const
static constexpr TypeSize getFixed(ScalarTy ExactSize)
Definition: TypeSize.h:330
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
Definition: Type.h:154
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
Definition: Type.h:157
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Definition: Type.h:348
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18