summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm-c/Target.h14
-rw-r--r--llvm/include/llvm-c/TargetMachine.h3
-rw-r--r--llvm/lib/Target/Target.cpp8
-rw-r--r--llvm/lib/Target/TargetMachineC.cpp4
-rw-r--r--llvm/test/Bindings/llvm-c/echo.ll3
-rw-r--r--llvm/tools/llvm-c-test/echo.cpp6
6 files changed, 38 insertions, 0 deletions
diff --git a/llvm/include/llvm-c/Target.h b/llvm/include/llvm-c/Target.h
index 2b969e24a18..f2a2b18cc05 100644
--- a/llvm/include/llvm-c/Target.h
+++ b/llvm/include/llvm-c/Target.h
@@ -183,6 +183,20 @@ static inline LLVMBool LLVMInitializeNativeDisassembler(void) {
/*===-- Target Data -------------------------------------------------------===*/
+/**
+ * Obtain the data layout for a module.
+ *
+ * @see Module::getDataLayout()
+ */
+LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);
+
+/**
+ * Set the data layout for a module.
+ *
+ * @see Module::setDataLayout()
+ */
+void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);
+
/** Creates target data from a target layout string.
See the constructor llvm::DataLayout::DataLayout. */
LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep);
diff --git a/llvm/include/llvm-c/TargetMachine.h b/llvm/include/llvm-c/TargetMachine.h
index e6c34dd2953..1d1f61f1a5b 100644
--- a/llvm/include/llvm-c/TargetMachine.h
+++ b/llvm/include/llvm-c/TargetMachine.h
@@ -115,6 +115,9 @@ char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T);
LLVMDisposeMessage. */
char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);
+/** Create a DataLayout based on the targetMachine. */
+LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T);
+
/** Set the target machine's ASM verbosity. */
void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
LLVMBool VerboseAsm);
diff --git a/llvm/lib/Target/Target.cpp b/llvm/lib/Target/Target.cpp
index 51d30679b52..93eab09fb85 100644
--- a/llvm/lib/Target/Target.cpp
+++ b/llvm/lib/Target/Target.cpp
@@ -42,6 +42,14 @@ void LLVMInitializeTarget(LLVMPassRegistryRef R) {
initializeTarget(*unwrap(R));
}
+LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M) {
+ return wrap(&unwrap(M)->getDataLayout());
+}
+
+void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL) {
+ unwrap(M)->setDataLayout(*unwrap(DL));
+}
+
LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep) {
return wrap(new DataLayout(StringRep));
}
diff --git a/llvm/lib/Target/TargetMachineC.cpp b/llvm/lib/Target/TargetMachineC.cpp
index 9405ba7f295..208c59c5f47 100644
--- a/llvm/lib/Target/TargetMachineC.cpp
+++ b/llvm/lib/Target/TargetMachineC.cpp
@@ -171,6 +171,10 @@ void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
unwrap(T)->Options.MCOptions.AsmVerbose = VerboseAsm;
}
+LLVMTargetDataRef LLVMCreateTargetDataLayout(LLVMTargetMachineRef T) {
+ return wrap(new DataLayout(unwrap(T)->createDataLayout()));
+}
+
static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M,
raw_pwrite_stream &OS,
LLVMCodeGenFileType codegen,
diff --git a/llvm/test/Bindings/llvm-c/echo.ll b/llvm/test/Bindings/llvm-c/echo.ll
index df6de857af9..54d37dc7688 100644
--- a/llvm/test/Bindings/llvm-c/echo.ll
+++ b/llvm/test/Bindings/llvm-c/echo.ll
@@ -2,6 +2,9 @@
; RUN: llvm-as < %s | llvm-c-test --echo > %t.echo
; RUN: diff -w %t.orig %t.echo
+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.11.0"
+
%S = type { i64, %S* }
define { i64, %S* } @unpackrepack(%S %s) {
diff --git a/llvm/tools/llvm-c-test/echo.cpp b/llvm/tools/llvm-c-test/echo.cpp
index b19ae951d4e..774e339879d 100644
--- a/llvm/tools/llvm-c-test/echo.cpp
+++ b/llvm/tools/llvm-c-test/echo.cpp
@@ -16,6 +16,7 @@
//===----------------------------------------------------------------------===//
#include "llvm-c-test.h"
+#include "llvm-c/Target.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/ErrorHandling.h"
@@ -629,6 +630,11 @@ int llvm_echo(void) {
LLVMContextRef Ctx = LLVMContextCreate();
LLVMModuleRef M = LLVMModuleCreateWithNameInContext("<stdin>", Ctx);
+ LLVMSetTarget(M, LLVMGetTarget(Src));
+ LLVMSetModuleDataLayout(M, LLVMGetModuleDataLayout(Src));
+ if (strcmp(LLVMGetDataLayoutStr(M), LLVMGetDataLayoutStr(Src)))
+ report_fatal_error("Inconsistent DataLayout string representation");
+
clone_functions(Src, M);
char *Str = LLVMPrintModuleToString(M);
fputs(Str, stdout);
OpenPOWER on IntegriCloud