9#ifndef LLVM_CLANG_CIR_DIALECT_BUILDER_CIRBASEBUILDER_H
10#define LLVM_CLANG_CIR_DIALECT_BUILDER_CIRBASEBUILDER_H
18#include "llvm/ADT/STLForwardCompat.h"
19#include "llvm/IR/FPEnv.h"
20#include "llvm/Support/ErrorHandling.h"
22#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
23#include "mlir/IR/Builders.h"
24#include "mlir/IR/BuiltinAttributes.h"
25#include "mlir/IR/Location.h"
26#include "mlir/IR/OperationSupport.h"
27#include "mlir/IR/Types.h"
40 llvm::to_underlying(b));
45 llvm::to_underlying(b));
68 :
mlir::OpBuilder(&mlirContext) {}
72 const llvm::APInt &val) {
73 return cir::ConstantOp::create(*
this, loc, cir::IntAttr::get(typ, val));
76 cir::ConstantOp
getConstant(mlir::Location loc, mlir::TypedAttr attr) {
77 return cir::ConstantOp::create(*
this, loc, attr);
82 return getConstant(loc, cir::IntAttr::get(ty, value));
85 mlir::Value
getSignedInt(mlir::Location loc, int64_t val,
unsigned numBits) {
86 auto type = cir::IntType::get(getContext(), numBits,
true);
88 llvm::APInt(numBits, val,
true));
93 auto type = cir::IntType::get(getContext(), numBits,
false);
103 assert(mlir::isa<cir::PointerType>(t) &&
"expected cir.ptr");
108 return cir::DataMemberAttr::get(ty);
112 if (mlir::isa<cir::IntType>(ty))
113 return cir::IntAttr::get(ty, 0);
114 if (cir::isAnyFloatingPointType(ty))
115 return cir::FPAttr::getZero(ty);
116 if (
auto complexType = mlir::dyn_cast<cir::ComplexType>(ty))
117 return cir::ZeroAttr::get(complexType);
118 if (
auto arrTy = mlir::dyn_cast<cir::ArrayType>(ty))
119 return cir::ZeroAttr::get(arrTy);
120 if (
auto vecTy = mlir::dyn_cast<cir::VectorType>(ty))
121 return cir::ZeroAttr::get(vecTy);
122 if (
auto ptrTy = mlir::dyn_cast<cir::PointerType>(ty))
124 if (
auto recordTy = mlir::dyn_cast<cir::RecordType>(ty))
125 return cir::ZeroAttr::get(recordTy);
126 if (
auto dataMemberTy = mlir::dyn_cast<cir::DataMemberType>(ty))
128 if (
auto methodTy = mlir::dyn_cast<cir::MethodType>(ty))
130 if (
auto vptrTy = mlir::dyn_cast<cir::VPtrType>(ty))
131 return cir::ZeroAttr::get(vptrTy);
132 if (mlir::isa<cir::BoolType>(ty)) {
136 llvm_unreachable(
"Zero initializer for given type is NYI");
139 cir::ConstantOp
getBool(
bool state, mlir::Location loc) {
140 return cir::ConstantOp::create(*
this, loc,
getCIRBoolAttr(state));
145 cir::BoolType
getBoolTy() {
return cir::BoolType::get(getContext()); }
146 cir::VoidType
getVoidTy() {
return cir::VoidType::get(getContext()); }
149 return cir::IntType::get(getContext(), n,
false);
153 if (
auto intType = mlir::dyn_cast<cir::IntTypeInterface>(eltTy))
154 return intType.getWidth();
155 if (
auto floatType = mlir::dyn_cast<cir::FPTypeInterface>(eltTy))
156 return floatType.getWidth();
158 llvm_unreachable(
"Unsupported type in getCIRIntOrFloatBitWidth");
161 return cir::IntType::get(getContext(), n,
true);
165 return cir::PointerType::get(ty);
169 mlir::ptr::MemorySpaceAttrInterface as) {
170 return cir::PointerType::get(ty, as);
177 mlir::ptr::MemorySpaceAttrInterface addrSpaceAttr =
183 return getPointerTo(cir::VoidType::get(getContext()), langAS);
186 cir::PointerType
getVoidPtrTy(mlir::ptr::MemorySpaceAttrInterface as) {
187 return getPointerTo(cir::VoidType::get(getContext()), as);
190 cir::MethodAttr
getMethodAttr(cir::MethodType ty, cir::FuncOp methodFuncOp) {
191 auto methodFuncSymbolRef = mlir::FlatSymbolRefAttr::get(methodFuncOp);
192 return cir::MethodAttr::get(ty, methodFuncSymbolRef);
196 return cir::MethodAttr::get(ty);
200 return cir::BoolAttr::get(getContext(), state);
208 auto resultComplexTy = cir::ComplexType::get(real.getType());
209 return cir::ComplexCreateOp::create(*
this, loc, resultComplexTy, real,
214 auto resultType = operand.getType();
215 if (
auto complexResultType = mlir::dyn_cast<cir::ComplexType>(resultType))
216 resultType = complexResultType.getElementType();
217 return cir::ComplexRealOp::create(*
this, loc, resultType, operand);
221 auto resultType = operand.getType();
222 if (
auto complexResultType = mlir::dyn_cast<cir::ComplexType>(resultType))
223 resultType = complexResultType.getElementType();
224 return cir::ComplexImagOp::create(*
this, loc, resultType, operand);
228 return cir::ComplexConjOp::create(*
this, loc, operand.getType(), operand);
232 bool isVolatile =
false, uint64_t alignment = 0) {
234 return cir::LoadOp::create(*
this, loc, ptr,
false, isVolatile,
235 alignmentAttr, cir::SyncScopeKindAttr{},
236 cir::MemOrderAttr{});
240 uint64_t alignment) {
241 return createLoad(loc, ptr,
false, alignment);
244 mlir::Value
createNot(mlir::Location loc, mlir::Value value) {
245 return cir::NotOp::create(*
this, loc, value);
255 llvm::function_ref<
void(mlir::OpBuilder &, mlir::Location)> condBuilder,
256 llvm::function_ref<
void(mlir::OpBuilder &, mlir::Location)> bodyBuilder) {
257 return cir::DoWhileOp::create(*
this, loc, condBuilder, bodyBuilder);
263 llvm::function_ref<
void(mlir::OpBuilder &, mlir::Location)> condBuilder,
264 llvm::function_ref<
void(mlir::OpBuilder &, mlir::Location)> bodyBuilder) {
265 return cir::WhileOp::create(*
this, loc, condBuilder, bodyBuilder);
271 llvm::function_ref<
void(mlir::OpBuilder &, mlir::Location)> condBuilder,
272 llvm::function_ref<
void(mlir::OpBuilder &, mlir::Location)> bodyBuilder,
273 llvm::function_ref<
void(mlir::OpBuilder &, mlir::Location)> stepBuilder) {
274 return cir::ForOp::create(*
this, loc, condBuilder, bodyBuilder,
280 return cir::BreakOp::create(*
this, loc);
285 return cir::ContinueOp::create(*
this, loc);
288 mlir::Value
createInc(mlir::Location loc, mlir::Value input,
290 return cir::IncOp::create(*
this, loc, input, nsw);
293 mlir::Value
createDec(mlir::Location loc, mlir::Value input,
295 return cir::DecOp::create(*
this, loc, input, nsw);
300 return cir::MinusOp::create(*
this, loc, input, nsw);
304 return cir::ConstPtrAttr::get(type, getI64IntegerAttr(value));
307 mlir::Value
createAlloca(mlir::Location loc, cir::PointerType addrType,
308 mlir::Type type, llvm::StringRef name,
309 mlir::IntegerAttr alignment,
310 mlir::Value dynAllocSize) {
311 return cir::AllocaOp::create(*
this, loc, addrType, type, name, alignment,
315 mlir::Value
createAlloca(mlir::Location loc, cir::PointerType addrType,
316 mlir::Type type, llvm::StringRef name,
318 mlir::Value dynAllocSize) {
320 return createAlloca(loc, addrType, type, name, alignmentAttr, dynAllocSize);
323 mlir::Value
createAlloca(mlir::Location loc, cir::PointerType addrType,
324 mlir::Type type, llvm::StringRef name,
325 mlir::IntegerAttr alignment) {
326 return cir::AllocaOp::create(*
this, loc, addrType, type, name, alignment);
329 mlir::Value
createAlloca(mlir::Location loc, cir::PointerType addrType,
330 mlir::Type type, llvm::StringRef name,
333 return createAlloca(loc, addrType, type, name, alignmentAttr);
339 mlir::ArrayAttr indices = {}) {
340 cir::PointerType type =
getPointerTo(globalOp.getSymType());
346 cir::GlobalOp globalOp,
347 mlir::ArrayAttr indices = {}) {
348 auto symbol = mlir::FlatSymbolRefAttr::get(globalOp.getSymNameAttr());
349 return cir::GlobalViewAttr::get(type, symbol, indices);
355 cir::GlobalOp globalOp,
358 for (int64_t ind : indices)
359 attrs.push_back(getI64IntegerAttr(ind));
360 mlir::ArrayAttr arAttr = mlir::ArrayAttr::get(getContext(), attrs);
365 bool threadLocal =
false) {
367 return cir::GetGlobalOp::create(*
this, loc,
369 global.getSymNameAttr(), threadLocal);
373 bool threadLocal =
false) {
379 bool isVolatile =
false,
380 bool skipTailPadding =
false) {
381 return cir::CopyOp::create(*
this, dst.getLoc(), dst, src, isVolatile,
385 cir::StoreOp
createStore(mlir::Location loc, mlir::Value val, mlir::Value dst,
386 bool isVolatile =
false,
387 mlir::IntegerAttr align = {},
388 cir::SyncScopeKindAttr scope = {},
389 cir::MemOrderAttr order = {}) {
390 if (mlir::cast<cir::PointerType>(dst.getType()).getPointee() !=
393 return cir::StoreOp::create(*
this, loc, val, dst, isVolatile, align, scope,
400 if (boolTy != mlir::cast<cir::PointerType>(addr.getType()).getPointee())
406 mlir::Value flag =
getBool(val, loc);
410 [[nodiscard]] cir::GlobalOp
412 mlir::StringRef name, mlir::Type type,
bool isConstant,
413 cir::GlobalLinkageKind linkage,
414 mlir::ptr::MemorySpaceAttrInterface addrSpace) {
415 mlir::OpBuilder::InsertionGuard guard(*
this);
416 setInsertionPointToStart(mlirModule.getBody());
417 return cir::GlobalOp::create(*
this, loc, name, type, isConstant, addrSpace,
422 mlir::Value base, llvm::StringRef name,
424 return cir::GetMemberOp::create(*
this, loc, resultTy, base, name, index);
431 return cir::LoadOp::create(*
this, loc, addr,
false,
432 false, alignmentAttr,
437 mlir::Value stride) {
438 return cir::PtrStrideOp::create(*
this, loc, base.getType(), base, stride);
445 cir::CallOp
createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee,
446 mlir::Type returnType, mlir::ValueRange operands,
450 auto op = cir::CallOp::create(*
this, loc, callee, returnType, operands);
453 if (!argAttrs.empty()) {
454 llvm::SmallVector<mlir::Attribute> argDictAttrs;
455 argDictAttrs.reserve(argAttrs.size());
458 argAttrs, std::back_inserter(argDictAttrs),
459 [
this](llvm::ArrayRef<mlir::NamedAttribute> singleArgAttrs) {
460 return mlir::DictionaryAttr::get(getContext(), singleArgAttrs);
463 op.setArgAttrsAttr(mlir::ArrayAttr::get(getContext(), argDictAttrs));
466 if (!resAttrs.empty()) {
467 auto resultDictAttr = mlir::DictionaryAttr::get(getContext(), resAttrs);
468 op.setResAttrsAttr(mlir::ArrayAttr::get(getContext(), resultDictAttr));
474 mlir::ValueRange operands,
478 return createCallOp(loc, mlir::SymbolRefAttr::get(callee),
479 callee.getFunctionType().getReturnType(), operands,
480 attrs, argAttrs, resAttrs);
485 cir::FuncType funcType, mlir::ValueRange operands,
489 llvm::SmallVector<mlir::Value> resOperands{indirectTarget};
490 resOperands.append(operands.begin(), operands.end());
492 return createCallOp(loc, mlir::SymbolRefAttr(), funcType.getReturnType(),
493 resOperands, attrs, argAttrs, resAttrs);
496 cir::CallOp
createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee,
497 mlir::ValueRange operands = mlir::ValueRange(),
501 return createCallOp(loc, callee, cir::VoidType(), operands, attrs, argAttrs,
510 mlir::Value src, mlir::Type newTy) {
511 if (newTy == src.getType())
513 return cir::CastOp::create(*
this, loc, newTy,
kind, src);
518 if (newTy == src.getType())
525 if (newTy == src.getType())
533 return createCast(cir::CastKind::integral, src, newTy);
537 return createCast(cir::CastKind::int_to_ptr, src, newTy);
541 return createCast(cir::CastKind::ptr_to_int, src, newTy);
549 return createCast(cir::CastKind::bool_to_int, src, newTy);
553 return createCast(cir::CastKind::bitcast, src, newTy);
558 return createCast(loc, cir::CastKind::bitcast, src, newTy);
562 assert(mlir::isa<cir::PointerType>(src.getType()) &&
"expected ptr src");
563 cir::PointerType srcPtrTy = mlir::cast<cir::PointerType>(src.getType());
569 mlir::Value nullPtr =
getNullPtr(ptr.getType(), ptr.getLoc());
570 return createCompare(ptr.getLoc(), cir::CmpOpKind::eq, ptr, nullPtr);
574 mlir::Value nullPtr =
getNullPtr(ptr.getType(), ptr.getLoc());
575 return createCompare(ptr.getLoc(), cir::CmpOpKind::ne, ptr, nullPtr);
580 return createCast(loc, cir::CastKind::address_space, src, newTy);
595 return cir::VecExtractOp::create(*
this, loc, vec, idxVal);
599 mlir::Value newElt, uint64_t idx) {
602 return cir::VecInsertOp::create(*
this, loc, vec, newElt, idxVal);
606 auto resTy = cir::BoolType::get(getContext());
607 return cir::SignBitOp::create(*
this, loc, resTy, val);
616 llvm::APInt val = llvm::APInt::getLowBitsSet(size, bits);
617 auto type = cir::IntType::get(getContext(), size,
false);
621 mlir::Value
createAnd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
622 return cir::AndOp::create(*
this, loc, lhs, rhs);
625 mlir::Value
createOr(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
626 return cir::OrOp::create(*
this, loc, lhs, rhs);
630 mlir::Value trueValue, mlir::Value falseValue) {
631 assert(trueValue.getType() == falseValue.getType() &&
632 "trueValue and falseValue should have the same type");
633 return cir::SelectOp::create(*
this, loc, trueValue.getType(),
condition,
634 trueValue, falseValue);
647 mlir::Value
createMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
649 auto op = cir::MulOp::create(*
this, loc, lhs, rhs);
663 mlir::Value
createSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
665 auto op = cir::SubOp::create(*
this, loc, lhs, rhs);
682 mlir::Value
createAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
684 auto op = cir::AddOp::create(*
this, loc, lhs, rhs);
701 mlir::Value
createDiv(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
702 return cir::DivOp::create(*
this, loc, lhs, rhs);
705 mlir::Value
createRem(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
706 return cir::RemOp::create(*
this, loc, lhs, rhs);
709 mlir::Value
createFAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
713 return cir::FAddOp::create(*
this, loc, lhs, rhs);
716 mlir::Value
createFSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
720 return cir::FSubOp::create(*
this, loc, lhs, rhs);
723 mlir::Value
createFMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
727 return cir::FMulOp::create(*
this, loc, lhs, rhs);
730 mlir::Value
createFDiv(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
734 return cir::FDivOp::create(*
this, loc, lhs, rhs);
737 mlir::Value
createFRem(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
741 return cir::FRemOp::create(*
this, loc, lhs, rhs);
744 mlir::Value
createFNeg(mlir::Location loc, mlir::Value operand) {
745 assert(cir::isFPOrVectorOfFPType(operand.getType()) &&
746 "expected floating-point or vector-of-float type");
750 return cir::FNegOp::create(*
this, loc, operand);
753 mlir::Value
createXor(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
754 return cir::XorOp::create(*
this, loc, lhs, rhs);
757 mlir::Value
createMax(mlir::Location loc, mlir::Value lhs, mlir::Value rhs) {
758 return cir::MaxOp::create(*
this, loc, lhs, rhs);
762 mlir::Value lhs, mlir::Value rhs) {
763 return cir::CmpOp::create(*
this, loc,
kind, lhs, rhs);
767 mlir::Value lhs, mlir::Value rhs) {
768 VectorType vecCast = mlir::cast<VectorType>(lhs.getType());
771 VectorType integralVecTy =
772 cir::VectorType::get(integralTy, vecCast.getSize());
773 return cir::VecCmpOp::create(*
this, loc, integralVecTy,
kind, lhs, rhs);
776 mlir::Value
createIsNaN(mlir::Location loc, mlir::Value operand) {
777 return createCompare(loc, cir::CmpOpKind::ne, operand, operand);
780 mlir::Value
createShift(mlir::Location loc, mlir::Value lhs, mlir::Value rhs,
782 return cir::ShiftOp::create(*
this, loc, lhs.getType(), lhs, rhs,
787 const llvm::APInt &rhs,
bool isShiftLeft) {
792 mlir::Value
createShift(mlir::Location loc, mlir::Value lhs,
unsigned bits,
794 auto width = mlir::dyn_cast<cir::IntType>(lhs.getType()).getWidth();
795 auto shift = llvm::APInt(width, bits);
821 return cir::FuncType::get(llvm::to_vector(argTypes),
getVoidTy());
835 std::find_if(block->rbegin(), block->rend(), [](mlir::Operation &op) {
836 return mlir::isa<cir::AllocaOp, cir::LabelOp>(&op);
839 if (last != block->rend())
840 return OpBuilder::InsertPoint(block, ++mlir::Block::iterator(&*last));
841 return OpBuilder::InsertPoint(block, block->begin());
862 return alignment ? getI64IntegerAttr(alignment) : mlir::IntegerAttr();
877 cir::ConstantOp
getNullPtr(mlir::Type ty, mlir::Location loc) {
888 cir::YieldOp
createYield(mlir::Location loc, mlir::ValueRange value = {}) {
889 return cir::YieldOp::create(*
this, loc, value);
898 mlir::Value objectPtr) {
901 mlir::cast<cir::MethodType>(method.getType()).getMemberFuncTy();
902 auto methodFuncInputTypes = methodFuncTy.getInputs();
904 auto objectPtrTy = mlir::cast<cir::PointerType>(objectPtr.getType());
905 mlir::Type adjustedThisTy =
getVoidPtrTy(objectPtrTy.getAddrSpace());
910 if (methodFuncInputTypes.size() > 1)
911 calleeFuncInputTypes.insert(calleeFuncInputTypes.end(),
912 methodFuncInputTypes.begin() + 1,
913 methodFuncInputTypes.end());
914 cir::FuncType calleeFuncTy =
915 methodFuncTy.clone(calleeFuncInputTypes, methodFuncTy.getReturnType());
920 auto op = cir::GetMethodOp::create(*
this, loc, calleeTy, adjustedThisTy,
922 return {op.getCallee(), op.getAdjustedThis()};
Provides definitions for the various language-specific address spaces.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a an optional score condition
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
mlir::Value createNSWSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::ConstantOp getBool(bool state, mlir::Location loc)
mlir::Value createShift(mlir::Location loc, mlir::Value lhs, unsigned bits, bool isShiftLeft)
cir::StoreOp createFlagStore(mlir::Location loc, bool val, mlir::Value dst)
cir::WhileOp createWhile(mlir::Location loc, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> condBuilder, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> bodyBuilder)
Create a while operation.
mlir::Value createDiv(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::BreakOp createBreak(mlir::Location loc)
Create a break operation.
mlir::TypedAttr getConstNullPtrAttr(mlir::Type t)
cir::PointerType getVoidPtrTy(mlir::ptr::MemorySpaceAttrInterface as)
mlir::IntegerAttr getAlignmentAttr(int64_t alignment)
mlir::Value createDec(mlir::Location loc, mlir::Value input, bool nsw=false)
mlir::Value createShift(mlir::Location loc, mlir::Value lhs, const llvm::APInt &rhs, bool isShiftLeft)
mlir::Value getConstAPInt(mlir::Location loc, mlir::Type typ, const llvm::APInt &val)
cir::GlobalViewAttr getGlobalViewAttr(cir::PointerType type, cir::GlobalOp globalOp, mlir::ArrayAttr indices={})
Get constant address of a global variable as an MLIR attribute.
mlir::Value createCast(cir::CastKind kind, mlir::Value src, mlir::Type newTy)
mlir::Value createLogicalOr(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createShift(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, bool isShiftLeft)
mlir::Value createSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowBehavior ob=OverflowBehavior::None)
cir::ConditionOp createCondition(mlir::Value condition)
Create a loop condition.
mlir::Value createLowBitsSet(mlir::Location loc, unsigned size, unsigned bits)
mlir::Value createInc(mlir::Location loc, mlir::Value input, bool nsw=false)
cir::CopyOp createCopy(mlir::Value dst, mlir::Value src, bool isVolatile=false, bool skipTailPadding=false)
Create a copy with inferred length.
mlir::Value createNSWAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::GlobalViewAttr getGlobalViewAttr(cir::GlobalOp globalOp, mlir::ArrayAttr indices={})
Get constant address of a global variable as an MLIR attribute.
cir::MethodAttr getMethodAttr(cir::MethodType ty, cir::FuncOp methodFuncOp)
cir::VoidType getVoidTy()
cir::ConstantOp getNullValue(mlir::Type ty, mlir::Location loc)
cir::BoolAttr getCIRBoolAttr(bool state)
mlir::Value createBoolToInt(mlir::Value src, mlir::Type newTy)
cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr)
cir::MethodAttr getNullMethodAttr(cir::MethodType ty)
mlir::Value createNUWAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createOr(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createPtrIsNull(mlir::Value ptr)
mlir::Value createShiftLeft(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::SignBitOp createSignBit(mlir::Location loc, mlir::Value val)
mlir::Value createCast(mlir::Location loc, cir::CastKind kind, mlir::Value src, mlir::Type newTy)
mlir::IntegerAttr getSizeFromCharUnits(clang::CharUnits size)
cir::PointerType getVoidFnPtrTy(mlir::TypeRange argTypes={})
Returns void (*)(T...) as a cir::PointerType.
cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base, mlir::Value stride)
mlir::Value createIntToPtr(mlir::Value src, mlir::Type newTy)
mlir::Value createRem(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::ForOp createFor(mlir::Location loc, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> condBuilder, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> bodyBuilder, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> stepBuilder)
Create a for operation.
static OpBuilder::InsertPoint getBestAllocaInsertPoint(mlir::Block *block)
mlir::Value createPtrToInt(mlir::Value src, mlir::Type newTy)
mlir::Value createFDiv(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createNUWSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::ConstantOp getFalse(mlir::Location loc)
cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee, mlir::ValueRange operands=mlir::ValueRange(), llvm::ArrayRef< mlir::NamedAttribute > attrs={}, llvm::ArrayRef< mlir::NamedAttrList > argAttrs={}, llvm::ArrayRef< mlir::NamedAttribute > resAttrs={})
mlir::Value createAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowBehavior ob=OverflowBehavior::None)
cir::GetMemberOp createGetMember(mlir::Location loc, mlir::Type resultTy, mlir::Value base, llvm::StringRef name, unsigned index)
cir::PointerType getPointerTo(mlir::Type ty)
mlir::Value createFNeg(mlir::Location loc, mlir::Value operand)
mlir::Value createNot(mlir::Value value)
mlir::Value createFAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createComplexImag(mlir::Location loc, mlir::Value operand)
cir::ConstantOp getTrue(mlir::Location loc)
mlir::Value createNSWMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc)
cir::GetGlobalOp createGetGlobal(cir::GlobalOp global, bool threadLocal=false)
cir::IntType getUIntNTy(int n)
cir::DoWhileOp createDoWhile(mlir::Location loc, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> condBuilder, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> bodyBuilder)
Create a do-while operation.
mlir::Value createNUWAMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createPtrBitcast(mlir::Value src, mlir::Type newPointeeTy)
cir::GetGlobalOp createGetGlobal(mlir::Location loc, cir::GlobalOp global, bool threadLocal=false)
mlir::Value createShiftLeft(mlir::Location loc, mlir::Value lhs, unsigned bits)
mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType, mlir::Type type, llvm::StringRef name, clang::CharUnits alignment, mlir::Value dynAllocSize)
mlir::Value getSignedInt(mlir::Location loc, int64_t val, unsigned numBits)
mlir::Value createMax(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createAnd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::PointerType getPointerTo(mlir::Type ty, clang::LangAS langAS)
mlir::Value createExtractElement(mlir::Location loc, mlir::Value vec, uint64_t idx)
cir::VecCmpOp createVecCompare(mlir::Location loc, cir::CmpOpKind kind, mlir::Value lhs, mlir::Value rhs)
mlir::Value createIntCast(mlir::Value src, mlir::Type newTy)
mlir::Value createInsertElement(mlir::Location loc, mlir::Value vec, mlir::Value newElt, uint64_t idx)
mlir::Value createBitcast(mlir::Value src, mlir::Type newTy)
mlir::Value createFMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
CIRBaseBuilderTy(mlir::MLIRContext &mlirContext)
mlir::Value createBitcast(mlir::Location loc, mlir::Value src, mlir::Type newTy)
cir::FuncType getVoidFnTy(mlir::TypeRange argTypes={})
Returns void (T...) as a cir::FuncType.
mlir::TypedAttr getNullDataMemberAttr(cir::DataMemberType ty)
cir::CmpOp createCompare(mlir::Location loc, cir::CmpOpKind kind, mlir::Value lhs, mlir::Value rhs)
mlir::IntegerAttr getAlignmentAttr(clang::CharUnits alignment)
mlir::Value createNot(mlir::Location loc, mlir::Value value)
mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType, mlir::Type type, llvm::StringRef name, mlir::IntegerAttr alignment)
mlir::Value createSelect(mlir::Location loc, mlir::Value condition, mlir::Value trueValue, mlir::Value falseValue)
cir::ContinueOp createContinue(mlir::Location loc)
Create a continue operation.
mlir::Value createMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowBehavior ob=OverflowBehavior::None)
cir::PointerType getPointerTo(mlir::Type ty, mlir::ptr::MemorySpaceAttrInterface as)
mlir::TypedAttr getZeroInitAttr(mlir::Type ty)
cir::LoadOp createLoad(mlir::Location loc, mlir::Value ptr, bool isVolatile=false, uint64_t alignment=0)
mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType, mlir::Type type, llvm::StringRef name, clang::CharUnits alignment)
mlir::Value createMinus(mlir::Location loc, mlir::Value input, bool nsw=false)
CIRBaseBuilderTy(mlir::OpBuilder &builder)
mlir::Value createPtrIsNotNull(mlir::Value ptr)
static unsigned getCIRIntOrFloatBitWidth(mlir::Type eltTy)
cir::CallOp createIndirectCallOp(mlir::Location loc, mlir::Value indirectTarget, cir::FuncType funcType, mlir::ValueRange operands, llvm::ArrayRef< mlir::NamedAttribute > attrs={}, llvm::ArrayRef< mlir::NamedAttrList > argAttrs={}, llvm::ArrayRef< mlir::NamedAttribute > resAttrs={})
cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty, int64_t value)
mlir::Value createComplexCreate(mlir::Location loc, mlir::Value real, mlir::Value imag)
mlir::Value createBoolIntToIntCast(mlir::Value src, mlir::Type newTy)
mlir::Value createAddrSpaceCast(mlir::Value src, mlir::Type newTy)
mlir::Value createComplexConj(mlir::Location loc, mlir::Value operand)
mlir::Value createPtrToBoolCast(mlir::Value v)
cir::BoolAttr getTrueAttr()
cir::PointerType getVoidPtrTy(clang::LangAS langAS=clang::LangAS::Default)
cir::GlobalViewAttr getGlobalViewAttr(cir::PointerType type, cir::GlobalOp globalOp, llvm::ArrayRef< int64_t > indices)
Get constant address of a global variable as an MLIR attribute.
mlir::Value createFRem(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createShiftRight(mlir::Location loc, mlir::Value lhs, unsigned bits)
mlir::Value createIsNaN(mlir::Location loc, mlir::Value operand)
cir::IntType getSIntNTy(int n)
mlir::Value createAlignedLoad(mlir::Location loc, mlir::Value ptr, uint64_t alignment)
mlir::TypedAttr getConstPtrAttr(mlir::Type type, int64_t value)
mlir::Value createAddrSpaceCast(mlir::Location loc, mlir::Value src, mlir::Type newTy)
cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee, mlir::Type returnType, mlir::ValueRange operands, llvm::ArrayRef< mlir::NamedAttribute > attrs={}, llvm::ArrayRef< mlir::NamedAttrList > argAttrs={}, llvm::ArrayRef< mlir::NamedAttribute > resAttrs={})
mlir::Value createDummyValue(mlir::Location loc, mlir::Type type, clang::CharUnits alignment)
cir::BoolAttr getFalseAttr()
mlir::Value createShiftRight(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::StoreOp createStore(mlir::Location loc, mlir::Value val, mlir::Value dst, bool isVolatile=false, mlir::IntegerAttr align={}, cir::SyncScopeKindAttr scope={}, cir::MemOrderAttr order={})
mlir::Value createXor(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::CallOp createCallOp(mlir::Location loc, cir::FuncOp callee, mlir::ValueRange operands, llvm::ArrayRef< mlir::NamedAttribute > attrs={}, llvm::ArrayRef< mlir::NamedAttrList > argAttrs={}, llvm::ArrayRef< mlir::NamedAttribute > resAttrs={})
cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value={})
Create a yield operation.
cir::ConstantOp getAlignment(mlir::Location loc, mlir::Type t, clang::CharUnits alignment)
mlir::Value createLogicalAnd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::GlobalOp createGlobal(mlir::ModuleOp mlirModule, mlir::Location loc, mlir::StringRef name, mlir::Type type, bool isConstant, cir::GlobalLinkageKind linkage, mlir::ptr::MemorySpaceAttrInterface addrSpace)
mlir::IntegerAttr getAlignmentAttr(llvm::Align alignment)
mlir::Value createFSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::LoadOp createFlagLoad(mlir::Location loc, mlir::Value addr)
Emit a load from an boolean flag variable.
mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType, mlir::Type type, llvm::StringRef name, mlir::IntegerAttr alignment, mlir::Value dynAllocSize)
cir::BoolType getBoolTy()
mlir::Value getUnsignedInt(mlir::Location loc, uint64_t val, unsigned numBits)
GetMethodResults createGetMethod(mlir::Location loc, mlir::Value method, mlir::Value objectPtr)
mlir::Value createComplexReal(mlir::Location loc, mlir::Value operand)
CharUnits - This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
constexpr OverflowBehavior operator|(OverflowBehavior a, OverflowBehavior b)
constexpr OverflowBehavior operator&(OverflowBehavior a, OverflowBehavior b)
constexpr OverflowBehavior & operator|=(OverflowBehavior &a, OverflowBehavior b)
constexpr OverflowBehavior & operator&=(OverflowBehavior &a, OverflowBehavior b)
mlir::ptr::MemorySpaceAttrInterface toCIRAddressSpaceAttr(mlir::MLIRContext &ctx, clang::LangAS langAS)
Convert an AST LangAS to the appropriate CIR address space attribute interface.
constexpr bool testFlag(OverflowBehavior ob, OverflowBehavior flag)
LangAS
Defines the address space values used by the address space qualifier of QualType.
static bool metaDataNode()
static bool addressSpace()
static bool targetCodeGenInfoGetNullPointer()
static bool fpConstraints()
static bool fastMathFlags()