Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit c1dafe7

Browse files
author
Sven Verdoolaege
committed
LLVMCodegen::emitStmt: extract out CodeGen_TC::getValue
This function will be reused to extract an llvm::Value from an AST expression corresponding to a variable.
1 parent 9f47507 commit c1dafe7

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/core/polyhedral/codegen_llvm.cc

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,11 @@ class CodeGen_TC : public Halide::Internal::CodeGen_X86 {
249249
return std::move(module);
250250
}
251251

252+
// Convert an isl AST expression into an llvm::Value.
253+
// Only expressions that consist of a pure identifier or
254+
// a pure integer constant are currently supported.
255+
llvm::Value* getValue(isl::ast_expr expr);
256+
252257
protected:
253258
using CodeGen_X86::visit;
254259
void visit(const Halide::Internal::Call* call) override {
@@ -361,6 +366,21 @@ class CodeGen_TC : public Halide::Internal::CodeGen_X86 {
361366
}
362367
};
363368

369+
llvm::Value* CodeGen_TC::getValue(isl::ast_expr expr) {
370+
switch (isl_ast_expr_get_type(expr.get())) {
371+
case isl_ast_expr_type::isl_ast_expr_id:
372+
return sym_get(expr.get_id().get_name());
373+
case isl_ast_expr_type::isl_ast_expr_int: {
374+
auto val = isl::manage(isl_ast_expr_get_val(expr.get()));
375+
CHECK(val.is_int());
376+
return getLLVMConstantSignedInt64(val.get_num_si());
377+
}
378+
default:
379+
LOG(FATAL) << "NYI";
380+
return nullptr;
381+
}
382+
}
383+
364384
class LLVMCodegen {
365385
void collectTensor(const Halide::OutputImageParam& t) {
366386
auto sizes =
@@ -638,22 +658,7 @@ class LLVMCodegen {
638658
llvm::SmallVector<llvm::Value*, 5> subscriptValues;
639659

640660
for (const auto& subscript : subscripts) {
641-
switch (isl_ast_expr_get_type(subscript.get())) {
642-
case isl_ast_expr_type::isl_ast_expr_id: {
643-
subscriptValues.push_back(
644-
halide_cg.sym_get(subscript.get_id().get_name()));
645-
break;
646-
}
647-
case isl_ast_expr_type::isl_ast_expr_int: {
648-
auto val = isl::manage(isl_ast_expr_get_val(subscript.get()));
649-
CHECK(val.is_int());
650-
subscriptValues.push_back(
651-
getLLVMConstantSignedInt64(val.get_num_si()));
652-
break;
653-
}
654-
default:
655-
LOG(FATAL) << "NYI";
656-
}
661+
subscriptValues.push_back(halide_cg.getValue(subscript));
657662
}
658663

659664
auto destAddr = halide_cg.get_builder().CreateInBoundsGEP(

0 commit comments

Comments
 (0)