loop add getOrInsertCycle helper function

Signed-off-by: xiehuc <xiehuc@gmail.com>