[PATCH] D49414: Add target triple normalization to the C API

Markus Lindström via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 17 00:01:03 PDT 2018


mhlindstr created this revision.
mhlindstr added a reviewer: whitequark.
Herald added a reviewer: deadalnix.
Herald added a subscriber: llvm-commits.

https://reviews.llvm.org/rL333307 was introduced to remove automatic target triple normalization when calling sys::getDefaultTargetTriple(), arguing that users of the latter already called Triple::normalize() if necessary. However, users of the C API currently have no way of doing target triple normalization. This patch introduces an LLVMNormalizeTargetTriple function to the C API which wraps Triple::normalize() and can be used on the result of LLVMGetDefaultTargetTriple to achieve the same effect.


Repository:
  rL LLVM

https://reviews.llvm.org/D49414

Files:
  include/llvm-c/TargetMachine.h
  lib/Target/TargetMachineC.cpp


Index: lib/Target/TargetMachineC.cpp
===================================================================
--- lib/Target/TargetMachineC.cpp
+++ lib/Target/TargetMachineC.cpp
@@ -238,6 +238,10 @@
   return strdup(sys::getDefaultTargetTriple().c_str());
 }
 
+char *LLVMNormalizeTargetTriple(char* triple) {
+  return strdup(Triple::normalize(StringRef(triple)).c_str());
+}
+
 char *LLVMGetHostCPUName(void) {
   return strdup(sys::getHostCPUName().data());
 }
Index: include/llvm-c/TargetMachine.h
===================================================================
--- include/llvm-c/TargetMachine.h
+++ include/llvm-c/TargetMachine.h
@@ -137,6 +137,10 @@
   disposed with LLVMDisposeMessage. */
 char* LLVMGetDefaultTargetTriple(void);
 
+/** Normalize a target triple. The result needs to be disposed with
+  LLVMDisposeMessage. */
+char* LLVMNormalizeTargetTriple(char* triple);
+
 /** Get the host CPU as a string. The result needs to be disposed with
   LLVMDisposeMessage. */
 char* LLVMGetHostCPUName(void);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49414.155814.patch
Type: text/x-patch
Size: 1015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180717/2a873c2c/attachment.bin>


More information about the llvm-commits mailing list