clang 24.0.0git
CIRDialect.h
Go to the documentation of this file.
1//===- CIRDialect.h - CIR dialect -------------------------------*- C++ -*-===//
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 declares the CIR dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CLANG_CIR_DIALECT_IR_CIRDIALECT_H
14#define CLANG_CIR_DIALECT_IR_CIRDIALECT_H
15
16#include "mlir/IR/Builders.h"
17#include "mlir/IR/BuiltinOps.h"
18#include "mlir/IR/BuiltinTypes.h"
19#include "mlir/IR/Dialect.h"
20#include "mlir/IR/OpDefinition.h"
21#include "mlir/Interfaces/CallInterfaces.h"
22#include "mlir/Interfaces/ControlFlowInterfaces.h"
23#include "mlir/Interfaces/FunctionInterfaces.h"
24#include "mlir/Interfaces/InferTypeOpInterface.h"
25#include "mlir/Interfaces/LoopLikeInterface.h"
26#include "mlir/Interfaces/MemorySlotInterfaces.h"
27#include "mlir/Interfaces/SideEffectInterfaces.h"
28
30#include "clang/CIR/Dialect/IR/CIROpsDialect.h.inc"
36
38 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)>;
39using BuilderOpStateCallbackRef = llvm::function_ref<void(
40 mlir::OpBuilder &, mlir::Location, mlir::OperationState &)>;
41
42namespace cir {
43void buildTerminatedBody(mlir::OpBuilder &builder, mlir::Location loc);
44
45/// The process floating-point environment, including its rounding mode and
46/// exception state.
48 : public mlir::SideEffects::Resource::Base<
49 FloatingPointEnvironmentResource> {
50 mlir::StringRef getName() const final { return "FloatingPointEnvironment"; }
51 bool isAddressable() const final { return false; }
52};
53
54template <typename ConcreteType>
55class FenvOpTrait : public mlir::OpTrait::TraitBase<ConcreteType, FenvOpTrait> {
56public:
57 mlir::Speculation::Speculatability getSpeculatability() {
58 // Masked exceptions cannot trap. When strict_except is false, exception
59 // side effects are non-deterministic, so speculation is still safe.
60 FPEnvConstrainedOpInterface fenvOp = getFenvOp();
61 if (fenvOp.getFenvExceptionMode() == cir::FPExceptionMode::Masked &&
62 !fenvOp.getFenvStrictExcept())
63 return mlir::Speculation::Speculatable;
64
65 return mlir::Speculation::NotSpeculatable;
66 }
67
70 if (!getFenvOp().getFenvAttr())
71 return;
72 effects.emplace_back(mlir::MemoryEffects::Read::get(),
73 FloatingPointEnvironmentResource::get());
74 effects.emplace_back(mlir::MemoryEffects::Write::get(),
75 FloatingPointEnvironmentResource::get());
76 }
77
78private:
79 FPEnvConstrainedOpInterface getFenvOp() {
80 return mlir::cast<FPEnvConstrainedOpInterface>(this->getOperation());
81 }
82};
83
84/// Look up the RecordLayoutAttr for a named record in the module's
85/// cir.record_layouts dictionary. Asserts if the entry is missing.
86RecordLayoutAttr getRecordLayout(mlir::ModuleOp mod, mlir::StringAttr name);
87
88/// Same lookup as getRecordLayout, but returns a null attribute instead of
89/// asserting when the record has no layout entry.
90RecordLayoutAttr tryGetRecordLayout(mlir::ModuleOp mod, mlir::StringAttr name);
91} // namespace cir
92
93// TableGen'erated files for MLIR dialects require that a macro be defined when
94// they are included. GET_OP_CLASSES tells the file to define the classes for
95// the operations of that dialect.
96#define GET_OP_CLASSES
97#include "clang/CIR/Dialect/IR/CIROps.h.inc"
98
99#endif // CLANG_CIR_DIALECT_IR_CIRDIALECT_H
llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> BuilderCallbackRef
Definition CIRDialect.h:37
llvm::function_ref< void( mlir::OpBuilder &, mlir::Location, mlir::OperationState &)> BuilderOpStateCallbackRef
Definition CIRDialect.h:39
mlir::Speculation::Speculatability getSpeculatability()
Definition CIRDialect.h:57
void getEffects(llvm::SmallVectorImpl< mlir::MemoryEffects::EffectInstance > &effects)
Definition CIRDialect.h:68
RecordLayoutAttr tryGetRecordLayout(mlir::ModuleOp mod, mlir::StringAttr name)
Same lookup as getRecordLayout, but returns a null attribute instead of asserting when the record has...
Definition CIRAttrs.cpp:923
RecordLayoutAttr getRecordLayout(mlir::ModuleOp mod, mlir::StringAttr name)
Look up the RecordLayoutAttr for a named record in the module's cir.record_layouts dictionary.
Definition CIRAttrs.cpp:934
void buildTerminatedBody(mlir::OpBuilder &builder, mlir::Location loc)
The process floating-point environment, including its rounding mode and exception state.
Definition CIRDialect.h:49
mlir::StringRef getName() const final
Definition CIRDialect.h:50