Different roles of trap states in semiconductors for solar energy conversion