Skip to content

Commit a5da280

Browse files
committed
Revert "[CIR] Upstream initial attribute support (llvm#121069)"
This reverts commit 8e32959.
1 parent ef4d5a7 commit a5da280

File tree

13 files changed

+23
-583
lines changed

13 files changed

+23
-583
lines changed

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
#ifndef LLVM_CLANG_CIR_DIALECT_BUILDER_CIRBASEBUILDER_H
1010
#define LLVM_CLANG_CIR_DIALECT_BUILDER_CIRBASEBUILDER_H
1111

12-
#include "clang/CIR/Dialect/IR/CIRAttrs.h"
13-
1412
#include "mlir/IR/Builders.h"
15-
#include "mlir/IR/BuiltinTypes.h"
16-
#include "mlir/IR/Types.h"
1713

1814
namespace cir {
1915

@@ -30,13 +26,6 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
3026
cir::PointerType getVoidPtrTy() {
3127
return getPointerTo(cir::VoidType::get(getContext()));
3228
}
33-
34-
mlir::TypedAttr getConstPtrAttr(mlir::Type type, int64_t value) {
35-
auto valueAttr = mlir::IntegerAttr::get(
36-
mlir::IntegerType::get(type.getContext(), 64), value);
37-
return cir::ConstPtrAttr::get(
38-
getContext(), mlir::cast<cir::PointerType>(type), valueAttr);
39-
}
4029
};
4130

4231
} // namespace cir

clang/include/clang/CIR/Dialect/IR/CIRAttrs.h

Lines changed: 0 additions & 36 deletions
This file was deleted.

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td

Lines changed: 0 additions & 142 deletions
This file was deleted.

clang/include/clang/CIR/Dialect/IR/CIRDialect.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "mlir/Interfaces/MemorySlotInterfaces.h"
2727
#include "mlir/Interfaces/SideEffectInterfaces.h"
2828

29-
#include "clang/CIR/Dialect/IR/CIRAttrs.h"
3029
#include "clang/CIR/Dialect/IR/CIROpsDialect.h.inc"
3130

3231
// TableGen'erated files for MLIR dialects require that a macro be defined when

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
include "clang/CIR/Dialect/IR/CIRDialect.td"
1818
include "clang/CIR/Dialect/IR/CIRTypes.td"
19-
include "clang/CIR/Dialect/IR/CIRAttrs.td"
2019

2120
include "mlir/IR/BuiltinAttributeInterfaces.td"
2221
include "mlir/IR/EnumAttr.td"
@@ -76,45 +75,6 @@ class LLVMLoweringInfo {
7675
class CIR_Op<string mnemonic, list<Trait> traits = []> :
7776
Op<CIR_Dialect, mnemonic, traits>, LLVMLoweringInfo;
7877

79-
//===----------------------------------------------------------------------===//
80-
// ConstantOp
81-
//===----------------------------------------------------------------------===//
82-
83-
def ConstantOp : CIR_Op<"const",
84-
[ConstantLike, Pure, AllTypesMatch<["value", "res"]>]> {
85-
let summary = "Defines a CIR constant";
86-
let description = [{
87-
The `cir.const` operation turns a literal into an SSA value. The data is
88-
attached to the operation as an attribute.
89-
90-
```mlir
91-
%0 = cir.const 42 : i32
92-
%1 = cir.const 4.2 : f32
93-
%2 = cir.const nullptr : !cir.ptr<i32>
94-
```
95-
}];
96-
97-
// The constant operation takes an attribute as the only input.
98-
let arguments = (ins TypedAttrInterface:$value);
99-
100-
// The constant operation returns a single value of CIR_AnyType.
101-
let results = (outs CIR_AnyType:$res);
102-
103-
let assemblyFormat = "attr-dict $value";
104-
105-
let hasVerifier = 1;
106-
107-
let extraClassDeclaration = [{
108-
bool isNullPtr() {
109-
if (const auto ptrAttr = mlir::dyn_cast<cir::ConstPtrAttr>(getValue()))
110-
return ptrAttr.isNullValue();
111-
return false;
112-
}
113-
}];
114-
115-
let hasFolder = 1;
116-
}
117-
11878
//===----------------------------------------------------------------------===//
11979
// GlobalOp
12080
//===----------------------------------------------------------------------===//
@@ -132,19 +92,9 @@ def GlobalOp : CIR_Op<"global"> {
13292
described by the type of the variable.
13393
}];
13494

135-
let arguments = (ins SymbolNameAttr:$sym_name, TypeAttr:$sym_type,
136-
OptionalAttr<AnyAttr>:$initial_value);
137-
138-
let assemblyFormat = [{
139-
$sym_name
140-
custom<GlobalOpTypeAndInitialValue>($sym_type, $initial_value)
141-
attr-dict
142-
}];
95+
let arguments = (ins SymbolNameAttr:$sym_name, TypeAttr:$sym_type);
14396

