xref: /freebsd/contrib/llvm-project/clang/lib/CIR/Dialect/IR/CIRDataLayout.cpp (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 #include "clang/CIR/Dialect/IR/CIRDataLayout.h"
2 
3 using namespace cir;
4 
5 //===----------------------------------------------------------------------===//
6 //                       DataLayout Class Implementation
7 //===----------------------------------------------------------------------===//
8 
CIRDataLayout(mlir::ModuleOp modOp)9 CIRDataLayout::CIRDataLayout(mlir::ModuleOp modOp) : layout(modOp) {
10   reset(modOp.getDataLayoutSpec());
11 }
12 
reset(mlir::DataLayoutSpecInterface spec)13 void CIRDataLayout::reset(mlir::DataLayoutSpecInterface spec) {
14   bigEndian = false;
15   if (spec) {
16     mlir::StringAttr key = mlir::StringAttr::get(
17         spec.getContext(), mlir::DLTIDialect::kDataLayoutEndiannessKey);
18     if (mlir::DataLayoutEntryInterface entry = spec.getSpecForIdentifier(key))
19       if (auto str = llvm::dyn_cast<mlir::StringAttr>(entry.getValue()))
20         bigEndian = str == mlir::DLTIDialect::kDataLayoutEndiannessBig;
21   }
22 }
23