Skip to content

Commit 0bedc28

Browse files
authored
[CIR] Clean up and complete CIRGlobalValueInterface methods (#1423)
Cleans up default linkage query implementations. Removes duplicities from `extraClassDeclaration` that are now introduced through `CIRGlobalValueInterface`. This makes it more consistent with the `llvm::GlobalValue` methods.
1 parent a018447 commit 0bedc28

File tree

3 files changed

+75
-20
lines changed

3 files changed

+75
-20
lines changed

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,15 +2482,6 @@ def GlobalOp : CIR_Op<"global",
24822482
return !getInitialValue() && getCtorRegion().empty() && getDtorRegion().empty();
24832483
}
24842484
bool hasInitializer() { return !isDeclaration(); }
2485-
bool hasAvailableExternallyLinkage() {
2486-
return cir::isAvailableExternallyLinkage(getLinkage());
2487-
}
2488-
bool hasInternalLinkage() {
2489-
return cir::isInternalLinkage(getLinkage());
2490-
}
2491-
/// Whether the definition of this global may be replaced at link time.
2492-
bool isWeakForLinker() { return cir::isWeakForLinker(getLinkage()); }
2493-
bool isDSOLocal() { return getDsolocal(); }
24942485
}];
24952486

24962487
let skipDefaultBuilders = 1;
@@ -3602,10 +3593,6 @@ def FuncOp : CIR_Op<"func", [
36023593
//===------------------------------------------------------------------===//
36033594

36043595
bool isDeclaration();
3605-
3606-
bool hasAvailableExternallyLinkage() {
3607-
return cir::isAvailableExternallyLinkage(getLinkage());
3608-
}
36093596
}];
36103597

36113598
let hasCustomAssemblyFormat = 1;

clang/include/clang/CIR/Interfaces/CIROpInterfaces.td

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,65 @@ let cppNamespace = "::cir" in {
4747
: OpInterface<"CIRGlobalValueInterface", [Symbol]> {
4848

4949
let methods = [
50+
InterfaceMethod<"",
51+
"bool", "hasExternalLinkage", (ins), [{}],
52+
/*defaultImplementation=*/[{
53+
return cir::isExternalLinkage($_op.getLinkage());
54+
}]
55+
>,
5056
InterfaceMethod<"",
5157
"bool", "hasAvailableExternallyLinkage", (ins), [{}],
52-
/*defaultImplementation=*/[{ return false; }]
58+
/*defaultImplementation=*/[{
59+
return cir::isAvailableExternallyLinkage($_op.getLinkage());
60+
}]
61+
>,
62+
InterfaceMethod<"",
63+
"bool", "hasLinkOnceLinkage", (ins), [{}],
64+
/*defaultImplementation=*/[{
65+
return cir::isLinkOnceLinkage($_op.getLinkage());
66+
}]
67+
>,
68+
InterfaceMethod<"",
69+
"bool", "hasLinkOnceAnyLinkage", (ins), [{}],
70+
/*defaultImplementation=*/[{
71+
return cir::isLinkOnceAnyLinkage($_op.getLinkage());
72+
}]
73+
>,
74+
InterfaceMethod<"",
75+
"bool", "hasLinkOnceODRLinkage", (ins), [{}],
76+
/*defaultImplementation=*/[{
77+
return cir::isLinkOnceODRLinkage($_op.getLinkage());
78+
}]
79+
>,
80+
InterfaceMethod<"",
81+
"bool", "hasWeakLinkage", (ins), [{}],
82+
/*defaultImplementation=*/[{
83+
return cir::isWeakLinkage($_op.getLinkage());
84+
}]
85+
>,
86+
InterfaceMethod<"",
87+
"bool", "hasWeakAnyLinkage", (ins), [{}],
88+
/*defaultImplementation=*/[{
89+
return cir::isWeakAnyLinkage($_op.getLinkage());
90+
}]
91+
>,
92+
InterfaceMethod<"",
93+
"bool", "hasWeakODRLinkage", (ins), [{}],
94+
/*defaultImplementation=*/[{
95+
return cir::isWeakODRLinkage($_op.getLinkage());
96+
}]
97+
>,
98+
InterfaceMethod<"",
99+
"bool", "hasInternalLinkage", (ins), [{}],
100+
/*defaultImplementation=*/[{
101+
return cir::isInternalLinkage($_op.getLinkage());
102+
}]
103+
>,
104+
InterfaceMethod<"",
105+
"bool", "hasPrivateLinkage", (ins), [{}],
106+
/*defaultImplementation=*/[{
107+
return cir::isPrivateLinkage($_op.getLinkage());
108+
}]
53109
>,
54110
InterfaceMethod<"",
55111
"bool", "hasLocalLinkage", (ins), [{}],
@@ -64,9 +120,9 @@ let cppNamespace = "::cir" in {
64120
}]
65121
>,
66122
InterfaceMethod<"",
67-
"bool", "isExternalLinkage", (ins), [{}],
123+
"bool", "hasCommonLinkage", (ins), [{}],
68124
/*defaultImplementation=*/[{
69-
return cir::isExternalLinkage($_op.getLinkage());
125+
return cir::isCommonLinkage($_op.getLinkage());
70126
}]
71127
>,
72128
InterfaceMethod<"",
@@ -89,11 +145,23 @@ let cppNamespace = "::cir" in {
89145
$_op.setDsolocal(val);
90146
}]
91147
>,
148+
InterfaceMethod<"",
149+
"bool", "isDSOLocal", (ins), [{}],
150+
/*defaultImplementation=*/[{
151+
return $_op.getDsolocal();
152+
}]
153+
>,
154+
InterfaceMethod<"",
155+
"bool", "isWeakForLinker", (ins), [{}],
156+
/*defaultImplementation=*/[{
157+
return cir::isWeakForLinker($_op.getLinkage());
158+
}]
159+
>
92160
];
93161
let extraClassDeclaration = [{
94-
bool hasDefaultVisibility();
95-
bool canBenefitFromLocalAlias();
96-
}];
162+
bool hasDefaultVisibility();
163+
bool canBenefitFromLocalAlias();
164+
}];
97165
}
98166

99167
} // namespace cir

clang/lib/CIR/Interfaces/CIROpInterfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ bool CIRGlobalValueInterface::canBenefitFromLocalAlias() {
3131
// wouldn't even generate Comdat::Largest comdat as it tries to leave ABI
3232
// specifics to LLVM lowering stage, thus here we don't need test Comdat
3333
// selectionKind.
34-
return hasDefaultVisibility() && isExternalLinkage() && !isDeclaration() &&
34+
return hasDefaultVisibility() && hasExternalLinkage() && !isDeclaration() &&
3535
!hasComdat();
3636
return false;
3737
}

0 commit comments

Comments
 (0)