One long-term goal for research on probabilistic programming languages (PPLs) is efficient inference using a single, generic inference engine. Many current inference engines are, however, interpreters for the given PP, leading to substantial overhead and poor performance. This paper describes a PPL compiler, SWIFT, that generates model-specific and inference-algorithm-specific target code from a given PP in the BLOG language, in much the same way that a Prolog compiler generates code that performs backward-chaining logical inference for a specific Prolog program. This approach eliminates a great deal of interpretation overhead. We evaluate the performance of SWIFT and existing systems such as BLOG, BUGS, Church, Stan, and infer.net on several benchmark problems. In our experiments, SWIFT's compiled code runs 100x faster than the original BLOG engine, and much faster than other systems on the same models.