-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[CIR] Upstream initial attribute support #121069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file declares the attributes in the CIR dialect. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRATTRS_H | ||
| #define LLVM_CLANG_CIR_DIALECT_IR_CIRATTRS_H | ||
|
|
||
| #include "clang/CIR/Dialect/IR/CIRTypes.h" | ||
|
|
||
| #include "mlir/IR/Attributes.h" | ||
| #include "mlir/IR/BuiltinAttributeInterfaces.h" | ||
|
|
||
| #include "llvm/ADT/SmallVector.h" | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // CIR Dialect Attrs | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| namespace clang { | ||
| class FunctionDecl; | ||
| class VarDecl; | ||
| class RecordDecl; | ||
| } // namespace clang | ||
|
|
||
| #define GET_ATTRDEF_CLASSES | ||
| #include "clang/CIR/Dialect/IR/CIROpsAttributes.h.inc" | ||
|
|
||
| #endif // LLVM_CLANG_CIR_DIALECT_IR_CIRATTRS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file declares the CIR dialect attributes. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRATTRS_TD | ||
| #define LLVM_CLANG_CIR_DIALECT_IR_CIRATTRS_TD | ||
|
|
||
| include "mlir/IR/BuiltinAttributeInterfaces.td" | ||
| include "mlir/IR/EnumAttr.td" | ||
|
|
||
| include "clang/CIR/Dialect/IR/CIRDialect.td" | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // CIR Attrs | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| class CIR_Attr<string name, string attrMnemonic, list<Trait> traits = []> | ||
| : AttrDef<CIR_Dialect, name, traits> { | ||
| let mnemonic = attrMnemonic; | ||
| } | ||
|
|
||
| class CIRUnitAttr<string name, string attrMnemonic, list<Trait> traits = []> | ||
| : CIR_Attr<name, attrMnemonic, traits> { | ||
| let returnType = "bool"; | ||
| let defaultValue = "false"; | ||
| let valueType = NoneType; | ||
| let isOptional = 1; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // IntegerAttr | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def IntAttr : CIR_Attr<"Int", "int", [TypedAttrInterface]> { | ||
| let summary = "An attribute containing an integer value"; | ||
| let description = [{ | ||
| An integer attribute is a literal attribute that represents an integral | ||
| value of the specified integer type. | ||
| }]; | ||
| let parameters = (ins AttributeSelfTypeParameter<"">:$type, | ||
| "llvm::APInt":$value); | ||
| let builders = [ | ||
| AttrBuilderWithInferredContext<(ins "mlir::Type":$type, | ||
| "const llvm::APInt &":$value), [{ | ||
| return $_get(type.getContext(), type, value); | ||
| }]>, | ||
| AttrBuilderWithInferredContext<(ins "mlir::Type":$type, | ||
| "int64_t":$value), [{ | ||
| IntType intType = mlir::cast<IntType>(type); | ||
| mlir::APInt apValue(intType.getWidth(), value, intType.isSigned()); | ||
| return $_get(intType.getContext(), intType, apValue); | ||
| }]>, | ||
| ]; | ||
| let extraClassDeclaration = [{ | ||
| int64_t getSInt() const { return getValue().getSExtValue(); } | ||
| uint64_t getUInt() const { return getValue().getZExtValue(); } | ||
| bool isNullValue() const { return getValue() == 0; } | ||
| uint64_t getBitWidth() const { | ||
| return mlir::cast<IntType>(getType()).getWidth(); | ||
| } | ||
| }]; | ||
| let genVerifyDecl = 1; | ||
| let hasCustomAssemblyFormat = 1; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // FPAttr | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def FPAttr : CIR_Attr<"FP", "fp", [TypedAttrInterface]> { | ||
| let summary = "An attribute containing a floating-point value"; | ||
| let description = [{ | ||
| An fp attribute is a literal attribute that represents a floating-point | ||
| value of the specified floating-point type. Supporting only CIR FP types. | ||
| }]; | ||
| let parameters = (ins | ||
| AttributeSelfTypeParameter<"", "::cir::CIRFPTypeInterface">:$type, | ||
| APFloatParameter<"">:$value | ||
| ); | ||
| let builders = [ | ||
| AttrBuilderWithInferredContext<(ins "mlir::Type":$type, | ||
| "const llvm::APFloat &":$value), [{ | ||
| return $_get(type.getContext(), mlir::cast<CIRFPTypeInterface>(type), | ||
| value); | ||
| }]>, | ||
| AttrBuilder<(ins "mlir::Type":$type, | ||
| "const llvm::APFloat &":$value), [{ | ||
| return $_get($_ctxt, mlir::cast<CIRFPTypeInterface>(type), value); | ||
| }]>, | ||
| ]; | ||
| let extraClassDeclaration = [{ | ||
| static FPAttr getZero(mlir::Type type); | ||
| }]; | ||
| let genVerifyDecl = 1; | ||
|
|
||
| let assemblyFormat = [{ | ||
| `<` custom<FloatLiteral>($value, ref($type)) `>` | ||
| }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // ConstPtrAttr | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def ConstPtrAttr : CIR_Attr<"ConstPtr", "ptr", [TypedAttrInterface]> { | ||
| let summary = "Holds a constant pointer value"; | ||
| let parameters = (ins | ||
| AttributeSelfTypeParameter<"", "::cir::PointerType">:$type, | ||
| "mlir::IntegerAttr":$value); | ||
| let description = [{ | ||
| A pointer attribute is a literal attribute that represents an integral | ||
| value of a pointer type. | ||
| }]; | ||
| let builders = [ | ||
| AttrBuilderWithInferredContext<(ins "mlir::Type":$type, | ||
| "mlir::IntegerAttr":$value), [{ | ||
| return $_get(type.getContext(), mlir::cast<cir::PointerType>(type), | ||
| value); | ||
| }]>, | ||
| AttrBuilder<(ins "mlir::Type":$type, | ||
| "mlir::IntegerAttr":$value), [{ | ||
| return $_get($_ctxt, mlir::cast<cir::PointerType>(type), value); | ||
| }]>, | ||
| ]; | ||
| let extraClassDeclaration = [{ | ||
| bool isNullValue() const { return getValue().getInt() == 0; } | ||
| }]; | ||
|
|
||
| let assemblyFormat = [{ | ||
| `<` custom<ConstPtr>($value) `>` | ||
| }]; | ||
| } | ||
|
|
||
| #endif // LLVM_CLANG_CIR_DIALECT_IR_CIRATTRS_TD |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we do a better variable name than
v? I presume it meansvalue? But that is really only something I can guess at.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I am still calibrating when to use the same names that are in the ClangIR incubator and when to choose better names.