Skip to content

Commit 53112a5

Browse files
frabertwizardengineer
authored andcommitted
[CIR] Fix SymbolUserOpInterface::getUserSymbol
[CIR] Clean up CIRLinkerInterface [CIR] Remove stray include
1 parent 66bc0a7 commit 53112a5

File tree

19 files changed

+367
-328
lines changed

19 files changed

+367
-328
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ def CIR_AddressSpaceAttr : CIR_EnumAttr<CIR_AddressSpace, "address_space"> {
972972
];
973973

974974
let assemblyFormat = [{
975-
`<` custom<AddressSpaceValue>($value) `>`
975+
`` custom<AddressSpaceValue>($value)
976976
}];
977977

978978
let defaultValue = "cir::AddressSpace::Default";

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,7 +2557,8 @@ def CIR_GlobalOp : CIR_Op<"global", [
25572557
//===----------------------------------------------------------------------===//
25582558

25592559
def CIR_GetGlobalOp : CIR_Op<"get_global", [
2560-
Pure, DeclareOpInterfaceMethods<SymbolUserOpInterface>
2560+
Pure, SymbolUserOpInterface,
2561+
DeclareOpInterfaceMethods<SymbolUserOpInterface, ["getUserSymbol"]>
25612562
]> {
25622563
let summary = "Get the address of a global variable";
25632564
let description = [{
@@ -2595,7 +2596,8 @@ def CIR_GetGlobalOp : CIR_Op<"get_global", [
25952596
//===----------------------------------------------------------------------===//
25962597

25972598
def CIR_VTableAddrPointOp : CIR_Op<"vtable.address_point", [
2598-
Pure, DeclareOpInterfaceMethods<SymbolUserOpInterface>
2599+
Pure, SymbolUserOpInterface,
2600+
DeclareOpInterfaceMethods<SymbolUserOpInterface, ["getUserSymbol"]>
25992601
]> {
26002602
let summary = "Get the vtable (global variable) address point";
26012603
let description = [{
@@ -2873,7 +2875,8 @@ def CIR_VTableGetVirtualFnAddrOp : CIR_Op<"vtable.get_virtual_fn_addr", [
28732875
//===----------------------------------------------------------------------===//
28742876

28752877
def CIR_VTTAddrPointOp : CIR_Op<"vtt.address_point", [
2876-
Pure, DeclareOpInterfaceMethods<SymbolUserOpInterface>
2878+
Pure, SymbolUserOpInterface,
2879+
DeclareOpInterfaceMethods<SymbolUserOpInterface, ["getUserSymbol"]>
28772880
]> {
28782881
let summary = "Get the VTT address point";
28792882
let description = [{
@@ -4201,8 +4204,9 @@ def CIR_SideEffect : CIR_I32EnumAttr<
42014204

42024205
class CIR_CallOp<string mnemonic, list<Trait> extra_traits = []>
42034206
: CIR_Op<mnemonic, !listconcat(extra_traits, [
4207+
SymbolUserOpInterface,
42044208
DeclareOpInterfaceMethods<CIRCallOpInterface>,
4205-
DeclareOpInterfaceMethods<SymbolUserOpInterface>
4209+
DeclareOpInterfaceMethods<SymbolUserOpInterface, ["getUserSymbol"]>
42064210
])>
42074211
{
42084212
let extraClassDeclaration = [{
@@ -4682,8 +4686,10 @@ def CIR_EhInflightOp : CIR_Op<"eh.inflight_exception"> {
46824686
}];
46834687
}
46844688

4685-
def CIR_EhTypeIdOp : CIR_Op<"eh.typeid",
4686-
[Pure, DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
4689+
def CIR_EhTypeIdOp : CIR_Op<"eh.typeid", [
4690+
Pure, SymbolUserOpInterface,
4691+
DeclareOpInterfaceMethods<SymbolUserOpInterface, ["getUserSymbol"]>
4692+
]> {
46874693
let summary = "Compute exception type id from it's global type symbol";
46884694
let description = [{
46894695
Returns the exception type id for a given global symbol representing

clang/include/clang/CIR/Interfaces/CIRLinkerInterface.h

Lines changed: 33 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
#ifndef CLANG_INTERFACES_CIR_CIRLINKINTERFACE_H_
1414
#define CLANG_INTERFACES_CIR_CIRLINKINTERFACE_H_
15+
#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
1516
#include "mlir/Linker/LLVMLinkerMixin.h"
16-
#include "mlir/Linker/LinkerInterface.h"
17-
#include "clang/CIR/Dialect/IR/CIRDialect.h"
17+
1818
#include <optional>
1919

2020
namespace mlir {
@@ -35,183 +35,44 @@ class CIRSymbolLinkerInterface
3535
CIRSymbolLinkerInterface(Dialect *dialect)
3636
: SymbolAttrLLVMLinkerInterface(dialect) {}
3737

38-
bool canBeLinked(Operation *op) const override {
39-
return isa<cir::GlobalOp>(op) || isa<cir::FuncOp>(op);
40-
}
38+
bool canBeLinked(Operation *op) const override;
4139

4240
//===--------------------------------------------------------------------===//
4341
// LLVMLinkerMixin required methods from derived linker interface
4442
//===--------------------------------------------------------------------===//
4543

46-
// TODO: expose convertLinkage from LowerToLLVM.cpp
47-
static Linkage toLLVMLinkage(cir::GlobalLinkageKind linkage) {
48-
using CIR = cir::GlobalLinkageKind;
49-
using LLVM = mlir::LLVM::Linkage;
50-
51-
switch (linkage) {
52-
case CIR::AvailableExternallyLinkage:
53-
return LLVM::AvailableExternally;
54-
case CIR::CommonLinkage:
55-
return LLVM::Common;
56-
case CIR::ExternalLinkage:
57-
return LLVM::External;
58-
case CIR::ExternalWeakLinkage:
59-
return LLVM::ExternWeak;
60-
case CIR::InternalLinkage:
61-
return LLVM::Internal;
62-
case CIR::LinkOnceAnyLinkage:
63-
return LLVM::Linkonce;
64-
case CIR::LinkOnceODRLinkage:
65-
return LLVM::LinkonceODR;
66-
case CIR::PrivateLinkage:
67-
return LLVM::Private;
68-
case CIR::WeakAnyLinkage:
69-
return LLVM::Weak;
70-
case CIR::WeakODRLinkage:
71-
return LLVM::WeakODR;
72-
};
73-
}
74-
75-
static Linkage getLinkage(Operation *op) {
76-
if (auto gv = dyn_cast<cir::GlobalOp>(op))
77-
return toLLVMLinkage(gv.getLinkage());
78-
if (auto fn = dyn_cast<cir::FuncOp>(op))
79-
return toLLVMLinkage(fn.getLinkage());
80-
llvm_unreachable("unexpected operation");
81-
}
82-
83-
static bool isComdat(Operation *op) {
84-
// TODO(frabert): Extracting comdat info from CIR is not implemented yet
85-
return false;
86-
}
44+
static Linkage getLinkage(Operation *op);
45+
46+
static bool isComdat(Operation *op);
8747

8848
static std::optional<mlir::link::ComdatSelector>
89-
getComdatSelector(Operation *op) {
90-
// TODO(frabert): Extracting comdat info from CIR is not implemented yet
91-
return std::nullopt;
92-
}
93-
94-
// TODO: expose lowerCIRVisibilityToLLVMVisibility from LowerToLLVM.cpp
95-
static Visibility toLLVMVisibility(cir::VisibilityAttr visibility) {
96-
return toLLVMVisibility(visibility.getValue());
97-
}
98-
99-
static Visibility toLLVMVisibility(cir::VisibilityKind visibility) {
100-
using CIR = cir::VisibilityKind;
101-
using LLVM = mlir::LLVM::Visibility;
102-
103-
switch (visibility) {
104-
case CIR::Default:
105-
return LLVM::Default;
106-
case CIR::Hidden:
107-
return LLVM::Hidden;
108-
case CIR::Protected:
109-
return LLVM::Protected;
110-
};
111-
}
112-
113-
static cir::VisibilityKind toCIRVisibility(Visibility visibility) {
114-
using CIR = cir::VisibilityKind;
115-
using LLVM = mlir::LLVM::Visibility;
116-
117-
switch (visibility) {
118-
case LLVM::Default:
119-
return CIR::Default;
120-
case LLVM::Hidden:
121-
return CIR::Hidden;
122-
case LLVM::Protected:
123-
return CIR::Protected;
124-
};
125-
}
126-
127-
static cir::VisibilityAttr toCIRVisibilityAttr(Visibility visibility,
128-
MLIRContext *mlirContext) {
129-
return cir::VisibilityAttr::get(mlirContext, toCIRVisibility(visibility));
130-
}
131-
132-
static Visibility getVisibility(Operation *op) {
133-
if (auto gv = dyn_cast<cir::GlobalOp>(op))
134-
return toLLVMVisibility(gv.getGlobalVisibility());
135-
if (auto fn = dyn_cast<cir::FuncOp>(op))
136-
return toLLVMVisibility(fn.getGlobalVisibility());
137-
llvm_unreachable("unexpected operation");
138-
}
139-
140-
static void setVisibility(Operation *op, Visibility visibility) {
141-
if (auto gv = dyn_cast<cir::GlobalOp>(op))
142-
return gv.setGlobalVisibilityAttr(
143-
toCIRVisibilityAttr(visibility, op->getContext()));
144-
if (auto fn = dyn_cast<cir::FuncOp>(op))
145-
return fn.setGlobalVisibilityAttr(
146-
toCIRVisibilityAttr(visibility, op->getContext()));
147-
llvm_unreachable("unexpected operation");
148-
}
149-
150-
static bool isDeclaration(Operation *op) {
151-
if (auto gv = dyn_cast<cir::GlobalOp>(op))
152-
return gv.isDeclaration();
153-
if (auto fn = dyn_cast<cir::FuncOp>(op))
154-
return fn.isDeclaration();
155-
llvm_unreachable("unexpected operation");
156-
}
157-
158-
static unsigned getBitWidth(Operation *op) { llvm_unreachable("NYI"); }
159-
160-
// FIXME: CIR does not yet have UnnamedAddr attribute
161-
static UnnamedAddr getUnnamedAddr(Operation * /* op*/) {
162-
return UnnamedAddr::Global;
163-
}
164-
165-
// FIXME: CIR does not yet have UnnamedAddr attribute
166-
static void setUnnamedAddr(Operation * /* op*/, UnnamedAddr addr) {}
167-
168-
static std::optional<uint64_t> getAlignment(Operation *op) {
169-
if (auto gv = dyn_cast<cir::GlobalOp>(op))
170-
return gv.getAlignment();
171-
// FIXME: CIR does not (yet?) have alignment for functions
172-
llvm_unreachable("unexpected operation");
173-
}
174-
175-
static void setAlignment(Operation *op, std::optional<uint64_t> align) {
176-
if (auto gv = dyn_cast<cir::GlobalOp>(op))
177-
return gv.setAlignment(align);
178-
// FIXME: CIR does not (yet?) have alignment for functions
179-
llvm_unreachable("unexpected operation");
180-
}
181-
182-
static bool isConstant(Operation *op) {
183-
if (auto gv = dyn_cast<cir::GlobalOp>(op))
184-
return gv.getConstant();
185-
llvm_unreachable("unexpected operation");
186-
}
187-
188-
static void setIsConstant(Operation *op, bool value) {
189-
if (auto gv = dyn_cast<cir::GlobalOp>(op))
190-
return gv.setConstant(value);
191-
llvm_unreachable("constness setting allowed only for globals");
192-
}
193-
194-
static bool isGlobalVar(Operation *op) { return isa<cir::GlobalOp>(op); }
195-
196-
static llvm::StringRef getSection(Operation *op) {
197-
if (auto gv = dyn_cast<cir::GlobalOp>(op)) {
198-
auto section = gv.getSection();
199-
return section ? section.value() : llvm::StringRef();
200-
}
201-
// FIXME: CIR func does not yet have section attribute
202-
llvm_unreachable("unexpected operation");
203-
}
204-
205-
static std::optional<cir::AddressSpaceAttr> getAddressSpace(Operation *op) {
206-
if (auto gv = dyn_cast<cir::GlobalOp>(op)) {
207-
if (auto addrSpace = gv.getAddrSpaceAttr()) {
208-
return addrSpace;
209-
}
210-
return std::nullopt;
211-
}
212-
213-
llvm_unreachable("unexpected operation");
214-
}
49+
getComdatSelector(Operation *op);
50+
51+
static Visibility getVisibility(Operation *op);
52+
53+
static void setVisibility(Operation *op, Visibility visibility);
54+
55+
static bool isDeclaration(Operation *op);
56+
57+
static unsigned getBitWidth(Operation *op);
58+
59+
static UnnamedAddr getUnnamedAddr(Operation *op);
60+
61+
static void setUnnamedAddr(Operation *op, UnnamedAddr addr);
62+
63+
static std::optional<uint64_t> getAlignment(Operation *op);
64+
65+
static void setAlignment(Operation *op, std::optional<uint64_t> align);
66+
67+
static bool isConstant(Operation *op);
68+
69+
static void setIsConstant(Operation *op, bool value);
70+
71+
static bool isGlobalVar(Operation *op);
72+
73+
static llvm::StringRef getSection(Operation *op);
74+
75+
static std::optional<cir::AddressSpace> getAddressSpace(Operation *op);
21576
};
21677

21778
void registerLinkerInterface(mlir::DialectRegistry &registry);

0 commit comments

Comments
 (0)