[Mlir-commits] [mlir] [mlir] Add support for DIGlobalVariable and DIGlobalVariableExpression (PR #73367)
Christian Ulmann
llvmlistbot at llvm.org
Tue Nov 28 13:23:53 PST 2023
================
@@ -109,3 +125,94 @@ bool MemoryEffectsAttr::isReadWrite() {
return false;
return true;
}
+
+//===----------------------------------------------------------------------===//
+// DIExpression
+//===----------------------------------------------------------------------===//
+
+DIExpressionAttr DIExpressionAttr::get(MLIRContext *context) {
+ return get(context, ArrayRef<DIExpressionElemAttr>({}));
+}
+
+/// Parse DWARF expression arguments with respect to the DWARF operation
+/// opcode. Some DWARF expression operations have a specific number of operands
+/// and may appear in a textual form.
+LogicalResult parseExpressionArg(AsmParser &parser, uint64_t opcode,
+ SmallVector<uint64_t> &args) {
+ // The number of operands must be known for each specific operations
+ // in order to parse operations in their respective textual forms.
+ const llvm::DIExpression::ExprOperand opInfo(&opcode);
+ size_t numOperands = opInfo.getNumArgs();
+
+ for (size_t i = 0; i < numOperands; ++i) {
+ uint64_t operand = 0;
+
+ // Parse an operand.
+ if (i > 0 && opcode == llvm::dwarf::DW_OP_LLVM_convert) {
+ // Attempt to parse an keyword.
+ StringRef keyword;
+ if (succeeded(parser.parseOptionalKeyword(&keyword))) {
+ operand = llvm::dwarf::getAttributeEncoding(keyword);
+ if (operand == 0) {
+ // The keyword is invalid.
+ return parser.emitError(parser.getCurrentLocation())
+ << "encountered unknown attribute encoding \"" << keyword
+ << "\"";
+ }
+ }
+ }
+
+ // operand should be non-zero if a keyword was parsed. Otherwise, the
+ // operand MUST be an integer.
+ if (operand == 0) {
+ // Parse the next operand as an integer
+ if (parser.parseInteger(operand)) {
+ return parser.emitError(parser.getCurrentLocation())
+ << "expected operand #" << i;
+ }
+ }
+
+ // NOTE: A few operations are variadic.
+ if (i == 0 && (opcode == llvm::dwarf::DW_OP_LLVM_entry_value ||
+ opcode == llvm::dwarf::DW_OP_LLVM_arg)) {
+ // This operand represents the number of follwing operands. Add to the
+ // current number of operands.
+ numOperands += operand;
+ }
+ args.push_back(operand);
+
+ if (i + 1 != numOperands) {
----------------
Dinistro wrote:
Works for me
https://github.com/llvm/llvm-project/pull/73367
More information about the Mlir-commits
mailing list