Skip to content

Commit adae4ff

Browse files
committed
Revert "[CIR][CIRGen][TBAA] Replace hardcoded TBAA names with getTBAAName (#1242)"
Need to revert #1220 This reverts commit 445f2a5.
1 parent 2409769 commit adae4ff

File tree

7 files changed

+13
-80
lines changed

7 files changed

+13
-80
lines changed

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,13 @@ include "mlir/Interfaces/DataLayoutInterfaces.td"
2020
include "mlir/IR/AttrTypeBase.td"
2121
include "mlir/IR/EnumAttr.td"
2222

23-
// Specify the TBAA name of CIR_type
24-
class TBAALoweringInfo {
25-
string tbaaName = "";
26-
}
27-
2823
//===----------------------------------------------------------------------===//
2924
// CIR Types
3025
//===----------------------------------------------------------------------===//
3126

3227
class CIR_Type<string name, string typeMnemonic, list<Trait> traits = [],
3328
string baseCppClass = "::mlir::Type">
34-
: TypeDef<CIR_Dialect, name, traits, baseCppClass>, TBAALoweringInfo {
29+
: TypeDef<CIR_Dialect, name, traits, baseCppClass> {
3530
let mnemonic = typeMnemonic;
3631
}
3732

@@ -167,7 +162,6 @@ class CIR_FloatType<string name, string mnemonic>
167162
]> {}
168163

