Skip to content

Commit

Permalink
use llm lol for tblgen method
Browse files Browse the repository at this point in the history
  • Loading branch information
makslevental committed Jan 4, 2025
1 parent ffefb69 commit 4dd0f77
Show file tree
Hide file tree
Showing 6 changed files with 494 additions and 303 deletions.
1 change: 1 addition & 0 deletions build_tools/cmake/llvm_cache.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(LLVM_BUILD_TOOLS ON CACHE BOOL "")
set(LLVM_BUILD_UTILS ON CACHE BOOL "")
set(LLVM_INCLUDE_TOOLS ON CACHE BOOL "")
set(LLVM_INSTALL_UTILS ON CACHE BOOL "")
set(LLVM_ENABLE_DUMP ON CACHE BOOL "")

set(LLVM_BUILD_LLVM_DYLIB ON CACHE BOOL "")
# All the tools will use libllvm shared library
Expand Down
15 changes: 11 additions & 4 deletions projects/eudsl-tblgen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,26 @@ set(EUDSL_TBLGEN_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}/src")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${EUDSL_TBLGEN_SRC_DIR}/eudsl_tblgen)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

nanobind_add_module(eudsl_tblgen_ext NB_STATIC STABLE_ABI
nanobind_add_module(eudsl_tblgen_ext NB_STATIC
src/eudsl_tblgen_ext.cpp
src/TGParser.cpp
src/TGLexer.cpp
)
target_link_libraries(eudsl_tblgen_ext PRIVATE
LLVMTableGenCommon LLVMTableGen MLIRTableGen)
target_compile_options(eudsl_tblgen_ext
PUBLIC
set(nanobind_options
-Wno-cast-qual
-Wno-deprecated-literal-operator
-Wno-covered-switch-default
-Wno-nested-anon-types
-Wno-zero-length-array
-Wno-c++98-compat-extra-semi
$<$<PLATFORM_ID:Linux>:-fexceptions -frtti>
$<$<PLATFORM_ID:Darwin>:-fexceptions -frtti>
$<$<PLATFORM_ID:Windows>:/EHsc /GR>)
$<$<PLATFORM_ID:Windows>:/EHsc /GR>
)
target_compile_options(eudsl_tblgen_ext PRIVATE ${nanobind_options})
target_compile_options(nanobind-static PRIVATE ${nanobind_options})

# note WORKING_DIRECTORY
set(NB_STUBGEN_CMD "${Python_EXECUTABLE}" "-m" "nanobind.stubgen"
Expand Down
2 changes: 2 additions & 0 deletions projects/eudsl-tblgen/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cmake.source-dir = "."

[tool.scikit-build.cmake.define]
LLVM_DIR = { env = "LLVM_DIR", default = "EMPTY" }
MLIR_DIR = { env = "MLIR_DIR", default = "EMPTY" }
CMAKE_CXX_VISIBILITY_PRESET = "hidden"
CMAKE_C_COMPILER_LAUNCHER = { env = "CMAKE_C_COMPILER_LAUNCHER", default = "" }
CMAKE_CXX_COMPILER_LAUNCHER = { env = "CMAKE_CXX_COMPILER_LAUNCHER", default = "" }
Expand All @@ -34,6 +35,7 @@ archs = ["auto64"]
manylinux-x86_64-image = "manylinux_2_28"
environment-pass = [
"LLVM_DIR",
"MLIR_DIR",
"CMAKE_GENERATOR",
"CMAKE_PREFIX_PATH",
"CC",
Expand Down
39 changes: 39 additions & 0 deletions projects/eudsl-tblgen/src/eudsl_tblgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,42 @@
# Copyright (c) 2024.

from .eudsl_tblgen_ext import *


import re


def get_operation_name(def_record):
prefix = def_record.get_value_as_def("opDialect").get_value_as_string("name")
op_name = def_record.get_value_as_string("opName")

if not prefix:
return op_name
return f"{prefix}.{op_name}"


def get_requested_op_definitions(records, op_inc_filter=None, op_exc_filter=None):
class_def = records.get_class("Op")
if not class_def:
raise RuntimeError("ERROR: Couldn't find the 'Op' class!")

if op_inc_filter:
include_regex = re.compile(op_inc_filter)
if op_exc_filter:
exclude_regex = re.compile(op_exc_filter)
defs = []

for def_name in records.get_defs():
def_record = records.get_defs()[def_name]
if not def_record.is_sub_class_of(class_def):
continue
# Include if no include filter or include filter matches.
if op_inc_filter and not include_regex.match(get_operation_name(def_record)):
continue
# Unless there is an exclude filter and it matches.
if op_exc_filter and exclude_regex.match(get_operation_name(def_record)):
continue
def_record.dump()
defs.append(def_record)

return defs
Loading

0 comments on commit 4dd0f77

Please sign in to comment.