18 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/ADT/TypeSwitch.h"
20 #include "llvm/BinaryFormat/Dwarf.h"
21 #include "llvm/IR/DebugInfoMetadata.h"
31 SmallVector<uint64_t> &args);
36 ArrayRef<uint64_t> args);
38 #include "mlir/Dialect/LLVMIR/LLVMOpsEnums.cpp.inc"
39 #define GET_ATTRDEF_CLASSES
40 #include "mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.cpp.inc"
46 void LLVMDialect::registerAttributes() {
48 #define GET_ATTRDEF_LIST
49 #include "mlir/Dialect/LLVMIR/LLVMOpsAttrDefs.cpp.inc"
58 return llvm::isa<DIBasicTypeAttr, DICompileUnitAttr, DICompositeTypeAttr,
59 DIDerivedTypeAttr, DIFileAttr, DIGlobalVariableAttr,
60 DILabelAttr, DILexicalBlockAttr, DILexicalBlockFileAttr,
61 DILocalVariableAttr, DIModuleAttr, DINamespaceAttr,
62 DINullTypeAttr, DISubprogramAttr, DISubrangeAttr,
63 DISubroutineTypeAttr>(attr);
71 return llvm::isa<DICompileUnitAttr, DICompositeTypeAttr, DIFileAttr,
80 return llvm::isa<DILexicalBlockAttr, DILexicalBlockFileAttr,
81 DISubprogramAttr>(attr);
89 return llvm::isa<DINullTypeAttr, DIBasicTypeAttr, DICompositeTypeAttr,
90 DIDerivedTypeAttr, DISubroutineTypeAttr>(attr);
98 return llvm::isa<TBAATypeDescriptorAttr, TBAARootAttr>(attr);
107 if (memInfoArgs.empty())
109 ModRefInfo::ModRef, ModRefInfo::ModRef);
110 if (memInfoArgs.size() == 3)
116 bool MemoryEffectsAttr::isReadWrite() {
117 if (this->getArgMem() != ModRefInfo::ModRef)
119 if (this->getInaccessibleMem() != ModRefInfo::ModRef)
121 if (this->getOther() != ModRefInfo::ModRef)
131 return get(context, ArrayRef<DIExpressionElemAttr>({}));
135 SmallVector<uint64_t> &args) {
137 uint64_t operand = 0;
138 if (!args.empty() && opcode == llvm::dwarf::DW_OP_LLVM_convert) {
142 operand = llvm::dwarf::getAttributeEncoding(keyword);
146 <<
"encountered unknown attribute encoding \"" << keyword
158 <<
"expected integer operand";
162 args.push_back(operand);
171 ArrayRef<uint64_t> args) {
173 llvm::interleaveComma(args, printer, [&](uint64_t operand) {
174 if (i > 0 && opcode == llvm::dwarf::DW_OP_LLVM_convert) {
175 if (
const StringRef keyword =
176 llvm::dwarf::AttributeEncodingString(operand);
195 llvm::map_to_vector(features, [&](StringRef feature) {
201 StringRef targetFeatures) {
202 SmallVector<StringRef> features;
203 targetFeatures.split(features,
',', -1,
205 return get(context, features);
211 for (StringAttr featureAttr : features) {
212 if (!featureAttr || featureAttr.empty())
213 return emitError() <<
"target features can not be null or empty";
214 auto feature = featureAttr.strref();
215 if (feature[0] !=
'+' && feature[0] !=
'-')
216 return emitError() <<
"target features must start with '+' or '-'";
217 if (feature.contains(
','))
218 return emitError() <<
"target features can not contain ','";
227 return llvm::is_contained(getFeatures(), feature);
233 return llvm::is_contained(getFeatures(), feature);
236 std::string TargetFeaturesAttr::getFeaturesString()
const {
237 std::string featuresString;
238 llvm::raw_string_ostream ss(featuresString);
240 getFeatures(), ss, [&](
auto &feature) { ss << feature.strref(); },
",");
244 TargetFeaturesAttr TargetFeaturesAttr::featuresAt(
Operation *op) {
248 return parentFunction.getOperation()->getAttrOfType<TargetFeaturesAttr>(
static LogicalResult parseExpressionArg(AsmParser &parser, uint64_t opcode, SmallVector< uint64_t > &args)
Parses DWARF expression arguments with respect to the DWARF operation opcode.
static void printExpressionArg(AsmPrinter &printer, uint64_t opcode, ArrayRef< uint64_t > args)
Prints DWARF expression arguments with respect to the specific DWARF operation.
static bool contains(SMRange range, SMLoc loc)
Returns true if the given range contains the given source location.
This base class exposes generic asm parser hooks, usable across the various derived parsers.
virtual ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())=0
Parse a list of comma-separated items with an optional delimiter.
virtual ParseResult parseOptionalKeyword(StringRef keyword)=0
Parse the given keyword if present.
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
ParseResult parseInteger(IntT &result)
Parse an integer value from the stream.
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
This base class exposes generic asm printer hooks, usable across the various derived printers.
Attributes are known-constant values of operations.
This class represents a diagnostic that is inflight and set to be reported.
This class represents a LLVM attribute that describes a local debug info scope.
static bool classof(Attribute attr)
Support LLVM type casting.
static bool classof(Attribute attr)
static bool classof(Attribute attr)
Support LLVM type casting.
static bool classof(Attribute attr)
Support LLVM type casting.
static bool classof(Attribute attr)
Support LLVM type casting.
MLIRContext is the top-level object for a collection of MLIR operations.
Operation is the basic unit of execution within MLIR.
OpTy getParentOfType()
Return the closest surrounding parent operation that is of type 'OpTy'.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.
bool succeeded(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a success value.
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
LogicalResult verify(Operation *op, bool verifyRecursively=true)
Perform (potentially expensive) checks of invariants, used to detect compiler bugs,...
This class represents an efficient way to signal success or failure.