about summary refs log tree commit diff
path: root/src/rustllvm/PassWrapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rustllvm/PassWrapper.cpp')
-rw-r--r--src/rustllvm/PassWrapper.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp
index 2c0240eb8f9..6513fdfd2f2 100644
--- a/src/rustllvm/PassWrapper.cpp
+++ b/src/rustllvm/PassWrapper.cpp
@@ -21,6 +21,8 @@
 #else
 #include "llvm/Target/TargetLibraryInfo.h"
 #endif
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetSubtargetInfo.h"
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
 
 
@@ -327,3 +329,28 @@ LLVMRustMarkAllFunctionsNounwind(LLVMModuleRef M) {
         }
     }
 }
+
+extern "C" void
+LLVMRustSetDataLayoutFromTargetMachine(LLVMModuleRef Module,
+                                       LLVMTargetMachineRef TMR) {
+    TargetMachine *Target = unwrap(TMR);
+#if LLVM_VERSION_MINOR >= 7
+    if (const DataLayout *DL = Target->getDataLayout())
+        unwrap(Module)->setDataLayout(*DL);
+#elif LLVM_VERSION_MINOR >= 6
+    if (const DataLayout *DL = Target->getSubtargetImpl()->getDataLayout())
+        unwrap(Module)->setDataLayout(DL);
+#else
+    if (const DataLayout *DL = Target->getDataLayout())
+        unwrap(Module)->setDataLayout(DL);
+#endif
+}
+
+extern "C" LLVMTargetDataRef
+LLVMRustGetModuleDataLayout(LLVMModuleRef M) {
+#if LLVM_VERSION_MINOR >= 7
+    return wrap(&unwrap(M)->getDataLayout());
+#else
+    return wrap(unwrap(M)->getDataLayout());
+#endif
+}