[llvm] [LLVM-C] Add LLVMCreateTargetMachineWithABI (PR #68406)

Sebastian Poeplau via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 05:56:52 PDT 2023


https://github.com/sebastianpoeplau updated https://github.com/llvm/llvm-project/pull/68406

>From c574067c2b48822fa8dc6532dcddde0382581839 Mon Sep 17 00:00:00 2001
From: Sebastian Poeplau <poeplau at adacore.com>
Date: Thu, 5 Oct 2023 15:57:53 +0200
Subject: [PATCH] [LLVM-C] Add LLVMCreateTargetMachineWithABI

The ABI parameter is used by a number of common backends, including ARM,
MIPS, PPC, and RISCV. Exposing it via the C API makes it possible for
users of those backends to configure the ABI without custom bindings.
---
 llvm/include/llvm-c/TargetMachine.h |  7 +++++++
 llvm/lib/Target/TargetMachineC.cpp  | 18 ++++++++++++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/llvm/include/llvm-c/TargetMachine.h b/llvm/include/llvm-c/TargetMachine.h
index bfbe1421a3560a8..e7481a7b4373417 100644
--- a/llvm/include/llvm-c/TargetMachine.h
+++ b/llvm/include/llvm-c/TargetMachine.h
@@ -103,6 +103,13 @@ LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T,
   const char *Triple, const char *CPU, const char *Features,
   LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, LLVMCodeModel CodeModel);
 
+/** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
+LLVMTargetMachineRef
+LLVMCreateTargetMachineWithABI(LLVMTargetRef T, const char *Triple,
+                               const char *CPU, const char *Features,
+                               const char *ABI, LLVMCodeGenOptLevel Level,
+                               LLVMRelocMode Reloc, LLVMCodeModel CodeModel);
+
 /** Dispose the LLVMTargetMachineRef instance generated by
   LLVMCreateTargetMachine. */
 void LLVMDisposeTargetMachine(LLVMTargetMachineRef T);
diff --git a/llvm/lib/Target/TargetMachineC.cpp b/llvm/lib/Target/TargetMachineC.cpp
index d418377325b215e..dea4f1f71fed9ce 100644
--- a/llvm/lib/Target/TargetMachineC.cpp
+++ b/llvm/lib/Target/TargetMachineC.cpp
@@ -96,10 +96,19 @@ LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T) {
   return unwrap(T)->hasMCAsmBackend();
 }
 
-LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T,
-        const char *Triple, const char *CPU, const char *Features,
-        LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc,
-        LLVMCodeModel CodeModel) {
+LLVMTargetMachineRef
+LLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple, const char *CPU,
+                        const char *Features, LLVMCodeGenOptLevel Level,
+                        LLVMRelocMode Reloc, LLVMCodeModel CodeModel) {
+  return LLVMCreateTargetMachineWithABI(T, Triple, CPU, Features, "", Level,
+                                        Reloc, CodeModel);
+}
+
+LLVMTargetMachineRef
+LLVMCreateTargetMachineWithABI(LLVMTargetRef T, const char *Triple,
+                               const char *CPU, const char *Features,
+                               const char *ABI, LLVMCodeGenOptLevel Level,
+                               LLVMRelocMode Reloc, LLVMCodeModel CodeModel) {
   std::optional<Reloc::Model> RM;
   switch (Reloc){
     case LLVMRelocStatic:
@@ -144,6 +153,7 @@ LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T,
   }
 
   TargetOptions opt;
+  opt.MCOptions.ABIName = ABI;
   return wrap(unwrap(T)->createTargetMachine(Triple, CPU, Features, opt, RM, CM,
                                              OL, JIT));
 }



More information about the llvm-commits mailing list