Skip to content

Commit

Permalink
[CIR][Dialect] Add the datalayout interface to cir.ArrayType and Poin…
Browse files Browse the repository at this point in the history
…terType

Add the interface and the boilerplate methods to propagate the elements. This is
the same behavior as we see from llvm's datalayout types.
  • Loading branch information
lanza committed Apr 29, 2023
1 parent 7cc7d66 commit 6c0d95c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
1 change: 1 addition & 0 deletions clang/include/clang/CIR/Dialect/IR/CIRTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/Types.h"
#include "mlir/Interfaces/DataLayoutInterfaces.h"

//===----------------------------------------------------------------------===//
// CIR Dialect Types
Expand Down
13 changes: 7 additions & 6 deletions clang/include/clang/CIR/Dialect/IR/CIRTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@
#define MLIR_CIR_DIALECT_CIR_TYPES

include "clang/CIR/Dialect/IR/CIRDialect.td"
include "mlir/Interfaces/DataLayoutInterfaces.td"
include "mlir/IR/AttrTypeBase.td"

//===----------------------------------------------------------------------===//
// CIR Types
//===----------------------------------------------------------------------===//

class CIR_Type<string name, string typeMnemonic> : TypeDef<CIR_Dialect,
name> {
class CIR_Type<string name, string typeMnemonic, list<Trait> traits = []> :
TypeDef<CIR_Dialect, name, traits> {
let mnemonic = typeMnemonic;
}

//===----------------------------------------------------------------------===//
// PointerType
//===----------------------------------------------------------------------===//

def CIR_PointerType :
CIR_Type<"Pointer", "ptr"> {
def CIR_PointerType : CIR_Type<"Pointer", "ptr",
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {

let summary = "CIR pointer type";
let description = [{
Expand Down Expand Up @@ -112,8 +113,8 @@ def CIR_StructType : CIR_Type<"Struct", "struct"> {
// ArrayType
//===----------------------------------------------------------------------===//

def CIR_ArrayType :
CIR_Type<"Array", "array"> {
def CIR_ArrayType : CIR_Type<"Array", "array",
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {

let summary = "CIR array type";
let description = [{
Expand Down
36 changes: 36 additions & 0 deletions clang/lib/CIR/Dialect/IR/CIRTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,24 @@ void PointerType::print(mlir::AsmPrinter &printer) const {
printer << '>';
}

unsigned
PointerType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
llvm_unreachable("NYI");
}

unsigned
PointerType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
llvm_unreachable("NYI");
}

unsigned
PointerType::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
llvm_unreachable("NYI");
}

Type BoolType::parse(mlir::AsmParser &parser) {
return get(parser.getContext());
}
Expand Down Expand Up @@ -163,6 +181,24 @@ void ArrayType::print(mlir::AsmPrinter &printer) const {
printer << '>';
}

unsigned
ArrayType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
return dataLayout.getTypeSizeInBits(getEltType());
}

unsigned
ArrayType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
return dataLayout.getTypeABIAlignment(getEltType());
}

unsigned
ArrayType::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
return dataLayout.getTypePreferredAlignment(getEltType());
}

//===----------------------------------------------------------------------===//
// CIR Dialect
//===----------------------------------------------------------------------===//
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/Dialect/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ add_clang_library(MLIRCIR
LINK_LIBS PUBLIC
MLIRIR
MLIRFuncDialect
MLIRLLVMDialect
MLIRDataLayoutInterfaces
MLIRSideEffectInterfaces
)

0 comments on commit 6c0d95c

Please sign in to comment.