144-
let extraClassDeclaration = [{
145-
bool isDeclaration() { return !getInitialValue(); }
146-
bool hasInitializer() { return !isDeclaration(); }
147-
}];
97+
let assemblyFormat = [{ $sym_name `:` $sym_type attr-dict }];
14898

14999
let skipDefaultBuilders = 1;
150100

clang/include/clang/CIR/Dialect/IR/CIRTypes.td

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ def CIR_LongDouble : CIR_FloatType<"LongDouble", "long_double"> {
220220

221221
// Constraints
222222

223-
def CIR_AnyFloat: AnyTypeOf<[CIR_Single, CIR_Double, CIR_FP80, CIR_FP128,
224-
CIR_LongDouble, CIR_FP16, CIR_BFloat16]>;
223+
def CIR_AnyFloat: AnyTypeOf<[CIR_Single, CIR_Double, CIR_FP80, CIR_FP128, CIR_LongDouble,
224+
CIR_FP16, CIR_BFloat16]>;
225225
def CIR_AnyIntOrFloat: AnyTypeOf<[CIR_AnyFloat, CIR_IntType]>;
226226

227227
//===----------------------------------------------------------------------===//
@@ -350,12 +350,4 @@ def VoidPtr : Type<
350350
"cir::VoidType::get($_builder.getContext()))"> {
351351
}
352352

353-
//===----------------------------------------------------------------------===//
354-
// Global type constraints
355-
//===----------------------------------------------------------------------===//
356-
357-
def CIR_AnyType : AnyTypeOf<[
358-
CIR_VoidType, CIR_IntType, CIR_AnyFloat, CIR_PointerType, CIR_FuncType
359-
]>;
360-
361353
#endif // MLIR_CIR_DIALECT_CIR_TYPES

clang/include/clang/CIR/Dialect/IR/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,3 @@ mlir_tablegen(CIROpsDialect.cpp.inc -gen-dialect-defs)
1414
add_public_tablegen_target(MLIRCIROpsIncGen)
1515
add_dependencies(mlir-headers MLIRCIROpsIncGen)
1616

17-
mlir_tablegen(CIROpsAttributes.h.inc -gen-attrdef-decls)
18-
mlir_tablegen(CIROpsAttributes.cpp.inc -gen-attrdef-defs)
19-
add_public_tablegen_target(MLIRCIRAttrsEnumsGen)

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -115,48 +115,6 @@ void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd,
115115
if (clang::IdentifierInfo *identifier = vd->getIdentifier()) {
116116
auto varOp = builder.create<cir::GlobalOp>(getLoc(vd->getSourceRange()),
117117
identifier->getName(), type);
118-
// TODO(CIR): This code for processing initial values is a placeholder
119-
// until class ConstantEmitter is upstreamed and the code for processing
120-
// constant expressions is filled out. Only the most basic handling of
121-
// certain constant expressions is implemented for now.
122-
const VarDecl *initDecl;
123-
const Expr *initExpr = vd->getAnyInitializer(initDecl);
124-
if (initExpr) {
125-
mlir::Attribute initializer;
126-
if (APValue *value = initDecl->evaluateValue()) {
127-
switch (value->getKind()) {
128-
case APValue::Int: {
129-
initializer = builder.getAttr<cir::IntAttr>(type, value->getInt());
130-
break;
131-
}
132-
case APValue::Float: {
133-
initializer = builder.getAttr<cir::FPAttr>(type, value->getFloat());
134-
break;
135-
}
136-
case APValue::LValue: {
137-
if (value->getLValueBase()) {
138-
errorNYI(initExpr->getSourceRange(),
139-
"non-null pointer initialization");
140-
} else {
141-
if (auto ptrType = mlir::dyn_cast<cir::PointerType>(type)) {
142-
initializer = builder.getConstPtrAttr(
143-
ptrType, value->getLValueOffset().getQuantity());
144-
} else {
145-
llvm_unreachable(
146-
"non-pointer variable initialized with a pointer");
147-
}
148-
}
149-
break;
150-
}
151-
default:
152-
errorNYI(initExpr->getSourceRange(), "unsupported initializer kind");
153-
break;
154-
}
155-
} else {
156-
errorNYI(initExpr->getSourceRange(), "non-constant initializer");
157-
}
158-
varOp.setInitialValueAttr(initializer);
159-
}
160118
theModule.push_back(varOp);
161119
} else {
162120
errorNYI(vd->getSourceRange().getBegin(),

0 commit comments

Comments
 (0)