Skip to content

Commit

Permalink
Adding FindMLIR.cmake to link mlir header to ldc and creating output_…
Browse files Browse the repository at this point in the history
…mlir into globals.d
  • Loading branch information
Robertorosmaninho committed Oct 2, 2019
1 parent a611de4 commit d739ef4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 13 deletions.
20 changes: 9 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ endif()
#
include(GetLinuxDistribution)


#
# Get MLIR
# TODO: Make this generic
include_directories(~/llvm-project/llvm/projects/mlir)
include_directories( ~/llvm-project/llvm/build/projects/mlir/)
#
# Main configuration.
#
Expand Down Expand Up @@ -360,7 +354,6 @@ configure_file(driver/ldc-version.cpp.in driver/ldc-version.cpp)
file(GLOB_RECURSE FE_SRC_D dmd/*.d)
file(GLOB_RECURSE FE_HDR dmd/*.h)
file(GLOB_RECURSE FE_RES res/*.*)
file(GLOB_RECURSE MLIR_HDR ~/llvm-project/llvm/projects/mlir/include/IR/*.h)
file(GLOB_RECURSE GEN_SRC gen/*.cpp)
file(GLOB_RECURSE GEN_HDR gen/*.h)
file(GLOB_RECURSE GEN_SRC_D gen/*.d)
Expand Down Expand Up @@ -420,7 +413,6 @@ set(LDC_CXX_SOURCE_FILES
${GEN_HDR}
${IR_SRC}
${IR_HDR}
${MLIR_HDR}
)
set(LDC_D_SOURCE_FILES
${FE_SRC_D}
Expand All @@ -433,7 +425,6 @@ source_group("Source Files\\dmd" FILES ${FE_SRC_D})
source_group("Header Files\\dmd" FILES ${FE_HDR})
source_group("Source Files\\gen" FILES ${GEN_SRC} ${GEN_SRC_D})
source_group("Header Files\\gen" FILES ${GEN_HDR})
source_group("Header FILES\\mlir" FILES ${MLIR_HDR})
source_group("Source Files\\ir" FILES ${IR_SRC} ${IR_SRC_D})
source_group("Header Files\\ir" FILES ${IR_HDR})
source_group("Source Files" FILES ${DRV_SRC_D})
Expand All @@ -458,13 +449,20 @@ if(LDC_DYNAMIC_COMPILE STREQUAL "AUTO")
endif()
message(STATUS "Building LDC with dynamic compilation support: ${LDC_DYNAMIC_COMPILE} (LDC_DYNAMIC_COMPILE=${LDC_DYNAMIC_COMPILE})")

#
# Setting MLIR headers
#

find_package(MLIR REQUIRED)
include_directories(${MLIR_INCLUDE_DIRS})
include_directories(${MLIR_BUILD_INCLUDE_DIRS})


#
# Includes, defines.
#

include_directories(. dmd)
INCLUDE_DIRECTORIES(~/llvm-project/llvm/projects/mlir/include/)
INCLUDE_DIRECTORIES(~/llvm-project/llvm/build/projects/mlir/include/)
append("-I${PROJECT_SOURCE_DIR}" DDMD_DFLAGS)
append("-I${PROJECT_BINARY_DIR}" DDMD_DFLAGS)

Expand Down
35 changes: 35 additions & 0 deletions cmake/Modules/FindMLIR.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# - Try to find MLIR project at LLVM
#
# The following are set after configuration is done:
# MLIR_FOUND
# MLIR_ROOT_DIRS
# MLIR_INCLUDE_DIRS
# MLIR_BUILD_INCLUDE_DIR
project(ldc)

find_path(MLIR_ROOT_DIR NAMES "CONTRIBUTING.md" HINTS ${LLVM_ROOT_DIR}/../projects/mlir)

#Used to get the main header files
find_path(MLIR_INCLUDE_DIR NAMES "Parser.h" HINTS ${LLVM_ROOT_DIR}/../projects/mlir/include/mlir)

#Used to get StandardOps.h.inc
find_path(MLIR_BUILD_INCLUDE_DIR NAMES "cmake_install.cmake"
HINTS ${LLVM_ROOT_DIR}/projects/mlir/include/mlir)

message("-- MLIR Dir: ${MLIR_ROOT_DIR}")
message("-- MLIR Include Dir: ${MLIR_INCLUDE_DIR}/..")
message("-- MLIR Build include dir: ${MLIR_BUILD_INCLUDE_DIR}/..")
message("flag")

set(MLIR_ROOT_DIRS ${MLIR_ROOT_DIR})
set(MLIR_INCLUDE_DIRS ${MLIR_INCLUDE_DIR}/..)
set(MLIR_BUILD_INCLUDE_DIRS ${MLIR_BUILD_INCLUDE_DIR}/..)

# Handle the QUIETLY and REQUIRED arguments and set the MLIR_FOUND to TRUE
# if all listed variables are TRUE
include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(MLIR DEFAULT_MSG MLIR_ROOT_DIRS MLIR_INCLUDE_DIRS
MLIR_BUILD_INCLUDE_DIRS)

mark_as_advanced(MLIR_ROOT_DIRS MLIR_INCLUDE_DIRS MLIR_BUILD_INCLUDE_DIRS)
2 changes: 2 additions & 0 deletions dmd/globals.d
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ version (IN_LLVM)

// LDC stuff
OUTPUTFLAG output_ll;
OUTPUTFLAG output_mlir;
OUTPUTFLAG output_bc;
OUTPUTFLAG output_s;
OUTPUTFLAG output_o;
Expand Down Expand Up @@ -339,6 +340,7 @@ struct Global
version (IN_LLVM)
{
const(char)[] ll_ext;
const(char)[] mlir_ext;
const(char)[] bc_ext;
const(char)[] s_ext;
const(char)[] ldc_version;
Expand Down
4 changes: 2 additions & 2 deletions gen/mlirstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// code (i.e. MLIR) for a given D module.
//
//===----------------------------------------------------------------------===//

//
#pragma once

#include "mlir/Dialect/StandardOps/Ops.h"
Expand All @@ -29,7 +29,7 @@
namespace mlir {
class MLIRContext; /*Get the context of the program - similar to LLVMContext*/
class OwningModuleRef; /*returns a newly created MLIR module or nullptr
on failure.
on failure.*/
} //namespace mlir

class TypeFunction; /*unsed*/
Expand Down

0 comments on commit d739ef4

Please sign in to comment.