[llvm] [SPIRV] Implement translation for llvm.modf.* intrinsics (PR #147556)
Victor Lomuller via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 17 06:49:56 PDT 2025
================
@@ -995,4 +995,26 @@ unsigned getArrayComponentCount(const MachineRegisterInfo *MRI,
return foldImm(ResType->getOperand(2), MRI);
}
+MachineBasicBlock::iterator
+getPosForOpVariableWithinBlock(MachineBasicBlock &BB) {
+ // Find the position to insert the OpVariable instruction.
+ // We will insert it after the last OpFunctionParameter, if any, or
+ // after OpFunction otherwise.
+ MachineBasicBlock::iterator VarPos = BB.begin();
+ while (VarPos != BB.end() && VarPos->getOpcode() != SPIRV::OpFunction) {
+ ++VarPos;
+ }
+ // Advance VarPos to the next instruction after OpFunction, it will either
+ // be an OpFunctionParameter, so that we can start the next loop, or the
+ // position to insert the OpVariable instruction.
+ ++VarPos;
+ while (VarPos != BB.end() &&
+ VarPos->getOpcode() == SPIRV::OpFunctionParameter) {
+ ++VarPos;
+ }
+ // VarPos is now pointing at after the last OpFunctionParameter, if any,
+ // or after OpFunction, if no parameters.
+ return VarPos;
----------------
Naghasan wrote:
```suggestion
return VarPos != BB.end() && VarPos->getOpcode() == SPIRV::OpLabel ? ++VarPos : VarPos;
```
https://github.com/llvm/llvm-project/pull/147556
More information about the llvm-commits
mailing list