Skip to content

Commit 27bebc1

Browse files
authored
[GISel] Unify multiple instances of getTypeForLLT (NFC) (#95577)
Multiple static instances of this utility function have been found in different GlobalISel files. Unifying them by adding an instance in utils.cpp.
1 parent 47f8b85 commit 27bebc1

File tree

5 files changed

+11
-23
lines changed

5 files changed

+11
-23
lines changed

llvm/include/llvm/CodeGen/GlobalISel/Utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,5 +585,9 @@ bool isGuaranteedNotToBePoison(Register Reg, const MachineRegisterInfo &MRI,
585585
bool isGuaranteedNotToBeUndef(Register Reg, const MachineRegisterInfo &MRI,
586586
unsigned Depth = 0);
587587

588+
/// Get the type back from LLT. It won't be 100 percent accurate but returns an
589+
/// estimate of the type.
590+
Type *getTypeForLLT(LLT Ty, LLVMContext &C);
591+
588592
} // End namespace llvm.
589593
#endif

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,13 +1099,6 @@ void CombinerHelper::applySextInRegOfLoad(
10991099
MI.eraseFromParent();
11001100
}
11011101

1102-
static Type *getTypeForLLT(LLT Ty, LLVMContext &C) {
1103-
if (Ty.isVector())
1104-
return FixedVectorType::get(IntegerType::get(C, Ty.getScalarSizeInBits()),
1105-
Ty.getNumElements());
1106-
return IntegerType::get(C, Ty.getSizeInBits());
1107-
}
1108-
11091102
/// Return true if 'MI' is a load or a store that may be fold it's address
11101103
/// operand into the load / store addressing mode.
11111104
static bool canFoldInAddressingMode(GLoadStore *MI, const TargetLowering &TLI,

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8392,8 +8392,6 @@ LegalizerHelper::lowerVectorReduction(MachineInstr &MI) {
83928392
return UnableToLegalize;
83938393
}
83948394

8395-
static Type *getTypeForLLT(LLT Ty, LLVMContext &C);
8396-
83978395
LegalizerHelper::LegalizeResult LegalizerHelper::lowerVAArg(MachineInstr &MI) {
83988396
MachineFunction &MF = *MI.getMF();
83998397
const DataLayout &DL = MIRBuilder.getDataLayout();
@@ -8517,13 +8515,6 @@ static bool findGISelOptimalMemOpLowering(std::vector<LLT> &MemOps,
85178515
return true;
85188516
}
85198517

8520-
static Type *getTypeForLLT(LLT Ty, LLVMContext &C) {
8521-
if (Ty.isVector())
8522-
return FixedVectorType::get(IntegerType::get(C, Ty.getScalarSizeInBits()),
8523-
Ty.getNumElements());
8524-
return IntegerType::get(C, Ty.getSizeInBits());
8525-
}
8526-
85278518
// Get a vectorized representation of the memset value operand, GISel edition.
85288519
static Register getMemsetValue(Register Val, LLT Ty, MachineIRBuilder &MIB) {
85298520
MachineRegisterInfo &MRI = *MIB.getMRI();

llvm/lib/CodeGen/GlobalISel/Utils.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,3 +1906,10 @@ bool llvm::isGuaranteedNotToBeUndef(Register Reg,
19061906
return ::isGuaranteedNotToBeUndefOrPoison(Reg, MRI, Depth,
19071907
UndefPoisonKind::UndefOnly);
19081908
}
1909+
1910+
Type *llvm::getTypeForLLT(LLT Ty, LLVMContext &C) {
1911+
if (Ty.isVector())
1912+
return VectorType::get(IntegerType::get(C, Ty.getScalarSizeInBits()),
1913+
Ty.getElementCount());
1914+
return IntegerType::get(C, Ty.getSizeInBits());
1915+
}

llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -462,13 +462,6 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
462462
getLegacyLegalizerInfo().computeTables();
463463
}
464464

465-
static Type *getTypeForLLT(LLT Ty, LLVMContext &C) {
466-
if (Ty.isVector())
467-
return FixedVectorType::get(IntegerType::get(C, Ty.getScalarSizeInBits()),
468-
Ty.getNumElements());
469-
return IntegerType::get(C, Ty.getSizeInBits());
470-
}
471-
472465
bool RISCVLegalizerInfo::legalizeIntrinsic(LegalizerHelper &Helper,
473466
MachineInstr &MI) const {
474467
Intrinsic::ID IntrinsicID = cast<GIntrinsic>(MI).getIntrinsicID();

0 commit comments

Comments
 (0)