1515#include " llvm/Support/CBindingWrapping.h"
1616#include " llvm/Support/FileSystem.h"
1717#include " llvm/Support/Host.h"
18- #if LLVM_VERSION_MINOR >= 7
1918#include " llvm/Analysis/TargetLibraryInfo.h"
2019#include " llvm/Analysis/TargetTransformInfo.h"
21- #else
22- #include " llvm/Target/TargetLibraryInfo.h"
23- #endif
2420#include " llvm/Target/TargetMachine.h"
2521#include " llvm/Target/TargetSubtargetInfo.h"
2622#include " llvm/Transforms/IPO/PassManagerBuilder.h"
@@ -49,7 +45,7 @@ LLVMInitializePasses() {
4945 initializeVectorization (Registry);
5046 initializeIPO (Registry);
5147 initializeAnalysis (Registry);
52- #if LLVM_VERSION_MINOR < = 7
48+ #if LLVM_VERSION_MINOR = = 7
5349 initializeIPA (Registry);
5450#endif
5551 initializeTransformUtils (Registry);
@@ -223,17 +219,8 @@ LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
223219 LLVMPassManagerRef PMR,
224220 LLVMModuleRef M) {
225221 PassManagerBase *PM = unwrap (PMR);
226- #if LLVM_VERSION_MINOR >= 7
227222 PM->add (createTargetTransformInfoWrapperPass (
228223 unwrap (TM)->getTargetIRAnalysis ()));
229- #else
230- #if LLVM_VERSION_MINOR == 6
231- PM->add (new DataLayoutPass ());
232- #else
233- PM->add (new DataLayoutPass (unwrap (M)));
234- #endif
235- unwrap (TM)->addAnalysisPasses (*PM);
236- #endif
237224}
238225
239226extern " C" void
@@ -242,10 +229,8 @@ LLVMRustConfigurePassManagerBuilder(LLVMPassManagerBuilderRef PMB,
242229 bool MergeFunctions,
243230 bool SLPVectorize,
244231 bool LoopVectorize) {
245- #if LLVM_VERSION_MINOR >= 6
246232 // Ignore mergefunc for now as enabling it causes crashes.
247233 // unwrap(PMB)->MergeFunctions = MergeFunctions;
248- #endif
249234 unwrap (PMB)->SLPVectorize = SLPVectorize;
250235 unwrap (PMB)->OptLevel = OptLevel;
251236 unwrap (PMB)->LoopVectorize = LoopVectorize;
@@ -258,11 +243,7 @@ LLVMRustAddBuilderLibraryInfo(LLVMPassManagerBuilderRef PMB,
258243 LLVMModuleRef M,
259244 bool DisableSimplifyLibCalls) {
260245 Triple TargetTriple (unwrap (M)->getTargetTriple ());
261- #if LLVM_VERSION_MINOR >= 7
262246 TargetLibraryInfoImpl *TLI = new TargetLibraryInfoImpl (TargetTriple);
263- #else
264- TargetLibraryInfo *TLI = new TargetLibraryInfo (TargetTriple);
265- #endif
266247 if (DisableSimplifyLibCalls)
267248 TLI->disableAllFunctions ();
268249 unwrap (PMB)->LibraryInfo = TLI;
@@ -275,17 +256,10 @@ LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB,
275256 LLVMModuleRef M,
276257 bool DisableSimplifyLibCalls) {
277258 Triple TargetTriple (unwrap (M)->getTargetTriple ());
278- #if LLVM_VERSION_MINOR >= 7
279259 TargetLibraryInfoImpl TLII (TargetTriple);
280260 if (DisableSimplifyLibCalls)
281261 TLII.disableAllFunctions ();
282262 unwrap (PMB)->add (new TargetLibraryInfoWrapperPass (TLII));
283- #else
284- TargetLibraryInfo *TLI = new TargetLibraryInfo (TargetTriple);
285- if (DisableSimplifyLibCalls)
286- TLI->disableAllFunctions ();
287- unwrap (PMB)->add (TLI);
288- #endif
289263}
290264
291265// Unfortunately, the LLVM C API doesn't provide an easy way of iterating over
@@ -323,25 +297,16 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target,
323297 PassManager *PM = unwrap<PassManager>(PMR);
324298
325299 std::string ErrorInfo;
326- #if LLVM_VERSION_MINOR >= 6
327300 std::error_code EC;
328301 raw_fd_ostream OS (path, EC, sys::fs::F_None);
329302 if (EC)
330303 ErrorInfo = EC.message ();
331- #else
332- raw_fd_ostream OS (path, ErrorInfo, sys::fs::F_None);
333- #endif
334304 if (ErrorInfo != " " ) {
335305 LLVMRustSetLastError (ErrorInfo.c_str ());
336306 return false ;
337307 }
338308
339- #if LLVM_VERSION_MINOR >= 7
340309 unwrap (Target)->addPassesToEmitFile (*PM, OS, FileType, false );
341- #else
342- formatted_raw_ostream FOS (OS);
343- unwrap (Target)->addPassesToEmitFile (*PM, FOS, FileType, false );
344- #endif
345310 PM->run (*unwrap (M));
346311
347312 // Apparently `addPassesToEmitFile` adds a pointer to our on-the-stack output
@@ -358,14 +323,10 @@ LLVMRustPrintModule(LLVMPassManagerRef PMR,
358323 PassManager *PM = unwrap<PassManager>(PMR);
359324 std::string ErrorInfo;
360325
361- #if LLVM_VERSION_MINOR >= 6
362326 std::error_code EC;
363327 raw_fd_ostream OS (path, EC, sys::fs::F_None);
364328 if (EC)
365329 ErrorInfo = EC.message ();
366- #else
367- raw_fd_ostream OS (path, ErrorInfo, sys::fs::F_None);
368- #endif
369330
370331 formatted_raw_ostream FOS (OS);
371332
@@ -428,22 +389,10 @@ extern "C" void
428389LLVMRustSetDataLayoutFromTargetMachine (LLVMModuleRef Module,
429390 LLVMTargetMachineRef TMR) {
430391 TargetMachine *Target = unwrap (TMR);
431- #if LLVM_VERSION_MINOR >= 7
432392 unwrap (Module)->setDataLayout (Target->createDataLayout ());
433- #elif LLVM_VERSION_MINOR >= 6
434- if (const DataLayout *DL = Target->getSubtargetImpl ()->getDataLayout ())
435- unwrap (Module)->setDataLayout (DL);
436- #else
437- if (const DataLayout *DL = Target->getDataLayout ())
438- unwrap (Module)->setDataLayout (DL);
439- #endif
440393}
441394
442395extern " C" LLVMTargetDataRef
443396LLVMRustGetModuleDataLayout (LLVMModuleRef M) {
444- #if LLVM_VERSION_MINOR >= 7
445397 return wrap (&unwrap (M)->getDataLayout ());
446- #else
447- return wrap (unwrap (M)->getDataLayout ());
448- #endif
449398}
0 commit comments