The Swift compiler uses files with an extension of ".swiftdeps" to store information about cross-file dependencies within a single module, plus an extra "swiftdeps" file for the "build record" (information about the whole compilation). These files are read in at the start of compilation to compute a dependency graph, and updated (and re-read) as compilation proceeds. However, because these files are updated on every build, an issue with dependency analysis is hard to reproduce—the inputs have been lost.
A simple answer for this that will help in the common case is to move the previous swiftdeps file aside just before writing the new one. I'd suggest just renaming them from "foo.swiftdeps" to "foo.swiftdeps~". If this fails for any reason, just ignore the failure and continue on. (Maybe the directory isn't writable, only the one file. Maybe this is the first build. Maybe the user write-protected the previous "foo.swiftdeps~" for some reason.)
The LLVM APIs to mess with the filesystem are in "llvm/Support/FileSystem.h"; the one I'd expect to use is llvm::sys::fs::rename.