[llvm] 160f5ca - [AVR][NFC] Split AVRTargetTransformInfo.h to AVRTargetTransformInfo.cpp (#152841)

via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 9 01:09:48 PDT 2025


Author: Tom Vijlbrief
Date: 2025-08-09T16:09:45+08:00
New Revision: 160f5ca0f5e32b56559fdd6d993b0c7997adf6ff

URL: https://github.com/llvm/llvm-project/commit/160f5ca0f5e32b56559fdd6d993b0c7997adf6ff
DIFF: https://github.com/llvm/llvm-project/commit/160f5ca0f5e32b56559fdd6d993b0c7997adf6ff.diff

LOG: [AVR][NFC] Split AVRTargetTransformInfo.h to AVRTargetTransformInfo.cpp (#152841)

Added: 
    llvm/lib/Target/AVR/AVRTargetTransformInfo.cpp

Modified: 
    llvm/lib/Target/AVR/AVRTargetTransformInfo.h
    llvm/lib/Target/AVR/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AVR/AVRTargetTransformInfo.cpp b/llvm/lib/Target/AVR/AVRTargetTransformInfo.cpp
new file mode 100644
index 0000000000000..4dd8660589cf0
--- /dev/null
+++ b/llvm/lib/Target/AVR/AVRTargetTransformInfo.cpp
@@ -0,0 +1,25 @@
+//===-- AVRTargetTransformInfo.cpp - AVR specific TTI ---------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "AVRTargetTransformInfo.h"
+#include "llvm/CodeGen/CostTable.h"
+
+using namespace llvm;
+
+bool AVRTTIImpl::isLSRCostLess(const TargetTransformInfo::LSRCost &C1,
+                               const TargetTransformInfo::LSRCost &C2) const {
+  // AVR specific here are "instruction number 1st priority".
+  // If we need to emit adds inside the loop to add up base registers, then
+  // we need at least one extra temporary register.
+  unsigned C1NumRegs = C1.NumRegs + (C1.NumBaseAdds != 0);
+  unsigned C2NumRegs = C2.NumRegs + (C2.NumBaseAdds != 0);
+  return std::tie(C1.Insns, C1NumRegs, C1.AddRecCost, C1.NumIVMuls,
+                  C1.NumBaseAdds, C1.ScaleCost, C1.ImmCost, C1.SetupCost) <
+         std::tie(C2.Insns, C2NumRegs, C2.AddRecCost, C2.NumIVMuls,
+                  C2.NumBaseAdds, C2.ScaleCost, C2.ImmCost, C2.SetupCost);
+}

diff  --git a/llvm/lib/Target/AVR/AVRTargetTransformInfo.h b/llvm/lib/Target/AVR/AVRTargetTransformInfo.h
index 5ef2e6abc75fc..0daeeb8f11cfe 100644
--- a/llvm/lib/Target/AVR/AVRTargetTransformInfo.h
+++ b/llvm/lib/Target/AVR/AVRTargetTransformInfo.h
@@ -43,12 +43,7 @@ class AVRTTIImpl final : public BasicTTIImplBase<AVRTTIImpl> {
         TLI(ST->getTargetLowering()) {}
 
   bool isLSRCostLess(const TargetTransformInfo::LSRCost &C1,
-                     const TargetTransformInfo::LSRCost &C2) const override {
-    if (C2.Insns == ~0u)
-      return true;
-    return 2 * C1.Insns + C1.AddRecCost + C1.SetupCost + C1.NumRegs <
-           2 * C2.Insns + C2.AddRecCost + C2.SetupCost + C2.NumRegs;
-  }
+                     const TargetTransformInfo::LSRCost &C2) const override;
 };
 
 } // end namespace llvm

diff  --git a/llvm/lib/Target/AVR/CMakeLists.txt b/llvm/lib/Target/AVR/CMakeLists.txt
index 781dac02c7083..864936d1f6155 100644
--- a/llvm/lib/Target/AVR/CMakeLists.txt
+++ b/llvm/lib/Target/AVR/CMakeLists.txt
@@ -29,6 +29,7 @@ add_llvm_target(AVRCodeGen
   AVRSubtarget.cpp
   AVRTargetMachine.cpp
   AVRTargetObjectFile.cpp
+  AVRTargetTransformInfo.cpp
 
   DEPENDS
   intrinsics_gen


        


More information about the llvm-commits mailing list