Skip to content

Commit

Permalink
[NFC] buildAfter: return IRBuilder<>.
Browse files Browse the repository at this point in the history
In LLVM 19, we will no longer be able to use instruction pointers to
keep track of insertion points. This change prepares for that by making
a helper function that is only ever used to construct an IRBuilder<>
return an IRBuilder<> directly.
  • Loading branch information
hvdijk committed Feb 22, 2024
1 parent 030bd98 commit 012ef86
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ namespace vecz {
class TargetInfo;
struct SimdPacket;

/// @brief Provides the insertion point after the value V. Intended to be used
/// in IRBuilder constructor. If V has a position in the function, (e.g., an
/// Instruction), this method will return the next point after that. If V has
/// no position (e.g., a Constant or an Argument) then this method will return
/// a suitable insertion point at the beginning of the function.
/// @brief Determines the insertion point after the value V. If V has a position
/// in the function, (e.g., an Instruction), this method will return an
/// IRBuilder set to the next point after that. If V has no position (e.g., a
/// Constant or an Argument) then this method will return an IRBuilder set to a
/// suitable insertion point at the beginning of the function.
///
/// @param[in] V Value to insert instructions after, if an llvm::Instruction.
/// @param[in] F Function to insert instructions into, if V is not an
/// llvm::Instruction.
/// @param[in] IsPhi true if the instructions to insert are phis, false if the
/// insertion point should be after all phis in the basic block.
///
/// @return Insertion Point.
llvm::Instruction *buildAfter(llvm::Value *V, llvm::Function &F,
bool IsPhi = false);
/// @return IRBuilder set to a suitable insertion point.
llvm::IRBuilder<> buildAfter(llvm::Value *V, llvm::Function &F,
bool IsPhi = false);

/// @brief Utility function for building a shufflevector instruction, absorbing
/// its operands where possible.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,22 @@ Value *createFixedBroadcastOfScalableVector(const vecz::TargetInfo &TI,
} // namespace

namespace vecz {
Instruction *buildAfter(Value *V, Function &F, bool IsPhi) {
IRBuilder<> buildAfter(Value *V, Function &F, bool IsPhi) {
if (auto *const I = dyn_cast<Instruction>(V)) {
BasicBlock::iterator Next = I->getIterator();
const BasicBlock::iterator End = Next->getParent()->end();
do {
++Next;
} while (!IsPhi && (Next != End) &&
(isa<PHINode>(Next) || isa<AllocaInst>(Next)));
return &*Next;
return {I->getParent(), Next};
}
// Else find the first point in the function after any allocas.
auto it = F.getEntryBlock().begin();
while (isa<AllocaInst>(*it)) {
++it;
}
return &*it;
return {&F.getEntryBlock(), it};
}

Constant *getShuffleMask(ShuffleVectorInst *shuffle) {
Expand Down
8 changes: 7 additions & 1 deletion modules/compiler/vecz/source/transform/packetizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1935,7 +1935,13 @@ Value *Packetizer::Impl::packetizeMaskVarying(Instruction *I) {
// pressure, and to make it easier for CSE/GVN to combine them if there
// are multiple uses of the same value (we could cache these?)
auto *maskInst = dyn_cast<Instruction>(vecMask);
IRBuilder<> B(maskInst ? buildAfter(maskInst, F) : I);
IRBuilder<> B = [&] {
if (maskInst) {
return buildAfter(maskInst, F);
} else {
return IRBuilder<>(I);
}
}();

Value *anyOfMask =
createMaybeVPTargetReduction(B, TTI, vecMask, RecurKind::Or, VL);
Expand Down

0 comments on commit 012ef86

Please sign in to comment.