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

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 27 10:11:30 PDT 2023


================
@@ -0,0 +1,54 @@
+#include "llvm-c/Core.h"
+#include "llvm-c/TargetMachine.h"
+#include "llvm/Config/llvm-config.h"
+#include "gtest/gtest.h"
+
+namespace llvm {
+
+TEST(TargetMachineCTest, TargetMachineOptions) {
+  auto *Options = LLVMCreateTargetMachineOptions();
+
+  LLVMTargetMachineOptionsSetCPU(Options, "cortex-a53");
+  LLVMTargetMachineOptionsSetFeatures(Options, "+neon");
+  LLVMTargetMachineOptionsSetABI(Options, "aapcs");
+  LLVMTargetMachineOptionsSetCodeGenOptLevel(Options, LLVMCodeGenLevelNone);
+  LLVMTargetMachineOptionsSetRelocMode(Options, LLVMRelocStatic);
+  LLVMTargetMachineOptionsSetCodeModel(Options, LLVMCodeModelKernel);
+
+  LLVMDisposeTargetMachineOptions(Options);
+}
+
+TEST(TargetMachineCTest, TargetMachineCreation) {
+  LLVMInitializeAllTargets();
+  LLVMInitializeAllTargetInfos();
+  LLVMInitializeAllTargetMCs();
+
+  // Get the default target to keep the test as generic as possible. This may
+  // not be a target for which we can generate code; in that case we give up.
+
+  auto *Triple = LLVMGetDefaultTargetTriple();
----------------
aeubanks wrote:

I'm seeing checks in the other unittest that checks if this is empty and bails if so, perhaps we also need it here? I think it's possible to not have a default target triple.

https://github.com/llvm/llvm-project/blob/4c43c1eeef434cf0b98ee9094c776d118da1faeb/llvm/unittests/Passes/PassBuilderBindings/PassBuilderBindingsTest.cpp#L20

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


More information about the llvm-commits mailing list