Skip to content

Commit edf0e60

Browse files
hunhoffeclaude
andcommitted
[dyn-seq P1.3] AIEX->EmitC conversion + C++ TXN target
Add the runtime-parameterizable mirror of the compile-time binary TXN emitter. A straight-line aie.runtime_sequence of npu ops lowers to a standalone generate_txn_<seq>() C++ function that assembles the TXN stream from TxnEncoding.h, with scalar operands (constant or runtime) flowing through as C++ literals/parameters. - New pass --convert-aiex-to-emitc: converts write32, maskwrite32, sync, address_patch, blockwrite (+ feeding memref.get_global) to emitc calls; runs upstream ArithToEmitC so constant and derived scalar fields lower uniformly; rejects scf control flow with a clean diagnostic. - New aie-translate target --aie-npu-to-cpp (pass + translateToCpp). - Per-op / runtime-value / reject / end-to-end FileCheck coverage. For constant operands the generated C++ produces byte-identical TXN to aie-npu-to-binary; runtime scalar operands become generate_txn_<seq>() parameters (foundation for dynamic runtime sequences, milestone #3222). Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5557e05 commit edf0e60

14 files changed

Lines changed: 834 additions & 1 deletion

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===- AIEXToEmitC.h --------------------------------------------*- C++ -*-===//
2+
//
3+
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
// Copyright (C) 2026 Advanced Micro Devices, Inc.
8+
//
9+
//===----------------------------------------------------------------------===//
10+
11+
#ifndef AIE_CONVERSION_AIEXTOEMITC_AIEXTOEMITC_H
12+
#define AIE_CONVERSION_AIEXTOEMITC_AIEXTOEMITC_H
13+
14+
#include "mlir/IR/BuiltinOps.h"
15+
#include "mlir/Pass/Pass.h"
16+
#include <memory>
17+
18+
namespace xilinx {
19+
20+
std::unique_ptr<mlir::OperationPass<mlir::ModuleOp>>
21+
createConvertAIEXToEmitCPass();
22+
23+
} // namespace xilinx
24+
25+
#endif // AIE_CONVERSION_AIEXTOEMITC_AIEXTOEMITC_H

include/aie/Conversion/Passes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "aie/Conversion/AIEToConfiguration/AIEToConfiguration.h"
1313
#include "aie/Conversion/AIEVecToLLVM/AIEVecToLLVM.h"
14+
#include "aie/Conversion/AIEXToEmitC/AIEXToEmitC.h"
1415
#include "aie/Conversion/PassesEnums.h.inc"
1516

1617
namespace xilinx {

include/aie/Conversion/Passes.td

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,31 @@ def ConvertAIEToTransaction : Pass<"convert-aie-to-transaction",
7878
];
7979
}
8080

81+
//===----------------------------------------------------------------------===//
82+
// AIEXToEmitC
83+
//===----------------------------------------------------------------------===//
84+
85+
def ConvertAIEXToEmitC : Pass<"convert-aiex-to-emitc", "mlir::ModuleOp"> {
86+
let summary = "Convert AIEX runtime sequence ops to EmitC for C++ TXN generation";
87+
let description = [{
88+
This pass converts the straight-line npu transaction ops in an
89+
`aie.runtime_sequence` (`npu.write32`, `npu.maskwrite32`, `npu.sync`,
90+
`npu.address_patch`, `npu.blockwrite`) into EmitC dialect calls naming the
91+
functions in `aie/Runtime/TxnEncoding.h`. Running MLIR's `translateToCpp()`
92+
on the result produces a standalone `generate_txn_<seq>(...)` C++ function
93+
that assembles the TXN binary at run time -- the same words the compile-time
94+
binary emitter (`AIETargetNPU.cpp`) produces, but from a C++ function so
95+
runtime-valued operands can flow through to a single compiled xclbin.
96+
97+
Control flow (`scf.for`/`scf.if`) inside a runtime sequence is rejected with
98+
a diagnostic; it is handled by later passes in the dynamic-sequences work.
99+
}];
100+
let constructor = "xilinx::createConvertAIEXToEmitCPass()";
101+
let dependentDialects = ["mlir::emitc::EmitCDialect",
102+
"xilinx::AIE::AIEDialect",
103+
"xilinx::AIEX::AIEXDialect"];
104+
}
105+
81106
//===----------------------------------------------------------------------===//
82107
// AIEToControlPackets
83108
//===----------------------------------------------------------------------===//

include/aie/Targets/AIETargets.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ AIETranslateNpuToBinary(mlir::ModuleOp, std::vector<uint32_t> &,
7575
llvm::StringRef deviceName = "",
7676
llvm::StringRef sequenceName = "",
7777
std::vector<TxnLocEntry> *locmap = nullptr);
78+
mlir::LogicalResult AIETranslateNpuToCpp(mlir::ModuleOp module,
79+
llvm::raw_ostream &output);
7880
mlir::LogicalResult AIETranslateToUcDma(mlir::ModuleOp module,
7981
llvm::raw_ostream &output);
8082
mlir::LogicalResult AIETranslateToUcDma(mlir::ModuleOp, std::string &assembly);

0 commit comments

Comments
 (0)