|
| 1 | +//===- CIRDialect.cpp - MLIR CIR ops implementation -----------------------===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, 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 | +//===----------------------------------------------------------------------===// |
| 8 | +// |
| 9 | +// This file defines the CIR DataLayout class and its functions. |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===//a |
| 12 | +// |
| 13 | + |
| 14 | +#include "clang/CIR/Dialect/IR/CIRDataLayout.h" |
| 15 | + |
| 16 | +namespace cir { |
| 17 | +CIRDataLayout::CIRDataLayout(mlir::ModuleOp modOp) : layout{modOp} { |
| 18 | + auto dlSpec = modOp->getAttr(mlir::DLTIDialect::kDataLayoutAttrName) |
| 19 | + .dyn_cast<mlir::DataLayoutSpecAttr>(); |
| 20 | + assert(dlSpec && "expected dl_spec in the module"); |
| 21 | + auto entries = dlSpec.getEntries(); |
| 22 | + |
| 23 | + for (auto entry : entries) { |
| 24 | + auto entryKey = entry.getKey(); |
| 25 | + auto strKey = entryKey.dyn_cast<mlir::StringAttr>(); |
| 26 | + if (!strKey) |
| 27 | + continue; |
| 28 | + auto entryName = strKey.strref(); |
| 29 | + if (entryName == mlir::DLTIDialect::kDataLayoutEndiannessKey) { |
| 30 | + auto value = entry.getValue().dyn_cast<mlir::StringAttr>(); |
| 31 | + assert(value && "expected string attribute"); |
| 32 | + auto endian = value.getValue(); |
| 33 | + if (endian == mlir::DLTIDialect::kDataLayoutEndiannessBig) |
| 34 | + bigEndian = true; |
| 35 | + else if (endian == mlir::DLTIDialect::kDataLayoutEndiannessLittle) |
| 36 | + bigEndian = false; |
| 37 | + else |
| 38 | + llvm_unreachable("unknown endianess"); |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +} // namespace cir |
0 commit comments