Trace Abstraction Based on Automatic Detection of Execution Phases