[clang] [clang][AVR] Add AVR-specific builtin functions (PR #203214)
Ben Shi via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 13 07:03:47 PDT 2026
================
@@ -0,0 +1,303 @@
+//===------ AVR.cpp - Emit LLVM Code for AVR builtins ---------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This contains code to emit Builtin calls as LLVM code.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CGBuiltin.h"
+#include "clang/Basic/TargetBuiltins.h"
+#include "llvm/IR/InlineAsm.h"
+#include "llvm/IR/IntrinsicsAVR.h"
+
+using namespace clang;
+using namespace CodeGen;
+using namespace llvm;
+
+/// Emit an inline-asm-based fractional multiply (fmul/fmuls/fmulsu).
+/// All three variants share the same shape: two i8 inputs → one i16 output,
+/// with the result collected from R1:R0 via movw, then R1 cleared.
+static Value *EmitAVRFMulInlineAsm(CodeGenFunction &CGF, const CallExpr *E,
+ const char *AsmInsn) {
+ Value *Arg0 = CGF.EmitScalarExpr(E->getArg(0));
+ Value *Arg1 = CGF.EmitScalarExpr(E->getArg(1));
+ llvm::LLVMContext &Ctx = CGF.getLLVMContext();
+ llvm::Type *ResTy = llvm::Type::getInt16Ty(Ctx);
+ llvm::Type *ArgTy = llvm::Type::getInt8Ty(Ctx);
+ llvm::FunctionType *FTy =
+ llvm::FunctionType::get(ResTy, {ArgTy, ArgTy}, false);
+
+ // Build the asm string: "<insn> $1, $2\n\tmovw $0, r0\n\tclr r1"
+ std::string Asm = std::string(AsmInsn) + " $1, $2\n\tmovw $0, r0\n\tclr r1";
----------------
benshi001 wrote:
`movw` is not available on `AVR2` family, and `r1` is not available on avr tiny.
https://github.com/llvm/llvm-project/pull/203214
More information about the cfe-commits
mailing list