24#include "llvm/ADT/DenseSet.h"
25#include "llvm/ADT/STLExtras.h"
26#include "llvm/ADT/TypeSwitch.h"
36 op, [&](StringRef name,
Attribute &attr) { attrs.
set(name, attr); });
47 for (StringAttr name : inherentAttrNames)
50 attrs.
set(name, *attr);
64 << name <<
"' does not reference a valid LLVM function";
65 if (
func.isExternal())
66 return op->
emitOpError(
"'") << name <<
"' does not have a definition";
75 for (
const auto &en : llvm::enumerate(keywords)) {
84 p << stringifyLinkage(val.getLinkage());
88 val = LinkageAttr::get(
102 Region *body =
result.addRegion();
106LogicalResult ComdatOp::verifyRegions() {
107 Region &body = getBody();
108 for (Operation &op : body.
getOps())
109 if (!isa<ComdatSelectorOp>(op))
111 "only comdat selector symbols can appear in a comdat region");
121 bool isConstant, Linkage linkage, StringRef name,
122 Attribute value, uint64_t alignment,
unsigned addrSpace,
123 bool dsoLocal, ThreadLocalMode threadModel,
126 result.getOrAddProperties<Properties>().sym_name =
128 result.addAttribute(getGlobalTypeAttrName(
result.name), TypeAttr::get(type));
130 getTlsModeAttrName(
result.name),
131 ThreadLocalModeAttr::get(builder.
getContext(), threadModel));
136 result.addAttribute(getValueAttrName(
result.name), value);
141 result.addAttribute(getComdatAttrName(
result.name), comdat);
151 LinkageAttr::get(builder.
getContext(), linkage));
155 result.attributes.append(attrs.begin(), attrs.end());
157 if (!dbgExprs.empty())
159 ArrayAttr::get(builder.
getContext(), dbgExprs));
164template <
typename OpType>
166 p <<
' ' << stringifyLinkage(op.getLinkage()) <<
' ';
167 StringRef visibility = stringifyVisibility(op.getVisibility_());
168 if (!visibility.empty())
169 p << visibility <<
' ';
171 if (ThreadLocalMode mode = op.getTlsMode();
172 mode != ThreadLocalMode::NotThreadLocal) {
174 if (mode != ThreadLocalMode::GeneralDynamic)
175 p <<
'(' << mode <<
')';
179 if (
auto unnamedAddr = op.getUnnamedAddr()) {
180 StringRef str = stringifyUnnamedAddr(*unnamedAddr);
192 if (
auto value = getValueOrNull())
195 if (
auto comdat = getComdat())
196 p <<
" comdat(" << *comdat <<
')';
203 *
this, {getDsoLocalAttrName(), getExternallyInitializedAttrName(),
204 getAlignmentAttrName(), getAddrSpaceAttrName(),
205 getSectionAttrName(), getAssociatedAttrName(),
206 getAbsoluteSymbolAttrName(), getDbgExprsAttrName(),
207 getTargetSpecificAttrsAttrName(), getSymVisibilityAttrName()})
209 {getSymNameAttrName(), getGlobalTypeAttrName(), getConstantAttrName(),
210 getValueAttrName(), getLinkageAttrName(), getUnnamedAddrAttrName(),
211 getTlsModeAttrName(), getVisibility_AttrName(), getComdatAttrName()});
214 if (llvm::dyn_cast_or_null<StringAttr>(getValueOrNull()))
218 Region &initializer = getInitializerRegion();
219 if (!initializer.
empty()) {
226 std::optional<SymbolRefAttr> attr,
232 if (!isa_and_nonnull<ComdatSelectorOp>(comdatSelector))
233 return op->
emitError() <<
"expected comdat symbol";
243 WalkResult res = funcOp.walk([&](BlockTagOp blockTagOp) {
244 if (blockTags.contains(blockTagOp.getTag())) {
245 blockTagOp.emitError()
246 <<
"duplicate block tag '" << blockTagOp.getTag().getId()
247 <<
"' in the same function: ";
250 blockTags.insert(blockTagOp.getTag());
254 return failure(res.wasInterrupted());
259template <
typename OpType>
266 OpType::getLinkageAttrName(
result.name),
268 parser, LLVM::Linkage::External)));
271 result.addAttribute(OpType::getVisibility_AttrName(
result.name),
274 parser, LLVM::Visibility::Default)));
277 ThreadLocalMode threadModel = ThreadLocalMode::GeneralDynamic;
284 parser, ThreadLocalMode::NotThreadLocal);
285 if (threadModel == ThreadLocalMode::NotThreadLocal) {
286 parser.
emitError(kwLoc,
"invalid value for thread_local");
292 result.addAttribute(OpType::getTlsModeAttrName(
result.name),
293 ThreadLocalModeAttr::get(ctx, threadModel));
297 result.addAttribute(OpType::getUnnamedAddrAttrName(
result.name),
300 parser, LLVM::UnnamedAddr::None)));
338 SymbolRefAttr comdat;
343 result.addAttribute(getComdatAttrName(
result.name), comdat);
351 if (types.size() > 1)
356 if (
auto strAttr = llvm::dyn_cast_or_null<StringAttr>(value)) {
358 auto arrayType = LLVM::LLVMArrayType::get(IntegerType::get(context, 8),
359 strAttr.getValue().size());
360 types.push_back(arrayType);
363 "type can only be omitted for string globals");
374 TypeAttr::get(types[0]));
379 if (
auto intValue = llvm::dyn_cast<IntegerAttr>(value))
380 return intValue.getValue().isZero();
381 if (
auto fpValue = llvm::dyn_cast<FloatAttr>(value))
382 return fpValue.getValue().isZero();
383 if (
auto splatValue = llvm::dyn_cast<SplatElementsAttr>(value))
385 if (
auto elementsValue = llvm::dyn_cast<ElementsAttr>(value))
387 if (
auto arrayValue = llvm::dyn_cast<ArrayAttr>(value))
396LogicalResult GlobalOp::verify() {
398 ? !llvm::isa<LLVMVoidType, TokenType, LLVMMetadataType,
400 :
llvm::isa<PointerElementTypeInterface>(
getType());
403 "expects type to be a valid element type for an LLVM global");
405 return emitOpError(
"must appear at the module level");
407 if (
auto strAttr = llvm::dyn_cast_or_null<StringAttr>(getValueOrNull())) {
408 auto type = llvm::dyn_cast<LLVMArrayType>(
getType());
409 IntegerType elementType =
410 type ? llvm::dyn_cast<IntegerType>(type.getElementType()) :
nullptr;
411 if (!elementType || elementType.getWidth() != 8 ||
412 type.getNumElements() != strAttr.getValue().size())
414 "requires an i8 array type of the length equal to that of the string "
418 if (
auto targetExtType = dyn_cast<LLVMTargetExtType>(
getType())) {
419 if (!targetExtType.hasProperty(LLVMTargetExtType::CanBeGlobal))
421 <<
"this target extension type cannot be used in a global";
424 return emitOpError() <<
"global with target extension type can only be "
425 "initialized with zero-initializer";
428 if (getLinkage() == Linkage::Common) {
429 if (
Attribute value = getValueOrNull()) {
432 <<
"expected zero value for '"
433 << stringifyLinkage(Linkage::Common) <<
"' linkage";
438 if (getLinkage() == Linkage::Appending) {
439 if (!llvm::isa<LLVMArrayType>(
getType())) {
440 return emitOpError() <<
"expected array type for '"
441 << stringifyLinkage(Linkage::Appending)
446 std::optional<uint64_t> alignAttr = getAlignment();
447 if (alignAttr.has_value()) {
448 uint64_t value = alignAttr.value();
449 if (!llvm::isPowerOf2_64(value))
450 return emitError() <<
"alignment attribute is not a power of 2";
454 if (associated.getValue() == getSymName())
455 return emitOpError(
"associated cannot refer to the global itself");
458 if (
ArrayAttr absSym = getAbsoluteSymbolAttr()) {
459 if (absSym.empty() || absSym.size() % 2 != 0)
461 "absolute_symbol must contain one or more integer range pairs");
464 auto intAttr = dyn_cast<IntegerAttr>(attr);
466 return emitOpError(
"absolute_symbol operands must be integers");
468 pairType = intAttr.getType();
469 else if (intAttr.getType() != pairType)
470 return emitOpError(
"absolute_symbol range pair types must match");
477LogicalResult GlobalOp::verifyRegions() {
478 if (
Block *
b = getInitializerBlock()) {
479 ReturnOp ret = cast<ReturnOp>(
b->getTerminator());
480 if (ret.operand_type_begin() == ret.operand_type_end())
481 return emitOpError(
"initializer region cannot return void");
482 if (*ret.operand_type_begin() !=
getType())
483 return emitOpError(
"initializer region type ")
484 << *ret.operand_type_begin() <<
" does not match global type "
488 auto iface = dyn_cast<MemoryEffectOpInterface>(op);
489 if (!iface || !iface.hasNoEffect())
490 return op.emitError()
491 <<
"ops with side effects not allowed in global initializers";
494 if (getValueOrNull())
495 return emitOpError(
"cannot have both initializer value and region");
510 return isa<FlatSymbolRefAttr, ZeroAttr>(v);
513 return op->
emitError(
"data element must be symbol or #llvm.zero");
526LogicalResult GlobalCtorsOp::verify() {
530 if (getCtors().size() == getPriorities().size() &&
531 getCtors().size() == getData().size())
534 "ctors, priorities, and data must have the same number of elements");
551LogicalResult GlobalDtorsOp::verify() {
555 if (getDtors().size() == getPriorities().size() &&
556 getDtors().size() == getData().size())
559 "dtors, priorities, and data must have the same number of elements");
567 Linkage linkage, StringRef name,
bool dsoLocal,
568 ThreadLocalMode threadModel,
572 result.addAttribute(getAliasTypeAttrName(
result.name), TypeAttr::get(type));
574 getTlsModeAttrName(
result.name),
575 ThreadLocalModeAttr::get(builder.
getContext(), threadModel));
581 LinkageAttr::get(builder.
getContext(), linkage));
582 result.attributes.append(attrs.begin(), attrs.end());
593 {getDsoLocalAttrName(), getSymVisibilityAttrName()})
595 {getSymNameAttrName(), getAliasTypeAttrName(), getLinkageAttrName(),
596 getUnnamedAddrAttrName(), getTlsModeAttrName(),
597 getVisibility_AttrName()});
600 p <<
" : " <<
getType() <<
' ';
626 if (types.size() > 1)
634 TypeAttr::get(types[0]));
638LogicalResult AliasOp::verify() {
640 ? !llvm::isa<LLVMVoidType, TokenType, LLVMMetadataType,
642 :
llvm::isa<PointerElementTypeInterface>(
getType());
645 "expects type to be a valid element type for an LLVM global alias");
648 switch (getLinkage()) {
649 case Linkage::External:
650 case Linkage::Internal:
651 case Linkage::Private:
653 case Linkage::WeakODR:
654 case Linkage::Linkonce:
655 case Linkage::LinkonceODR:
656 case Linkage::AvailableExternally:
660 <<
"'" << stringifyLinkage(getLinkage())
661 <<
"' linkage not supported in aliases, available options: private, "
662 "internal, linkonce, weak, linkonce_odr, weak_odr, external or "
663 "available_externally";
669LogicalResult AliasOp::verifyRegions() {
670 Block &
b = getInitializerBlock();
671 auto ret = cast<ReturnOp>(
b.getTerminator());
672 if (ret.getNumOperands() == 0 ||
673 !isa<LLVM::LLVMPointerType>(ret.getOperand(0).getType()))
674 return emitOpError(
"initializer region must always return a pointer");
677 auto iface = dyn_cast<MemoryEffectOpInterface>(op);
678 if (!iface || !iface.hasNoEffect())
679 return op.emitError()
680 <<
"ops with side effects are not allowed in alias initializers";
686unsigned AliasOp::getAddrSpace() {
687 Block &initializer = getInitializerBlock();
689 auto ptrTy = cast<LLVMPointerType>(ret.getOperand(0).getType());
690 return ptrTy.getAddressSpace();
698 Type iFuncType, StringRef resolverName,
Type resolverType,
699 Linkage linkage, LLVM::Visibility visibility) {
700 return build(builder,
result, name, iFuncType, resolverName, resolverType,
702 UnnamedAddr::None, visibility,
nullptr);
709 auto resolver = dyn_cast_if_present<LLVMFuncOp>(symbol);
710 auto alias = dyn_cast_if_present<AliasOp>(symbol);
712 Block &initBlock = alias.getInitializerBlock();
714 auto addrOp = returnOp.getArg().getDefiningOp<AddressOfOp>();
721 resolver = addrOp.getFunction(symbolTable);
722 alias = addrOp.getAlias(symbolTable);
725 return emitOpError(
"must have a function resolver");
726 Linkage linkage = resolver.getLinkage();
727 if (resolver.isExternal() || linkage == Linkage::AvailableExternally)
728 return emitOpError(
"resolver must be a definition");
729 if (!isa<LLVMPointerType>(resolver.getFunctionType().getReturnType()))
730 return emitOpError(
"resolver must return a pointer");
731 auto resolverPtr = dyn_cast<LLVMPointerType>(getResolverType());
732 if (!resolverPtr || resolverPtr.getAddressSpace() != getAddressSpace())
733 return emitOpError(
"resolver has incorrect type");
737LogicalResult IFuncOp::verify() {
738 switch (getLinkage()) {
739 case Linkage::External:
740 case Linkage::Internal:
741 case Linkage::Private:
743 case Linkage::WeakODR:
744 case Linkage::Linkonce:
745 case Linkage::LinkonceODR:
748 return emitOpError() <<
"'" << stringifyLinkage(getLinkage())
749 <<
"' linkage not supported in ifuncs, available "
750 "options: private, internal, linkonce, weak, "
751 "linkonce_odr, weak_odr, or external linkage";
762 assert(empty() &&
"function already has an entry block");
767 LLVMFunctionType type = getFunctionType();
768 for (
unsigned i = 0, e = type.getNumParams(); i < e; ++i)
769 entry->
addArgument(type.getParamType(i), getLoc());
774 StringRef name,
Type type, LLVM::Linkage linkage,
775 bool dsoLocal, CConv cconv, SymbolRefAttr comdat,
778 std::optional<uint64_t> functionEntryCount) {
782 result.addAttribute(getFunctionTypeAttrName(
result.name),
783 TypeAttr::get(type));
785 LinkageAttr::get(builder.
getContext(), linkage));
788 result.attributes.append(attrs.begin(), attrs.end());
793 result.addAttribute(getComdatAttrName(
result.name), comdat);
794 if (functionEntryCount)
795 result.addAttribute(getFunctionEntryCountAttrName(
result.name),
796 FunctionEntryCountAttr::get(builder.
getContext(),
800 std::optional<NamedAttribute> duplicate =
result.attributes.findDuplicate();
801 if (duplicate.has_value()) {
802 llvm::report_fatal_error(
803 Twine(
"LLVMFuncOp propagated an attribute that is meant "
804 "to be constructed by the builder: ") +
805 duplicate->getName().str());
808 if (argAttrs.empty())
811 assert(llvm::cast<LLVMFunctionType>(type).getNumParams() == argAttrs.size() &&
812 "expected as many argument attribute lists as arguments");
814 builder,
result, argAttrs, {},
815 getArgAttrsAttrName(
result.name), getResAttrsAttrName(
result.name));
826 if (outputs.size() > 1) {
827 parser.
emitError(loc,
"failed to construct function type: expected zero or "
828 "one function result");
834 for (
auto t : inputs) {
836 parser.
emitError(loc,
"failed to construct function type: expected LLVM "
837 "type for function arguments");
840 llvmInputs.push_back(t);
845 outputs.empty() ? LLVMVoidType::get(
b.getContext()) : outputs.front();
847 parser.
emitError(loc,
"failed to construct function type: expected LLVM "
848 "type for function results")
852 return LLVMFunctionType::get(llvmOutput, llvmInputs,
868 parser, LLVM::Linkage::External)));
871 result.addAttribute(getVisibility_AttrName(
result.name),
874 parser, LLVM::Visibility::Default)));
877 result.addAttribute(getUnnamedAddrAttrName(
result.name),
880 parser, LLVM::UnnamedAddr::None)));
884 getCConvAttrName(
result.name),
898 parser,
true, entryArgs, isVariadic, resultTypes,
903 for (
auto &arg : entryArgs)
904 argTypes.push_back(arg.type);
910 result.addAttribute(getFunctionTypeAttrName(
result.name),
911 TypeAttr::get(type));
919 auto intTy = IntegerType::get(parser.
getContext(), 32);
921 getVscaleRangeAttrName(
result.name),
922 LLVM::VScaleRangeAttr::get(parser.
getContext(),
923 IntegerAttr::get(intTy, minRange),
924 IntegerAttr::get(intTy, maxRange)));
928 SymbolRefAttr comdat;
933 result.addAttribute(getComdatAttrName(
result.name), comdat);
940 getArgAttrsAttrName(
result.name), getResAttrsAttrName(
result.name));
942 auto *body =
result.addRegion();
953 if (getLinkage() != LLVM::Linkage::External)
954 p << stringifyLinkage(getLinkage()) <<
' ';
955 StringRef visibility = stringifyVisibility(getVisibility_());
956 if (!visibility.empty())
957 p << visibility <<
' ';
958 if (
auto unnamedAddr = getUnnamedAddr()) {
959 StringRef str = stringifyUnnamedAddr(*unnamedAddr);
963 if (getCConv() != LLVM::CConv::C)
964 p << stringifyCConv(getCConv()) <<
' ';
968 LLVMFunctionType fnType = getFunctionType();
971 argTypes.reserve(fnType.getNumParams());
972 for (
unsigned i = 0, e = fnType.getNumParams(); i < e; ++i)
973 argTypes.push_back(fnType.getParamType(i));
975 Type returnType = fnType.getReturnType();
976 if (!llvm::isa<LLVMVoidType>(returnType))
977 resTypes.push_back(returnType);
980 isVarArg(), resTypes);
983 if (std::optional<VScaleRangeAttr> vscale = getVscaleRange())
984 p <<
" vscale_range(" << vscale->getMinRange().getInt() <<
", "
985 << vscale->getMaxRange().getInt() <<
')';
988 if (
auto comdat = getComdat())
989 p <<
" comdat(" << *comdat <<
')';
993 {getFunctionTypeAttrName(), getArgAttrsAttrName(), getResAttrsAttrName(),
994 getLinkageAttrName(), getCConvAttrName(), getVisibility_AttrName(),
995 getComdatAttrName(), getUnnamedAddrAttrName(),
996 getVscaleRangeAttrName()});
1000 if (!body.empty()) {
1015LogicalResult LLVMFuncOp::verify() {
1016 if (getLinkage() == LLVM::Linkage::Common)
1017 return emitOpError() <<
"functions cannot have '"
1018 << stringifyLinkage(LLVM::Linkage::Common)
1022 if (getFunctionEntryCountAttr())
1023 return emitOpError() <<
"external functions cannot have "
1024 << getFunctionEntryCountAttrName() <<
" attribute";
1026 if (getLinkage() != LLVM::Linkage::External &&
1027 getLinkage() != LLVM::Linkage::ExternWeak)
1028 return emitOpError() <<
"external functions must have '"
1029 << stringifyLinkage(LLVM::Linkage::External)
1031 << stringifyLinkage(LLVM::Linkage::ExternWeak)
1037 if (isNoInline() && isAlwaysInline())
1038 return emitError(
"no_inline and always_inline attributes are incompatible");
1040 if (isOptimizeNone() && !isNoInline())
1041 return emitOpError(
"with optimize_none must also be no_inline");
1043 Type landingpadResultTy;
1044 StringRef diagnosticMessage;
1045 bool isLandingpadTypeConsistent =
1047 const auto checkType = [&](
Type type, StringRef errorMessage) {
1048 if (!landingpadResultTy) {
1049 landingpadResultTy = type;
1052 if (landingpadResultTy != type) {
1053 diagnosticMessage = errorMessage;
1059 .Case([&](LandingpadOp landingpad) {
1060 constexpr StringLiteral errorMessage =
1061 "'llvm.landingpad' should have a consistent result type "
1062 "inside a function";
1063 return checkType(landingpad.getType(), errorMessage);
1065 .Case([&](ResumeOp resume) {
1066 constexpr StringLiteral errorMessage =
1067 "'llvm.resume' should have a consistent input type inside a "
1069 return checkType(resume.getValue().getType(), errorMessage);
1072 }).wasInterrupted();
1073 if (!isLandingpadTypeConsistent) {
1074 assert(!diagnosticMessage.empty() &&
1075 "Expecting a non-empty diagnostic message");
1087LogicalResult LLVMFuncOp::verifyRegions() {
1091 unsigned numArguments = getFunctionType().getNumParams();
1092 Block &entryBlock = front();
1093 for (
unsigned i = 0; i < numArguments; ++i) {
1096 return emitOpError(
"entry block argument #")
1097 << i <<
" is not of LLVM type";
1103Region *LLVMFuncOp::getCallableRegion() {
1113LogicalResult LinkerOptionsOp::verify() {
1116 return emitOpError(
"must appear at the module level");
1124LogicalResult ModuleFlagsOp::verify() {
1127 return emitOpError(
"must appear at the module level");
1131 auto moduleFlag = dyn_cast<ModuleFlagAttrInterface>(flag);
1133 return emitOpError(
"expected a module flag attribute");
1135 moduleFlag.getModuleFlagKey(), moduleFlag.getModuleFlagValue(),
1136 [&] { return emitOpError(); })))
1138 if (moduleFlag.getModuleFlagBehavior() == ModFlagBehavior::Require)
1140 StringAttr key = moduleFlag.getModuleFlagKey();
1141 if (!seenNonRequireKeys.insert(key).second)
1142 return emitOpError(
"expected module flag key '")
1143 << key.getValue() <<
"' to be unique for non-require flags";
1153 StringRef name, StringRef value,
1154 LLVM::Linkage linkage) {
1157 "expected builder to point to a block constrained in an op");
1159 builder.getInsertionBlock()->getParentOp()->getParentOfType<ModuleOp>();
1160 assert(module &&
"builder points to an op outside of a module");
1165 auto type = LLVM::LLVMArrayType::get(IntegerType::get(ctx, 8), value.size());
1166 auto global = LLVM::GlobalOp::create(
1167 moduleBuilder, loc, type,
true, linkage, name,
1170 LLVMPointerType ptrType = LLVMPointerType::get(ctx);
1173 LLVM::AddressOfOp::create(builder, loc, ptrType, global.getSymNameAttr());
1174 return LLVM::GEPOp::create(builder, loc, ptrType, type, globalPtr,
1186 module = module->getParentOp();
1187 assert(module &&
"unexpected operation outside of a module");
1191#define GET_OP_CLASSES
1192#include "mlir/Dialect/LLVMIR/LLVMModuleOps.cpp.inc"
static LogicalResult checkGlobalXtorData(Operation *op, ArrayAttr data)
static bool isZeroAttribute(Attribute value)
static LogicalResult verifyComdat(Operation *op, std::optional< SymbolRefAttr > attr, SymbolTableCollection &symbolTable)
static LogicalResult verifyBlockTags(LLVMFuncOp funcOp)
static Type buildLLVMFunctionType(OpAsmParser &parser, SMLoc loc, ArrayRef< Type > inputs, ArrayRef< Type > outputs, function_interface_impl::VariadicFlag variadicFlag)
static LogicalResult verifySymbolAttrUse(FlatSymbolRefAttr symbol, Operation *op, SymbolTableCollection &symbolTable)
Verifies symbol's use in op to ensure the symbol is a valid and fully defined llvm....
static ParseResult parseCommonGlobalAndAlias(OpAsmParser &parser, OperationState &result)
Parse common attributes that might show up in the same order in both GlobalOp and AliasOp.
static void printCommonGlobalAndAlias(OpAsmPrinter &p, OpType op)
static arith::FastMathFlags getFlags(arith::FastMathFlagsAttr fastmath)
Returns the flags held by fastmath, or none if it is null.
ParseResult parseSymbolName(StringAttr &result)
Parse an -identifier and store it (without the '@' symbol) in a string attribute.
virtual Builder & getBuilder() const =0
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
virtual ParseResult parseOptionalAttrDict(NamedAttrList &result)=0
Parse a named dictionary into 'result' if it is present.
virtual ParseResult parseOptionalKeyword(StringRef keyword)=0
Parse the given keyword if present.
MLIRContext * getContext() const
virtual ParseResult parseRParen()=0
Parse a ) token.
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
virtual ParseResult parseOptionalColonTypeList(SmallVectorImpl< Type > &result)=0
Parse an optional colon followed by a type list, which if present must have at least one type.
ParseResult parseInteger(IntT &result)
Parse an integer value from the stream.
virtual ParseResult parseOptionalRParen()=0
Parse a ) token if present.
virtual ParseResult parseOptionalAttrDictWithKeyword(NamedAttrList &result)=0
Parse a named dictionary into 'result' if the attributes keyword is present.
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
virtual SMLoc getNameLoc() const =0
Return the location of the original name token.
virtual ParseResult parseLParen()=0
Parse a ( token.
virtual ParseResult parseComma()=0
Parse a , token.
virtual ParseResult parseOptionalLParen()=0
Parse a ( token if present.
virtual ParseResult parseAttribute(Attribute &result, Type type={})=0
Parse an arbitrary attribute of a given type and return it in result.
virtual void printSymbolName(StringRef symbolRef)
Print the given string as a symbol reference, i.e.
virtual void printAttribute(Attribute attr)
Attributes are known-constant values of operations.
Block represents an ordered list of Operations.
BlockArgument getArgument(unsigned i)
Operation * getTerminator()
Get the terminator operation of this block.
BlockArgument addArgument(Type type, Location loc)
Add one value to the argument list.
Operation * getParentOp()
Returns the closest surrounding operation that contains this block.
This class is a general helper class for creating context-global objects like types,...
IntegerAttr getI32IntegerAttr(int32_t value)
IntegerAttr getI64IntegerAttr(int64_t value)
StringAttr getStringAttr(const Twine &bytes)
MLIRContext * getContext() const
A symbol reference with a reference path containing a single element.
StringRef getValue() const
Returns the name of the held symbol reference.
StringAttr getAttr() const
Returns the name of the held symbol reference as a StringAttr.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
ArrayRef< NamedAttribute > getAttrs() const
Return all of the attributes on this operation.
Attribute set(StringAttr name, Attribute value)
If the an attribute exists with the specified name, change it to the new value.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
virtual ParseResult parseRegion(Region ®ion, ArrayRef< Argument > arguments={}, bool enableNameShadowing=false)=0
Parses a region.
virtual OptionalParseResult parseOptionalRegion(Region ®ion, ArrayRef< Argument > arguments={}, bool enableNameShadowing=false)=0
Parses a region if present.
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
virtual void printOptionalAttrDict(ArrayRef< NamedAttribute > attrs, ArrayRef< StringRef > elidedAttrs={})=0
If the specified operation has attributes, print out an attribute dictionary with their values.
virtual void printRegion(Region &blocks, bool printEntryBlockArgs=true, bool printBlockTerminators=true, bool printEmptyBlock=false)=0
Prints a region.
RAII guard to reset the insertion point of the builder when destroyed.
This class helps build Operations.
Block * createBlock(Region *parent, Region::iterator insertPt={}, TypeRange argTypes={}, ArrayRef< Location > locs={})
Add new block with 'argTypes' arguments and set the insertion point to the end of it.
Listener * getListener() const
Returns the current listener of this builder, or nullptr if this builder doesn't have a listener.
Block * getInsertionBlock() const
Return the block the current insertion point belongs to.
This class provides the API for ops that are known to be isolated from above.
A trait used to provide symbol table functionalities to a region operation.
void walkInherentAttrs(Operation *op, InherentAttrVisitor visitor) const
Visit the inherent attributes stored in the properties of op.
Operation is the basic unit of execution within MLIR.
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
std::optional< Attribute > getInherentAttr(StringRef name)
Access an inherent attribute by name: returns an empty optional if there is no inherent attribute wit...
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
DictionaryAttr getRawDictionaryAttrs()
Return all attributes that are not stored as properties.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
OperationName getName()
The name of an operation is the key identifier for it.
InFlightDiagnostic emitOpError(const Twine &message={})
Emit an error with the op name prefixed, like "'dim' op " which is convenient for verifiers.
This class implements Optional functionality for ParseResult.
bool has_value() const
Returns true if we contain a valid ParseResult value.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
iterator_range< OpIterator > getOps()
This class represents a collection of SymbolTables.
virtual Operation * lookupNearestSymbolFrom(Operation *from, StringAttr symbol)
Returns the operation registered with the given symbol name within the closest parent operation of,...
virtual Operation * lookupSymbolIn(Operation *symbolTableOp, StringAttr symbol)
Look up a symbol with the specified name within the specified symbol table operation,...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
A utility result that is used to signal how to proceed with an ongoing walk:
static WalkResult advance()
static WalkResult interrupt()
A named class for passing around the variadic flag.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
LogicalResult verifyModuleFlagValue(StringAttr key, Attribute value, function_ref< InFlightDiagnostic()> emitError)
Verifies that a module flag value can be exported to LLVM IR.
Value createGlobalString(Location loc, OpBuilder &builder, StringRef name, StringRef value, Linkage linkage)
Create an LLVM global containing the string "value" at the module containing surrounding the insertio...
Operation * parentLLVMModule(Operation *op)
Lookup parent Module satisfying LLVM conditions on the Module Operation.
NamedAttrList getAttrsForPrinting(Operation *op)
Returns the attributes of op to print: its discardable attributes and all its inherent attributes.
void printLLVMLinkage(mlir::OpAsmPrinter &p, mlir::Operation *, mlir::LLVM::LinkageAttr val)
bool isCompatibleOuterType(Type type)
Returns true if the given outer type is compatible with the LLVM dialect without checking its potenti...
RetTy parseOptionalLLVMKeyword(OpAsmParser &parser, EnumTy defaultValue)
Parse an enum from the keyword, or default to the provided default value.
bool satisfiesLLVMModule(Operation *op)
LLVM requires some operations to be inside of a Module operation.
bool isCompatibleType(Type type)
Returns true if the given type is compatible with the LLVM dialect.
mlir::ParseResult parseLLVMLinkage(mlir::OpAsmParser &p, mlir::LLVM::LinkageAttr &val)
int parseOptionalKeywordAlternative(OpAsmParser &parser, ArrayRef< StringRef > keywords)
void addArgAndResultAttrs(Builder &builder, OperationState &result, ArrayRef< DictionaryAttr > argAttrs, ArrayRef< DictionaryAttr > resultAttrs, StringAttr argAttrsName, StringAttr resAttrsName)
Adds argument and result attributes, provided as argAttrs and resultAttrs arguments,...
void walk(Operation *op, function_ref< void(Region *)> callback, WalkOrder order)
Walk all of the regions, blocks, or operations nested under (and including) the given operation.
ParseResult parseFunctionSignatureWithArguments(OpAsmParser &parser, bool allowVariadic, SmallVectorImpl< OpAsmParser::Argument > &arguments, bool &isVariadic, SmallVectorImpl< Type > &resultTypes, SmallVectorImpl< DictionaryAttr > &resultAttrs)
Parses a function signature using parser.
void printFunctionAttributes(OpAsmPrinter &p, Operation *op, ArrayRef< StringRef > elided={})
Prints the list of function prefixed with the "attributes" keyword.
void printFunctionSignature(OpAsmPrinter &p, FunctionOpInterface op, ArrayRef< Type > argTypes, bool isVariadic, ArrayRef< Type > resultTypes)
Prints the signature of the function-like operation op.
Include the generated interface declarations.
Type getType(OpFoldResult ofr)
Returns the int type of the integer in ofr.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
llvm::TypeSwitch< T, ResultT > TypeSwitch
This represents an operation in an abstracted form, suitable for use with the builder APIs.