Skip to content

Commit b77e24d

Browse files
committed
Revert "[CIR] Integral types; simple global variables (llvm#118743)"
This reverts commit a43b2e1.
1 parent 88b1d08 commit b77e24d

File tree

12 files changed

+38
-583
lines changed

12 files changed

+38
-583
lines changed

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

+2-33
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#define LLVM_CLANG_CIR_DIALECT_IR_CIROPS
1616

1717
include "clang/CIR/Dialect/IR/CIRDialect.td"
18-
include "clang/CIR/Dialect/IR/CIRTypes.td"
1918

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

78-
//===----------------------------------------------------------------------===//
79-
// GlobalOp
80-
//===----------------------------------------------------------------------===//
81-
82-
// TODO(CIR): For starters, cir.global has only name and type. The other
83-
// properties of a global variable will be added over time as more of ClangIR
84-
// is upstreamed.
85-
86-
def GlobalOp : CIR_Op<"global"> {
87-
let summary = "Declare or define a global variable";
88-
let description = [{
89-
The `cir.global` operation declares or defines a named global variable.
90-
91-
The backing memory for the variable is allocated statically and is
92-
described by the type of the variable.
93-
}];
94-
95-
let arguments = (ins SymbolNameAttr:$sym_name, TypeAttr:$sym_type);
96-
97-
let assemblyFormat = [{ $sym_name `:` $sym_type attr-dict }];
98-
99-
let skipDefaultBuilders = 1;
100-
101-
let builders = [OpBuilder<(ins "llvm::StringRef":$sym_name,
102-
"mlir::Type":$sym_type)>];
103-
104-
let hasVerifier = 1;
105-
}
106-
10777
//===----------------------------------------------------------------------===//
10878
// FuncOp
10979
//===----------------------------------------------------------------------===//
@@ -115,15 +85,14 @@ def GlobalOp : CIR_Op<"global"> {
11585
def FuncOp : CIR_Op<"func"> {
11686
let summary = "Declare or define a function";
11787
let description = [{
118-
The `cir.func` operation defines a function, similar to the `mlir::FuncOp`
119-
built-in.
88+
... lots of text to be added later ...
12089
}];
12190

12291
let arguments = (ins SymbolNameAttr:$sym_name);
12392

12493
let skipDefaultBuilders = 1;
12594

126-
let builders = [OpBuilder<(ins "llvm::StringRef":$sym_name)>];
95+
let builders = [OpBuilder<(ins "llvm::StringRef":$name)>];
12796

12897
let hasCustomAssemblyFormat = 1;
12998
let hasVerifier = 1;

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

-27
This file was deleted.

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

-132
This file was deleted.

clang/lib/CIR/CodeGen/CIRGenModule.cpp

+25-33
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ CIRGenModule::CIRGenModule(mlir::MLIRContext &context,
3131
DiagnosticsEngine &diags)
3232
: builder(&context), astCtx(astctx), langOpts(astctx.getLangOpts()),
3333
theModule{mlir::ModuleOp::create(mlir::UnknownLoc::get(&context))},
34-
diags(diags), target(astCtx.getTargetInfo()), genTypes(*this) {}
34+
diags(diags), target(astCtx.getTargetInfo()) {}
3535

3636
mlir::Location CIRGenModule::getLoc(SourceLocation cLoc) {
3737
assert(cLoc.isValid() && "expected valid source location");
@@ -67,8 +67,7 @@ void CIRGenModule::emitGlobal(clang::GlobalDecl gd) {
6767
return;
6868
}
6969
} else {
70-
assert(cast<VarDecl>(global)->isFileVarDecl() &&
71-
"Cannot emit local var decl as global");
70+
errorNYI(global->getSourceRange(), "global variable declaration");
7271
}
7372

7473
// TODO(CIR): Defer emitting some global definitions until later
@@ -78,27 +77,9 @@ void CIRGenModule::emitGlobal(clang::GlobalDecl gd) {
7877
void CIRGenModule::emitGlobalFunctionDefinition(clang::GlobalDecl gd,
7978
mlir::Operation *op) {
8079
auto const *funcDecl = cast<FunctionDecl>(gd.getDecl());
81-
if (clang::IdentifierInfo *identifier = funcDecl->getIdentifier()) {
82-
auto funcOp = builder.create<cir::FuncOp>(
83-
getLoc(funcDecl->getSourceRange()), identifier->getName());
84-
theModule.push_back(funcOp);
85-
} else {
86-
errorNYI(funcDecl->getSourceRange().getBegin(),
87-
"function definition with a non-identifier for a name");
88-
}
89-
}
90-
91-
void CIRGenModule::emitGlobalVarDefinition(const clang::VarDecl *vd,
92-
bool isTentative) {
93-
mlir::Type type = getTypes().convertType(vd->getType());
94-
if (clang::IdentifierInfo *identifier = vd->getIdentifier()) {
95-
auto varOp = builder.create<cir::GlobalOp>(getLoc(vd->getSourceRange()),
96-
identifier->getName(), type);
97-
theModule.push_back(varOp);
98-
} else {
99-
errorNYI(vd->getSourceRange().getBegin(),
100-
"variable definition with a non-identifier for a name");
101-
}
80+
auto funcOp = builder.create<cir::FuncOp>(
81+
getLoc(funcDecl->getSourceRange()), funcDecl->getIdentifier()->getName());
82+
theModule.push_back(funcOp);
10283
}
10384

10485
void CIRGenModule::emitGlobalDefinition(clang::GlobalDecl gd,
@@ -122,9 +103,6 @@ void CIRGenModule::emitGlobalDefinition(clang::GlobalDecl gd,
122103
return;
123104
}
124105

125-
if (const auto *vd = dyn_cast<VarDecl>(decl))
126-
return emitGlobalVarDefinition(vd, !vd->hasDefinition());
127-
128106
llvm_unreachable("Invalid argument to CIRGenModule::emitGlobalDefinition");
129107
}
130108

@@ -148,23 +126,37 @@ void CIRGenModule::emitTopLevelDecl(Decl *decl) {
148126
emitGlobal(fd);
149127
break;
150128
}
151-
152-
case Decl::Var: {
153-
auto *vd = cast<VarDecl>(decl);
154-
emitGlobal(vd);
155-
break;
156-
}
157129
}
158130
}
159131

132+
DiagnosticBuilder CIRGenModule::errorNYI(llvm::StringRef feature) {
133+
unsigned diagID = diags.getCustomDiagID(
134+
DiagnosticsEngine::Error, "ClangIR code gen Not Yet Implemented: %0");
135+
return diags.Report(diagID) << feature;
136+
}
137+
160138
DiagnosticBuilder CIRGenModule::errorNYI(SourceLocation loc,
161139
llvm::StringRef feature) {
162140
unsigned diagID = diags.getCustomDiagID(
163141
DiagnosticsEngine::Error, "ClangIR code gen Not Yet Implemented: %0");
164142
return diags.Report(loc, diagID) << feature;
165143
}
166144

145+
DiagnosticBuilder CIRGenModule::errorNYI(SourceLocation loc,
146+
llvm::StringRef feature,
147+
llvm::StringRef name) {
148+
unsigned diagID = diags.getCustomDiagID(
149+
DiagnosticsEngine::Error, "ClangIR code gen Not Yet Implemented: %0: %1");
150+
return diags.Report(loc, diagID) << feature << name;
151+
}
152+
167153
DiagnosticBuilder CIRGenModule::errorNYI(SourceRange loc,
168154
llvm::StringRef feature) {
169155
return errorNYI(loc.getBegin(), feature) << loc;
170156
}
157+
158+
DiagnosticBuilder CIRGenModule::errorNYI(SourceRange loc,
159+
llvm::StringRef feature,
160+
llvm::StringRef name) {
161+
return errorNYI(loc.getBegin(), feature, name) << loc;
162+
}

clang/lib/CIR/CodeGen/CIRGenModule.h

+7-26
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@
1414
#define LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENMODULE_H
1515

1616
#include "CIRGenTypeCache.h"
17-
#include "CIRGenTypes.h"
1817

1918
#include "mlir/IR/Builders.h"
2019
#include "mlir/IR/BuiltinOps.h"
2120
#include "mlir/IR/MLIRContext.h"
22-
#include "clang/Basic/SourceManager.h"
2321
#include "llvm/ADT/StringRef.h"
2422

2523
namespace clang {
2624
class ASTContext;
2725
class CodeGenOptions;
2826
class Decl;
27+
class DiagnosticBuilder;
28+
class DiagnosticsEngine;
2929
class GlobalDecl;
3030
class LangOptions;
31+
class SourceLocation;
32+
class SourceRange;
3133
class TargetInfo;
32-
class VarDecl;
3334

3435
namespace CIRGen {
3536

@@ -63,13 +64,8 @@ class CIRGenModule : public CIRGenTypeCache {
6364

6465
const clang::TargetInfo &target;
6566

66-
CIRGenTypes genTypes;
67-
6867
public:
6968
mlir::ModuleOp getModule() const { return theModule; }
70-
mlir::OpBuilder &getBuilder() { return builder; }
71-
clang::ASTContext &getASTContext() const { return astCtx; }
72-
CIRGenTypes &getTypes() { return genTypes; }
7369

7470
/// Helpers to convert the presumed location of Clang's SourceLocation to an
7571
/// MLIR Location.
@@ -85,28 +81,13 @@ class CIRGenModule : public CIRGenTypeCache {
8581
void emitGlobalDefinition(clang::GlobalDecl gd,
8682
mlir::Operation *op = nullptr);
8783
void emitGlobalFunctionDefinition(clang::GlobalDecl gd, mlir::Operation *op);
88-
void emitGlobalVarDefinition(const clang::VarDecl *vd,
89-
bool isTentative = false);
9084

9185
/// Helpers to emit "not yet implemented" error diagnostics
86+
DiagnosticBuilder errorNYI(llvm::StringRef);
9287
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef);
93-
94-
template <typename T>
95-
DiagnosticBuilder errorNYI(SourceLocation loc, llvm::StringRef feature,
96-
const T &name) {
97-
unsigned diagID =
98-
diags.getCustomDiagID(DiagnosticsEngine::Error,
99-
"ClangIR code gen Not Yet Implemented: %0: %1");
100-
return diags.Report(loc, diagID) << feature << name;
101-
}
102-
88+
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef, llvm::StringRef);
10389
DiagnosticBuilder errorNYI(SourceRange, llvm::StringRef);
104-
105-
template <typename T>
106-
DiagnosticBuilder errorNYI(SourceRange loc, llvm::StringRef feature,
107-
const T &name) {
108-
return errorNYI(loc.getBegin(), feature, name) << loc;
109-
}
90+
DiagnosticBuilder errorNYI(SourceRange, llvm::StringRef, llvm::StringRef);
11091
};
11192
} // namespace CIRGen
11293

0 commit comments

Comments
 (0)