[llvm] r260936 - Restore the capability to manipulate datalayout from the C API
Amaury Sechet via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 15 21:11:24 PST 2016
Author: deadalnix
Date: Mon Feb 15 23:11:24 2016
New Revision: 260936
URL: http://llvm.org/viewvc/llvm-project?rev=260936&view=rev
Log:
Restore the capability to manipulate datalayout from the C API
Summary:
This consist in variosu addition to the C API:
LLVMTargetDataRef LLVMGetModuleDataLayout(LLVMModuleRef M);
void LLVMSetModuleDataLayout(LLVMModuleRef M, LLVMTargetDataRef DL);
LLVMTargetDataRef LLVMCreateTargetMachineData(LLVMTargetMachineRef T);
Reviewers: joker.eph, Wallbraker, echristo
Subscribers: axw
Differential Revision: http://reviews.llvm.org/D17255
Modified:
llvm/trunk/include/llvm-c/Target.h
llvm/trunk/include/llvm-c/TargetMachine.h
llvm/trunk/lib/Target/Target.cpp
llvm/trunk/lib/Target/TargetMachineC.cpp
llvm/trunk/test/Bindings/llvm-c/echo.ll
llvm/trunk/tools/llvm-c-test/echo.cpp
Modified: llvm/trunk/include/llvm-c/Target.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/Target.h?rev=260936&r1=260935&r2=260936&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/Target.h (original)
+++ llvm/trunk/include/llvm-c/Target.h Mon Feb 15 23:11:24 2016
@@ -183,6 +183,20 @@ static inline LLVMBool LLVMInitializeNat
/*===-- 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);
Modified: llvm/trunk/include/llvm-c/TargetMachine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm-c/TargetMachine.h?rev=260936&r1=260935&r2=260936&view=diff
==============================================================================
--- llvm/trunk/include/llvm-c/TargetMachine.h (original)
+++ llvm/trunk/include/llvm-c/TargetMachine.h Mon Feb 15 23:11:24 2016
@@ -115,6 +115,9 @@ char *LLVMGetTargetMachineCPU(LLVMTarget
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);
Modified: llvm/trunk/lib/Target/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Target.cpp?rev=260936&r1=260935&r2=260936&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Target.cpp (original)
+++ llvm/trunk/lib/Target/Target.cpp Mon Feb 15 23:11:24 2016
@@ -42,6 +42,14 @@ void LLVMInitializeTarget(LLVMPassRegist
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));
}
Modified: llvm/trunk/lib/Target/TargetMachineC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachineC.cpp?rev=260936&r1=260935&r2=260936&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetMachineC.cpp (original)
+++ llvm/trunk/lib/Target/TargetMachineC.cpp Mon Feb 15 23:11:24 2016
@@ -171,6 +171,10 @@ void LLVMSetTargetMachineAsmVerbosity(LL
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,
Modified: llvm/trunk/test/Bindings/llvm-c/echo.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/llvm-c/echo.ll?rev=260936&r1=260935&r2=260936&view=diff
==============================================================================
--- llvm/trunk/test/Bindings/llvm-c/echo.ll (original)
+++ llvm/trunk/test/Bindings/llvm-c/echo.ll Mon Feb 15 23:11:24 2016
@@ -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) {
Modified: llvm/trunk/tools/llvm-c-test/echo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-c-test/echo.cpp?rev=260936&r1=260935&r2=260936&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-c-test/echo.cpp (original)
+++ llvm/trunk/tools/llvm-c-test/echo.cpp Mon Feb 15 23:11:24 2016
@@ -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);
More information about the llvm-commits
mailing list