aboutsummaryrefslogtreecommitdiff
path: root/rcc-legacy/include/rcc/loopinfo.h
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-06-08 16:58:53 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-06-08 16:58:53 +0800
commit4e7c29d1588fadf19a98476b5adf5ce84ed8076d (patch)
tree4aca189bb48e789d39baf0c5e6d568e6b41da51c /rcc-legacy/include/rcc/loopinfo.h
parent06a63b80effa4793f6c51ba827829655d6caf149 (diff)
downloadrcc-project-4e7c29d1588fadf19a98476b5adf5ce84ed8076d.tar.gz
rcc-project-4e7c29d1588fadf19a98476b5adf5ce84ed8076d.tar.xz
[legacy] Add IR, AST, and RISC-V target headers
Diffstat (limited to 'rcc-legacy/include/rcc/loopinfo.h')
-rw-r--r--rcc-legacy/include/rcc/loopinfo.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/rcc-legacy/include/rcc/loopinfo.h b/rcc-legacy/include/rcc/loopinfo.h
new file mode 100644
index 0000000..581f8c5
--- /dev/null
+++ b/rcc-legacy/include/rcc/loopinfo.h
@@ -0,0 +1,74 @@
+/* Source code for RCC-Legacy.
+ Copyright (C) 2026 Richard Qin
+
+This file is part of RCC.
+
+RCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+RCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with RCC; see the file LICENSE. If not see
+<http://www.gnu.org/licenses/>. */
+
+/// @file loopinfo.h
+/// @brief Natural loop and constant BIV identification.
+
+#pragma once
+
+#include "rcc/all.h"
+
+#include <unordered_set>
+#include <vector>
+
+namespace rcc {
+
+struct Loop {
+ Blk* header;
+ Blk* preheader;
+ Blk* latch;
+ std::vector<Blk*> body; // Includes header / latch
+ std::unordered_set<uint> body_bid; // Set of b->id in body, used for tmp.bid lookup
+};
+
+/// Constant Basic Induction Variable.
+struct Biv {
+ Ref to; // header phi.to
+ int cls; // phi cls
+ int64_t init; // Preheader constant
+ int64_t step; // Constant step of Oadd at latch, != 0
+};
+
+void find_loops(Fn*, std::vector<Loop>&);
+void detect_bivs(Fn*, const Loop&, std::vector<Biv>&);
+
+/// Decode CBits constant Ref (integer). Returns false for CAddr / float / non-RCon.
+bool ref_is_const(Fn*, Ref, int64_t& out);
+
+/// Get defining Ins via Tmp::def. Returns nullptr for non-RTmp or out of bounds.
+Ins* def_ins(Fn*, Ref);
+
+/// Canonical pointer IV after LSR.
+struct PointerIV {
+ Ref phi_to;
+ Ref base;
+ Ref next;
+ int64_t step;
+};
+
+/// Identify pointer IV on header phi. Returns false on failure.
+bool pick_pointer_iv(Fn*, const Loop&, Phi*, PointerIV*);
+
+/// Match pointer termination condition against pointer IV.
+bool check_exit_cmp(Fn*, const Loop&, Ref p, Ref* end_out, Blk** after_out);
+
+/// Check if any def inside the loop is used by outside users.
+bool has_outside_use(Fn*, const Loop&);
+
+} // namespace rcc