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/OpDefinition.h"
20#include "mlir/Interfaces/SideEffectInterfaces.h"
21
23#include "clang/CIR/Dialect/IR/CIROpsDialect.h.inc"
29
30#include "llvm/TargetParser/Triple.h"
31
32#include <optional>
33
35 llvm::function_ref<void(mlir::OpBuilder &, mlir::Location)>;
36using BuilderOpStateCallbackRef = llvm::function_ref<void(
37 mlir::OpBuilder &, mlir::Location, mlir::OperationState &)>;
38
39namespace cir {
40void buildTerminatedBody(mlir::OpBuilder &builder, mlir::Location loc);
41
42/// The process floating-point environment, including its rounding mode and
43/// exception state.
45 : public mlir::SideEffects::Resource::Base<
46 FloatingPointEnvironmentResource> {
47 mlir::StringRef getName() const final { return "FloatingPointEnvironment"; }
48 bool isAddressable() const final { return false; }
49};
50
51template <typename ConcreteType>
52class FenvOpTrait : public mlir::OpTrait::TraitBase<ConcreteType, FenvOpTrait> {
53public:
54 mlir::Speculation::Speculatability getSpeculatability() {
55 // Masked exceptions cannot trap. When strict_except is false, exception
56 // side effects are non-deterministic, so speculation is still safe.
57 FPEnvConstrainedOpInterface fenvOp = getFenvOp();
58 if (fenvOp.getFenvExceptionMode() == cir::FPExceptionMode::Masked &&
59 !fenvOp.getFenvStrictExcept())
60 return mlir::Speculation::Speculatable;
61
62 return mlir::Speculation::NotSpeculatable;
63 }
64
67 if (!getFenvOp().getFenvAttr())
68 return;
69 effects.emplace_back(mlir::MemoryEffects::Read::get(),
70 FloatingPointEnvironmentResource::get());
71 effects.emplace_back(mlir::MemoryEffects::Write::get(),
72 FloatingPointEnvironmentResource::get());
73 }
74
75private:
76 FPEnvConstrainedOpInterface getFenvOp() {
77 return mlir::cast<FPEnvConstrainedOpInterface>(this->getOperation());
78 }
79};
80
81/// The properties of \p Op with every ODS-declared default applied. The
82/// aggregate op builders that take a `Properties` struct do not apply those
83/// defaults themselves, so callers of those builders have to do it here.
84template <typename Op>
85typename Op::Properties getDefaultProperties(mlir::MLIRContext *context) {
86 typename Op::Properties properties{};
87 Op::populateDefaultProperties(
88 mlir::OperationName(Op::getOperationName(), context), properties);
89 return properties;
90}
91
92/// Look up the RecordLayoutAttr for a named record in the module's
93/// cir.record_layouts dictionary. Asserts if the entry is missing.
94RecordLayoutAttr getRecordLayout(mlir::ModuleOp mod, mlir::StringAttr name);
95
96/// Same lookup as getRecordLayout, but returns a null attribute instead of
97/// asserting when the record has no layout entry.
98RecordLayoutAttr tryGetRecordLayout(mlir::ModuleOp mod, mlir::StringAttr name);
99
100/// Attempts to construct an llvm::Triple from a module's cir.triple attribute.
101std::optional<llvm::Triple> getTripleFromModule(mlir::ModuleOp mod);
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
119/// Whether the C++ vtables of \p module use the relative layout.
120bool usesRelativeVTables(mlir::ModuleOp mod);
121
122/// The size in bytes of an entry of a C++ vtable in \p module. Operations
123/// address vtable entries by index, so this is the one place that relates the
124/// index of an entry to its distance from the address point.
125uint64_t getVTableEntrySize(mlir::ModuleOp mod,
126 const mlir::DataLayout &dataLayout);
127} // namespace cir
128
129#endif // CLANG_CIR_DIALECT_IR_CIRDIALECT_H
llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> BuilderCallbackRef
Definition CIRDialect.h:34
llvm::function_ref< void( mlir::OpBuilder &, mlir::Location, mlir::OperationState &)> BuilderOpStateCallbackRef
Definition CIRDialect.h:36
mlir::Speculation::Speculatability getSpeculatability()
Definition CIRDialect.h:54
void getEffects(llvm::SmallVectorImpl< mlir::MemoryEffects::EffectInstance > &effects)
Definition CIRDialect.h:65
RecordLayoutAttr tryGetRecordLayout(mlir::ModuleOp mod, mlir::StringAttr name)
Same lookup as getRecordLayout, but returns a null attribute instead of asserting when the record has...
RecordLayoutAttr getRecordLayout(mlir::ModuleOp mod, mlir::StringAttr name)
Look up the RecordLayoutAttr for a named record in the module's cir.record_layouts dictionary.
Op::Properties getDefaultProperties(mlir::MLIRContext *context)
The properties of Op with every ODS-declared default applied.
Definition CIRDialect.h:85
uint64_t getVTableEntrySize(mlir::ModuleOp mod, const mlir::DataLayout &dataLayout)
The size in bytes of an entry of a C++ vtable in module.
void buildTerminatedBody(mlir::OpBuilder &builder, mlir::Location loc)
bool usesRelativeVTables(mlir::ModuleOp mod)
Whether the C++ vtables of module use the relative layout.
AllocaOp getUnderlyingAlloca(mlir::Value addr)
The alloca that defines addr, looking through casts that preserve the underlying storage.
std::optional< llvm::Triple > getTripleFromModule(mlir::ModuleOp mod)
Attempts to construct an llvm::Triple from a module's cir.triple attribute.
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
The process floating-point environment, including its rounding mode and exception state.
Definition CIRDialect.h:46
mlir::StringRef getName() const final
Definition CIRDialect.h:47