169164
def CIR_Single : CIR_FloatType<"Single", "float"> {
170-
let tbaaName = "float";
171165
let summary = "CIR single-precision float type";
172166
let description = [{
173167
Floating-point type that represents the `float` type in C/C++. Its
@@ -176,7 +170,6 @@ def CIR_Single : CIR_FloatType<"Single", "float"> {
176170
}
177171

178172
def CIR_Double : CIR_FloatType<"Double", "double"> {
179-
let tbaaName = "double";
180173
let summary = "CIR double-precision float type";
181174
let description = [{
182175
Floating-point type that represents the `double` type in C/C++. Its
@@ -213,7 +206,6 @@ def CIR_FP128 : CIR_FloatType<"FP128", "f128"> {
213206
}
214207

215208
def CIR_LongDouble : CIR_FloatType<"LongDouble", "long_double"> {
216-
let tbaaName = "long double";
217209
let summary = "CIR extended-precision float type";
218210
let description = [{
219211
Floating-point type that represents the `long double` type in C/C++.
@@ -271,7 +263,7 @@ def CIR_ComplexType : CIR_Type<"Complex", "complex",
271263

272264
def CIR_PointerType : CIR_Type<"Pointer", "ptr",
273265
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {
274-
let tbaaName = "any pointer";
266+
275267
let summary = "CIR pointer type";
276268
let description = [{
277269
`CIR.ptr` is a type returned by any op generating a pointer in C++.
@@ -347,7 +339,7 @@ def CIR_DataMemberType : CIR_Type<"DataMember", "data_member",
347339
def CIR_BoolType :
348340
CIR_Type<"Bool", "bool",
349341
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {
350-
let tbaaName = "bool";
342+
351343
let summary = "CIR bool type";
352344
let description = [{
353345
`cir.bool` represent's C++ bool type.

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,3 @@ add_public_tablegen_target(MLIRCIREnumsGen)
3131
clang_tablegen(CIRBuiltinsLowering.inc -gen-cir-builtins-lowering
3232
SOURCE CIROps.td
3333
TARGET CIRBuiltinsLowering)
34-
35-
clang_tablegen(CIRTBAANameLowering.inc -gen-cir-tbaa-name-lowering
36-
SOURCE CIRTypes.td
37-
TARGET CIRTBAANameLowering)

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -689,18 +689,19 @@ mlir::LLVM::TBAATypeDescriptorAttr getChar(mlir::MLIRContext *ctx) {
689689
return createScalarTypeNode(ctx, "omnipotent char", getRoot(ctx), 0);
690690
}
691691

692-
#define GET_TBAANAME_LOWERING_FUNCTIONS_DEF
693-
#include "clang/CIR/Dialect/IR/CIRTBAANameLowering.inc"
694-
#undef GET_TBAANAME_LOWERING_FUNCTIONS_DEF
695-
692+
// FIXME(cir): This should be moved and use tablegen approach
693+
// see https://github.com/llvm/clangir/pull/1220#discussion_r1889187867
696694
StringRef getTypeName(mlir::Type type) {
697695
return TypeSwitch<mlir::Type, StringRef>(type)
698696
.Case<cir::IntType>([](cir::IntType ty) { return ty.getTBAATypeName(); })
699-
.Case<
700-
#define GET_TBAANAME_LOWERING_LIST
701-
#include "clang/CIR/Dialect/IR/CIRTBAANameLowering.inc"
702-
#undef GET_TBAANAME_LOWERING_LIST
703-
>([](auto ty) { return getTBAAName(ty); })
697+
.Case<cir::SingleType>([](cir::SingleType) { return "float"; })
698+
.Case<cir::DoubleType>([](cir::DoubleType) { return "double"; })
699+
.Case<cir::FP80Type>([](cir::FP80Type) { return "f80"; })
700+
.Case<cir::FP128Type>([](cir::FP128Type) { return "f128"; })
701+
.Case<cir::LongDoubleType>(
702+
[](cir::LongDoubleType) { return "long double"; })
703+
.Case<cir::BoolType>([](cir::BoolType) { return "bool"; })
704+
.Case<cir::PointerType>([](cir::PointerType) { return "any pointer"; })
704705
.Default([](auto ty) {
705706
llvm::errs() << "unknown type: " << ty << "\n";
706707
return "unknown";

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,9 +1099,5 @@ class CIRToLLVMSignBitOpLowering
10991099
#include "clang/CIR/Dialect/IR/CIRBuiltinsLowering.inc"
11001100
#undef GET_BUILTIN_LOWERING_CLASSES_DECLARE
11011101

1102-
#define GET_TBAANAME_LOWERING_FUNCTIONS_DECLARE
1103-
#include "clang/CIR/Dialect/IR/CIRTBAANameLowering.inc"
1104-
#undef GET_TBAANAME_LOWERING_FUNCTIONS_DECLARE
1105-
11061102
} // namespace direct
11071103
} // namespace cir

clang/utils/TableGen/CIRLoweringEmitter.cpp

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ std::string ClassDeclaration;
1616
std::string ClassDefinitions;
1717
std::string ClassList;
1818

19-
std::string TBAANameFunctionDeclaration;
20-
std::string TBAANameFunctionDefinitions;
21-
std::string TBAANameClassList;
22-
2319
void GenerateLowering(const Record *Operation) {
2420
using namespace std::string_literals;
2521
std::string Name = Operation->getName().str();
@@ -72,24 +68,6 @@ CIR)C++" +
7268

7369
ClassList += ", CIR" + Name + "Lowering\n";
7470
}
75-
76-
void GenerateTBAANameLowering(const Record *def) {
77-
using namespace std::string_literals;
78-
std::string Name = def->getValueAsString("cppClassName").str();
79-
std::string TBAAName = def->getValueAsString("tbaaName").str();
80-
TBAANameFunctionDeclaration += "llvm::StringRef getTBAAName(cir::";
81-
TBAANameFunctionDeclaration += Name + " ty);";
82-
TBAANameFunctionDeclaration += "\n";
83-
TBAANameFunctionDefinitions += "llvm::StringRef getTBAAName(cir::";
84-
TBAANameFunctionDefinitions += Name + " ty) {";
85-
TBAANameFunctionDefinitions += " return \"" + TBAAName + "\";";
86-
TBAANameFunctionDefinitions += "}";
87-
TBAANameFunctionDefinitions += "\n";
88-
TBAANameClassList += "\n";
89-
TBAANameClassList += "cir::";
90-
TBAANameClassList += Name;
91-
TBAANameClassList += ", ";
92-
}
9371
} // namespace
9472

9573
void clang::EmitCIRBuiltinsLowering(const RecordKeeper &Records,
@@ -107,25 +85,3 @@ void clang::EmitCIRBuiltinsLowering(const RecordKeeper &Records,
10785
<< ClassDefinitions << "\n#endif\n";
10886
OS << "#ifdef GET_BUILTIN_LOWERING_LIST\n" << ClassList << "\n#endif\n";
10987
}
110-
111-
void clang::EmitCIRTBAANameLowering(const RecordKeeper &Records,
112-
raw_ostream &OS) {
113-
emitSourceFileHeader("Lowering of ClangIR TBAA Name", OS);
114-
115-
for (const auto *Builtin :
116-
Records.getAllDerivedDefinitions("TBAALoweringInfo")) {
117-
if (!Builtin->getValueAsString("tbaaName").empty())
118-
GenerateTBAANameLowering(Builtin);
119-
}
120-
121-
OS << "#ifdef GET_TBAANAME_LOWERING_FUNCTIONS_DECLARE\n"
122-
<< TBAANameFunctionDeclaration << "\n#endif\n";
123-
OS << "#ifdef GET_TBAANAME_LOWERING_FUNCTIONS_DEF\n"
124-
<< TBAANameFunctionDefinitions << "\n#endif\n";
125-
// remove last `, `
126-
if (!TBAANameClassList.empty()) {
127-
TBAANameClassList.resize(TBAANameClassList.size() - 2);
128-
}
129-
OS << "#ifdef GET_TBAANAME_LOWERING_LIST\n"
130-
<< TBAANameClassList << "\n#endif\n";
131-
}

clang/utils/TableGen/TableGen.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ enum ActionType {
2626
PrintRecords,
2727
DumpJSON,
2828
GenCIRBuiltinsLowering,
29-
GenCIRTBAANameLowering,
3029
GenClangAttrClasses,
3130
GenClangAttrParserStringSwitches,
3231
GenClangAttrSubjectMatchRulesParserStringSwitches,
@@ -124,8 +123,6 @@ cl::opt<ActionType> Action(
124123
clEnumValN(GenCIRBuiltinsLowering, "gen-cir-builtins-lowering",
125124
"Generate lowering of ClangIR builtins to equivalent LLVM "
126125
"IR builtins"),
127-
clEnumValN(GenCIRTBAANameLowering, "gen-cir-tbaa-name-lowering",
128-
"Generate lowering of ClangIR TBAA Name"),
129126
clEnumValN(GenClangAttrClasses, "gen-clang-attr-classes",
130127
"Generate clang attribute clases"),
131128
clEnumValN(GenClangAttrParserStringSwitches,
@@ -334,9 +331,6 @@ bool ClangTableGenMain(raw_ostream &OS, const RecordKeeper &Records) {
334331
case GenCIRBuiltinsLowering:
335332
EmitCIRBuiltinsLowering(Records, OS);
336333
break;
337-
case GenCIRTBAANameLowering:
338-
EmitCIRTBAANameLowering(Records, OS);
339-
break;
340334
case GenClangAttrClasses:
341335
EmitClangAttrClass(Records, OS);
342336
break;

clang/utils/TableGen/TableGenBackends.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ namespace clang {
2626

2727
void EmitCIRBuiltinsLowering(const llvm::RecordKeeper &RK,
2828
llvm::raw_ostream &OS);
29-
void EmitCIRTBAANameLowering(const llvm::RecordKeeper &RK,
30-
llvm::raw_ostream &OS);
3129
void EmitClangDeclContext(const llvm::RecordKeeper &RK, llvm::raw_ostream &OS);
3230
/**
3331
@param PriorizeIfSubclassOf These classes should be prioritized in the output.

0 commit comments

Comments
 (0)