diff options
Diffstat (limited to 'llvm/lib/Target/SPIRV/SPIRVUtils.cpp')
-rw-r--r-- | llvm/lib/Target/SPIRV/SPIRVUtils.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp index 768efb9..416d811 100644 --- a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp @@ -995,4 +995,27 @@ unsigned getArrayComponentCount(const MachineRegisterInfo *MRI, return foldImm(ResType->getOperand(2), MRI); } +MachineBasicBlock::iterator +getFirstValidInstructionInsertPoint(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 != BB.end() && VarPos->getOpcode() == SPIRV::OpLabel ? ++VarPos + : VarPos; +} + } // namespace llvm |