llvm-project/llvm/lib/CodeGen/GlobalISel/LegalizeMutations.cpp
Denis.G b1aa6a4506
[GlobalISel][LLT] Introduce FPInfo for LLT (Enable bfloat, ppc128float and others in GlobalISel) (#155107)
Added extra information in LLT to support ambiguous fp types during
GlobalISel. Original idea by @tgymnich

Main differences from https://github.com/llvm/llvm-project/pull/122503
are:
* Do not deprecate LLT::scalar
* Allow targets to enable/disable IR translation with extenden LLT via
`TargetOption::EnableGlobalISelExtendedLLT` (disabled by default)
* `IRTranslator` use `TargetLoweringInfo` for appropriate `LLT`
generation.
* For this reason added flag in GlobalISelMatchTable` to allow switch
between legacy and new extended LLT names
* Revert using stubs like `LLT::float32` for float types as they are
real now. Added `TODO` for such cases.

Also MIRParser now may parse new type indentifiers.

---------

Co-authored-by: Tim Gymnich <tim@gymni.ch>
Co-authored-by: Ryan Cowan <ryan.cowan@arm.com>
2026-03-24 08:40:39 -04:00

120 lines
4.6 KiB
C++

//===- lib/CodeGen/GlobalISel/LegalizerMutations.cpp - Mutations ----------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// A library of mutation factories to use for LegalityMutation.
//
//===----------------------------------------------------------------------===//
#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
using namespace llvm;
LegalizeMutation LegalizeMutations::changeTo(unsigned TypeIdx, LLT Ty) {
return
[=](const LegalityQuery &Query) { return std::make_pair(TypeIdx, Ty); };
}
LegalizeMutation LegalizeMutations::changeTo(unsigned TypeIdx,
unsigned FromTypeIdx) {
return [=](const LegalityQuery &Query) {
return std::make_pair(TypeIdx, Query.Types[FromTypeIdx]);
};
}
LegalizeMutation LegalizeMutations::changeElementTo(unsigned TypeIdx,
unsigned FromTypeIdx) {
return [=](const LegalityQuery &Query) {
const LLT OldTy = Query.Types[TypeIdx];
const LLT NewTy = Query.Types[FromTypeIdx];
return std::make_pair(TypeIdx, OldTy.changeElementType(NewTy));
};
}
LegalizeMutation LegalizeMutations::changeElementTo(unsigned TypeIdx,
LLT NewEltTy) {
return [=](const LegalityQuery &Query) {
const LLT OldTy = Query.Types[TypeIdx];
return std::make_pair(TypeIdx, OldTy.changeElementType(NewEltTy));
};
}
LegalizeMutation LegalizeMutations::changeElementCountTo(unsigned TypeIdx,
unsigned FromTypeIdx) {
return [=](const LegalityQuery &Query) {
const LLT OldTy = Query.Types[TypeIdx];
const LLT NewTy = Query.Types[FromTypeIdx];
ElementCount NewEltCount =
NewTy.isVector() ? NewTy.getElementCount() : ElementCount::getFixed(1);
return std::make_pair(TypeIdx, OldTy.changeElementCount(NewEltCount));
};
}
LegalizeMutation LegalizeMutations::changeElementCountTo(unsigned TypeIdx,
ElementCount EC) {
return [=](const LegalityQuery &Query) {
const LLT OldTy = Query.Types[TypeIdx];
return std::make_pair(TypeIdx, OldTy.changeElementCount(EC));
};
}
LegalizeMutation LegalizeMutations::changeElementSizeTo(unsigned TypeIdx,
unsigned FromTypeIdx) {
return [=](const LegalityQuery &Query) {
const LLT OldTy = Query.Types[TypeIdx];
const LLT NewTy = Query.Types[FromTypeIdx];
return std::make_pair(TypeIdx,
OldTy.changeElementSize(NewTy.getScalarSizeInBits()));
};
}
LegalizeMutation LegalizeMutations::changeElementSizeTo(unsigned TypeIdx,
LLT NewTy) {
return [=](const LegalityQuery &Query) {
const LLT OldTy = Query.Types[TypeIdx];
return std::make_pair(TypeIdx,
OldTy.changeElementSize(NewTy.getScalarSizeInBits()));
};
}
LegalizeMutation LegalizeMutations::widenScalarOrEltToNextPow2(unsigned TypeIdx,
unsigned Min) {
return [=](const LegalityQuery &Query) {
const LLT Ty = Query.Types[TypeIdx];
unsigned NewEltSizeInBits =
std::max(1u << Log2_32_Ceil(Ty.getScalarSizeInBits()), Min);
return std::make_pair(TypeIdx, Ty.changeElementSize(NewEltSizeInBits));
};
}
LegalizeMutation
LegalizeMutations::widenScalarOrEltToNextMultipleOf(unsigned TypeIdx,
unsigned Size) {
return [=](const LegalityQuery &Query) {
const LLT Ty = Query.Types[TypeIdx];
unsigned NewEltSizeInBits = alignTo(Ty.getScalarSizeInBits(), Size);
return std::make_pair(TypeIdx, Ty.changeElementSize(NewEltSizeInBits));
};
}
LegalizeMutation LegalizeMutations::moreElementsToNextPow2(unsigned TypeIdx,
unsigned Min) {
return [=](const LegalityQuery &Query) {
const LLT VecTy = Query.Types[TypeIdx];
unsigned NewNumElements =
std::max(1u << Log2_32_Ceil(VecTy.getNumElements()), Min);
return std::make_pair(
TypeIdx, LLT::fixed_vector(NewNumElements, VecTy.getElementType()));
};
}
LegalizeMutation LegalizeMutations::scalarize(unsigned TypeIdx) {
return [=](const LegalityQuery &Query) {
return std::make_pair(TypeIdx, Query.Types[TypeIdx].getElementType());
};
}