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/// The properties of \p Op with every ODS-declared default applied. The
85/// aggregate op builders that take a `Properties` struct do not apply those
86/// defaults themselves, so callers of those builders have to do it here.
87template <typename Op>
88typename Op::Properties getDefaultProperties(mlir::MLIRContext *context) {
89 typename Op::Properties properties{};
90 Op::populateDefaultProperties(
91 mlir::OperationName(Op::getOperationName(), context), properties);
92 return properties;
93}
94
95/// Look up the RecordLayoutAttr for a named record in the module's
96/// cir.record_layouts dictionary. Asserts if the entry is missing.
97RecordLayoutAttr getRecordLayout(mlir::ModuleOp mod, mlir::StringAttr name);
98
99/// Same lookup as getRecordLayout, but returns a null attribute instead of
100/// asserting when the record has no layout entry.
101RecordLayoutAttr tryGetRecordLayout(mlir::ModuleOp mod, mlir::StringAttr name);
102} // namespace cir
103
104// TableGen'erated files for MLIR dialects require that a macro be defined when
105// they are included. GET_OP_CLASSES tells the file to define the classes for
106// the operations of that dialect.
107#define GET_OP_CLASSES
108#include "clang/CIR/Dialect/IR/CIROps.h.inc"
109
110namespace cir {
111/// The alloca that defines \p addr, looking through casts that preserve the
112/// underlying storage. Null when the chain does not end at an alloca.
113///
114/// Use the result only to inspect the allocation, such as its alignment or
115/// its allocated type. Addressing has to keep using \p addr, whose type and
116/// address space may differ from the alloca's own result.
117AllocaOp getUnderlyingAlloca(mlir::Value addr);
118} // namespace cir
119
120#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:927
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:938
Op::Properties getDefaultProperties(mlir::MLIRContext *context)
The properties of Op with every ODS-declared default applied.
Definition CIRDialect.h:88
void buildTerminatedBody(mlir::OpBuilder &builder, mlir::Location loc)
AllocaOp getUnderlyingAlloca(mlir::Value addr)
The alloca that defines addr, looking through casts that preserve the underlying storage.
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