|
12 | 12 |
|
13 | 13 | #include "llvm/Analysis/VectorUtils.h"
|
14 | 14 | #include "llvm/ADT/EquivalenceClasses.h"
|
| 15 | +#include "llvm/ADT/SmallVector.h" |
15 | 16 | #include "llvm/Analysis/DemandedBits.h"
|
16 | 17 | #include "llvm/Analysis/LoopInfo.h"
|
17 | 18 | #include "llvm/Analysis/LoopIterator.h"
|
|
24 | 25 | #include "llvm/IR/PatternMatch.h"
|
25 | 26 | #include "llvm/IR/Value.h"
|
26 | 27 | #include "llvm/Support/CommandLine.h"
|
| 28 | +#include <optional> |
27 | 29 |
|
28 | 30 | #define DEBUG_TYPE "vectorutils"
|
29 | 31 |
|
@@ -1477,6 +1479,49 @@ void VFABI::getVectorVariantNames(
|
1477 | 1479 | }
|
1478 | 1480 | }
|
1479 | 1481 |
|
| 1482 | +// Returns whether any of the operands or return type of \p I are vectors. |
| 1483 | +static bool isVectorized(const Instruction *I) { |
| 1484 | + if (I->getType()->isVectorTy()) |
| 1485 | + return true; |
| 1486 | + for (auto &U : I->operands()) |
| 1487 | + if (U->getType()->isVectorTy()) |
| 1488 | + return true; |
| 1489 | + return false; |
| 1490 | +} |
| 1491 | + |
| 1492 | +std::optional<std::pair<FunctionType *, int>> |
| 1493 | +VFABI::createFunctionType(const VFInfo &Info, const Instruction *I, |
| 1494 | + const Module *M) { |
| 1495 | + // only vectorized calls should reach this method |
| 1496 | + if (!isVectorized(I)) |
| 1497 | + return std::nullopt; |
| 1498 | + |
| 1499 | + ElementCount VF = Info.Shape.VF; |
| 1500 | + // get vectorized operands |
| 1501 | + const bool IsCall = isa<CallBase>(I); |
| 1502 | + SmallVector<Type *, 8> VecParams; |
| 1503 | + for (auto [i, U] : enumerate(I->operands())) { |
| 1504 | + // ignore the function pointer when the Instruction is a call |
| 1505 | + if (IsCall && i == I->getNumOperands() - 1) |
| 1506 | + break; |
| 1507 | + VecParams.push_back(U->getType()); |
| 1508 | + } |
| 1509 | + |
| 1510 | + // Append a mask and get its position. |
| 1511 | + int MaskPos = -1; |
| 1512 | + if (Info.isMasked()) { |
| 1513 | + auto OptMaskPos = Info.getParamIndexForOptionalMask(); |
| 1514 | + if (!OptMaskPos) |
| 1515 | + return std::nullopt; |
| 1516 | + |
| 1517 | + MaskPos = OptMaskPos.value(); |
| 1518 | + VectorType *MaskTy = VectorType::get(Type::getInt1Ty(M->getContext()), VF); |
| 1519 | + VecParams.insert(VecParams.begin() + MaskPos, MaskTy); |
| 1520 | + } |
| 1521 | + FunctionType *VecFTy = FunctionType::get(I->getType(), VecParams, false); |
| 1522 | + return std::make_pair(VecFTy, MaskPos); |
| 1523 | +} |
| 1524 | + |
1480 | 1525 | bool VFShape::hasValidParameterList() const {
|
1481 | 1526 | for (unsigned Pos = 0, NumParams = Parameters.size(); Pos < NumParams;
|
1482 | 1527 | ++Pos) {
|
|
0 commit comments