15#include "mlir/IR/DialectImplementation.h"
17#include "llvm/ADT/TypeSwitch.h"
23static mlir::ParseResult
27 mlir::ArrayRef<mlir::Type> params,
bool isVarArg);
33#define GET_TYPEDEF_CLASSES
34#include "clang/CIR/Dialect/IR/CIROpsTypes.cpp.inc"
43Type CIRDialect::parseType(DialectAsmParser &parser)
const {
44 llvm::SMLoc typeLoc = parser.getCurrentLocation();
45 llvm::StringRef mnemonic;
49 OptionalParseResult parseResult =
50 generatedTypeParser(parser, &mnemonic, genType);
51 if (parseResult.has_value())
55 parser.emitError(typeLoc) <<
"unknown CIR type: " << mnemonic;
59void CIRDialect::printType(
Type type, DialectAsmPrinter &os)
const {
61 if (generatedTypePrinter(type, os).succeeded())
65 llvm::report_fatal_error(
"printer is missing a handler for this type");
72Type IntType::parse(mlir::AsmParser &parser) {
73 mlir::MLIRContext *context = parser.getBuilder().getContext();
74 llvm::SMLoc loc = parser.getCurrentLocation();
78 if (parser.parseLess())
83 if (parser.parseKeyword(&
sign))
90 parser.emitError(loc,
"expected 's' or 'u'");
94 if (parser.parseComma())
98 if (parser.parseInteger(width))
100 if (width < IntType::minBitwidth() || width > IntType::maxBitwidth()) {
101 parser.emitError(loc,
"expected integer width to be from ")
102 << IntType::minBitwidth() <<
" up to " << IntType::maxBitwidth();
106 if (parser.parseGreater())
109 return IntType::get(context, width, isSigned);
112void IntType::print(mlir::AsmPrinter &printer)
const {
113 char sign = isSigned() ?
's' :
'u';
114 printer <<
'<' <<
sign <<
", " << getWidth() <<
'>';
118IntType::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
119 mlir::DataLayoutEntryListRef params)
const {
120 return llvm::TypeSize::getFixed(getWidth());
123uint64_t IntType::getABIAlignment(
const mlir::DataLayout &dataLayout,
124 mlir::DataLayoutEntryListRef params)
const {
125 return (uint64_t)(getWidth() / 8);
129IntType::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
130 ::mlir::DataLayoutEntryListRef params)
const {
131 return (uint64_t)(getWidth() / 8);
135IntType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
136 unsigned width,
bool isSigned) {
137 if (width < IntType::minBitwidth() || width > IntType::maxBitwidth()) {
138 emitError() <<
"IntType only supports widths from "
139 << IntType::minBitwidth() <<
" up to "
140 << IntType::maxBitwidth();
141 return mlir::failure();
143 return mlir::success();
150const llvm::fltSemantics &SingleType::getFloatSemantics()
const {
151 return llvm::APFloat::IEEEsingle();
155SingleType::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
156 mlir::DataLayoutEntryListRef params)
const {
157 return llvm::TypeSize::getFixed(getWidth());
161SingleType::getABIAlignment(
const mlir::DataLayout &dataLayout,
162 mlir::DataLayoutEntryListRef params)
const {
163 return (uint64_t)(getWidth() / 8);
167SingleType::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
168 ::mlir::DataLayoutEntryListRef params)
const {
169 return (uint64_t)(getWidth() / 8);
172const llvm::fltSemantics &DoubleType::getFloatSemantics()
const {
173 return llvm::APFloat::IEEEdouble();
177DoubleType::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
178 mlir::DataLayoutEntryListRef params)
const {
179 return llvm::TypeSize::getFixed(getWidth());
183DoubleType::getABIAlignment(
const mlir::DataLayout &dataLayout,
184 mlir::DataLayoutEntryListRef params)
const {
185 return (uint64_t)(getWidth() / 8);
189DoubleType::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
190 ::mlir::DataLayoutEntryListRef params)
const {
191 return (uint64_t)(getWidth() / 8);
194const llvm::fltSemantics &FP16Type::getFloatSemantics()
const {
195 return llvm::APFloat::IEEEhalf();
199FP16Type::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
200 mlir::DataLayoutEntryListRef params)
const {
201 return llvm::TypeSize::getFixed(getWidth());
204uint64_t FP16Type::getABIAlignment(
const mlir::DataLayout &dataLayout,
205 mlir::DataLayoutEntryListRef params)
const {
206 return (uint64_t)(getWidth() / 8);
210FP16Type::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
211 ::mlir::DataLayoutEntryListRef params)
const {
212 return (uint64_t)(getWidth() / 8);
215const llvm::fltSemantics &BF16Type::getFloatSemantics()
const {
216 return llvm::APFloat::BFloat();
220BF16Type::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
221 mlir::DataLayoutEntryListRef params)
const {
222 return llvm::TypeSize::getFixed(getWidth());
225uint64_t BF16Type::getABIAlignment(
const mlir::DataLayout &dataLayout,
226 mlir::DataLayoutEntryListRef params)
const {
227 return (uint64_t)(getWidth() / 8);
231BF16Type::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
232 ::mlir::DataLayoutEntryListRef params)
const {
233 return (uint64_t)(getWidth() / 8);
236const llvm::fltSemantics &FP80Type::getFloatSemantics()
const {
237 return llvm::APFloat::x87DoubleExtended();
241FP80Type::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
242 mlir::DataLayoutEntryListRef params)
const {
244 return llvm::TypeSize::getFixed(128);
247uint64_t FP80Type::getABIAlignment(
const mlir::DataLayout &dataLayout,
248 mlir::DataLayoutEntryListRef params)
const {
253FP80Type::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
254 ::mlir::DataLayoutEntryListRef params)
const {
258const llvm::fltSemantics &FP128Type::getFloatSemantics()
const {
259 return llvm::APFloat::IEEEquad();
263FP128Type::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
264 mlir::DataLayoutEntryListRef params)
const {
265 return llvm::TypeSize::getFixed(getWidth());
268uint64_t FP128Type::getABIAlignment(
const mlir::DataLayout &dataLayout,
269 mlir::DataLayoutEntryListRef params)
const {
274FP128Type::getPreferredAlignment(const ::mlir::DataLayout &dataLayout,
275 ::mlir::DataLayoutEntryListRef params)
const {
279const llvm::fltSemantics &LongDoubleType::getFloatSemantics()
const {
280 return mlir::cast<cir::CIRFPTypeInterface>(getUnderlying())
281 .getFloatSemantics();
285LongDoubleType::getTypeSizeInBits(
const mlir::DataLayout &dataLayout,
286 mlir::DataLayoutEntryListRef params)
const {
287 return mlir::cast<mlir::DataLayoutTypeInterface>(getUnderlying())
288 .getTypeSizeInBits(dataLayout, params);
292LongDoubleType::getABIAlignment(
const mlir::DataLayout &dataLayout,
293 mlir::DataLayoutEntryListRef params)
const {
294 return mlir::cast<mlir::DataLayoutTypeInterface>(getUnderlying())
295 .getABIAlignment(dataLayout, params);
298uint64_t LongDoubleType::getPreferredAlignment(
299 const ::mlir::DataLayout &dataLayout,
300 mlir::DataLayoutEntryListRef params)
const {
301 return mlir::cast<mlir::DataLayoutTypeInterface>(getUnderlying())
302 .getPreferredAlignment(dataLayout, params);
306LongDoubleType::verify(function_ref<InFlightDiagnostic()> emitError,
307 mlir::Type underlying) {
308 if (!mlir::isa<DoubleType, FP80Type, FP128Type>(underlying)) {
309 emitError() <<
"invalid underlying type for long double";
321 return isa<cir::SingleType, cir::DoubleType, cir::LongDoubleType,
322 cir::FP80Type, cir::BF16Type, cir::FP16Type, cir::FP128Type>(t);
329FuncType FuncType::clone(TypeRange inputs, TypeRange results)
const {
330 assert(results.size() == 1 &&
"expected exactly one result type");
331 return get(llvm::to_vector(inputs), results[0], isVarArg());
339 if (succeeded(p.parseOptionalRParen()))
340 return mlir::success();
343 if (succeeded(p.parseOptionalEllipsis())) {
345 return p.parseRParen();
350 if (p.parseType(type))
351 return mlir::failure();
352 params.push_back(type);
353 while (succeeded(p.parseOptionalComma())) {
354 if (succeeded(p.parseOptionalEllipsis())) {
356 return p.parseRParen();
358 if (p.parseType(type))
359 return mlir::failure();
360 params.push_back(type);
363 return p.parseRParen();
368 llvm::interleaveComma(params, p,
369 [&p](mlir::Type type) { p.printType(type); });
379 return static_cast<detail::FuncTypeStorage *
>(
getImpl())->returnType;
382bool FuncType::isVoid()
const {
return mlir::isa<VoidType>(getReturnType()); }
389PointerType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout,
390 ::mlir::DataLayoutEntryListRef params)
const {
392 return llvm::TypeSize::getFixed(64);
396PointerType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
397 ::mlir::DataLayoutEntryListRef params)
const {
402uint64_t PointerType::getPreferredAlignment(
403 const ::mlir::DataLayout &dataLayout,
404 ::mlir::DataLayoutEntryListRef params)
const {
410PointerType::verify(llvm::function_ref<mlir::InFlightDiagnostic()> emitError,
411 mlir::Type pointee) {
413 return mlir::success();
420void CIRDialect::registerTypes() {
423#define GET_TYPEDEF_LIST
424#include "clang/CIR/Dialect/IR/CIROpsTypes.cpp.inc"
static void printFuncTypeArgs(mlir::AsmPrinter &p, mlir::ArrayRef< mlir::Type > params, bool isVarArg)
static mlir::ParseResult parseFuncTypeArgs(mlir::AsmParser &p, llvm::SmallVector< mlir::Type > ¶ms, bool &isVarArg)
static LiveVariablesImpl & getImpl(void *x)
bool isAnyFloatingPointType(mlir::Type t)
float __ovld __cnfn sign(float)
Returns 1.0 if x > 0, -0.0 if x = -0.0, +0.0 if x = +0.0, or -1.0 if x < 0.