@@ -65,6 +65,54 @@ class CIRUnitAttr<string name, string attrMnemonic, list<Trait> traits = []>
6565 let isOptional = 1;
6666}
6767
68+ //===----------------------------------------------------------------------===//
69+ // OptInfoAttr
70+ //===----------------------------------------------------------------------===//
71+
72+ def CIR_OptInfoAttr : CIR_Attr<"OptInfo", "opt_info"> {
73+ let summary =
74+ "A module-level attribute that holds the optimization information";
75+ let description = [{
76+ The `#cir.opt_info` attribute holds optimization related information. For
77+ now this attribute is a module-level attribute that gets attached to the
78+ module operation during CIRGen.
79+
80+ The `level` parameter gives the optimization level. It must be an integer
81+ between 0 and 3, inclusive. It corresponds to the `OptimizationLevel` field
82+ within the `clang::CodeGenOptions` structure.
83+
84+ The `size` parameter gives the code size optimization level. It must be an
85+ integer between 0 and 2, inclusive. It corresponds to the `OptimizeSize`
86+ field within the `clang::CodeGenOptions` structure.
87+
88+ The `level` and `size` parameters correspond to the optimization level
89+ command line options passed to clang driver. The table below lists the
90+ current correspondance relationship:
91+
92+ | Flag | `level` | `size` |
93+ |------------------|---------|--------|
94+ | `-O0` or nothing | 0 | 0 |
95+ | `-O1` | 1 | 0 |
96+ | `-O2` | 2 | 0 |
97+ | `-O3` | 3 | 0 |
98+ | `-Os` | 2 | 1 |
99+ | `-Oz` | 2 | 2 |
100+
101+ Examples:
102+
103+ ```mlir
104+ #cir.opt_info<level = 2, size = 0> // -O2
105+ ```
106+ }];
107+
108+ let parameters = (ins "unsigned":$level, "unsigned":$size);
109+
110+ let assemblyFormat = [{
111+ `<` struct(params) `>`
112+ }];
113+ let genVerifyDecl = 1;
114+ }
115+
68116//===----------------------------------------------------------------------===//
69117// BoolAttr
70118//===----------------------------------------------------------------------===//
0 commit comments