Skip to content

Commit 036e7db

Browse files
MaskRayrorth
authored andcommitted
MCExpr: Move isSymbolUsedInExpression workaround to AMDGPU
This function was a workaround used to detect cyclic dependency (properly resolved by 343428c). We do not want backends to use it. However, llvm#112251 exposed it to MCExpr to be reused by AMDGPU. Keep the workaround within AMDGPU to prevent other backends from accidentally relying on it.
1 parent 510273e commit 036e7db

File tree

5 files changed

+36
-50
lines changed

5 files changed

+36
-50
lines changed

llvm/include/llvm/MC/MCExpr.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ class MCExpr {
8686
int SurroundingPrec = 0) const;
8787
LLVM_ABI void dump() const;
8888

89-
/// Returns whether the given symbol is used anywhere in the expression or
90-
/// subexpressions.
91-
LLVM_ABI bool isSymbolUsedInExpression(const MCSymbol *Sym) const;
92-
9389
/// @}
9490
/// \name Expression Evaluation
9591
/// @{
@@ -489,9 +485,6 @@ class LLVM_ABI MCTargetExpr : public MCExpr {
489485
const MCAssembler *Asm) const = 0;
490486
// allow Target Expressions to be checked for equality
491487
virtual bool isEqualTo(const MCExpr *x) const { return false; }
492-
virtual bool isSymbolUsedInExpression(const MCSymbol *Sym) const {
493-
return false;
494-
}
495488
// This should be set when assigned expressions are not valid ".set"
496489
// expressions, e.g. registers, and must be inlined.
497490
virtual bool inlineAssignedExpr() const { return false; }

llvm/lib/MC/MCExpr.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -187,38 +187,6 @@ LLVM_DUMP_METHOD void MCExpr::dump() const {
187187
}
188188
#endif
189189

190-
bool MCExpr::isSymbolUsedInExpression(const MCSymbol *Sym) const {
191-
switch (getKind()) {
192-
case MCExpr::Binary: {
193-
const MCBinaryExpr *BE = static_cast<const MCBinaryExpr *>(this);
194-
return BE->getLHS()->isSymbolUsedInExpression(Sym) ||
195-
BE->getRHS()->isSymbolUsedInExpression(Sym);
196-
}
197-
case MCExpr::Target: {
198-
const MCTargetExpr *TE = static_cast<const MCTargetExpr *>(this);
199-
return TE->isSymbolUsedInExpression(Sym);
200-
}
201-
case MCExpr::Constant:
202-
return false;
203-
case MCExpr::SymbolRef: {
204-
const MCSymbol &S = static_cast<const MCSymbolRefExpr *>(this)->getSymbol();
205-
if (S.isVariable() && !S.isWeakExternal())
206-
return S.getVariableValue()->isSymbolUsedInExpression(Sym);
207-
return &S == Sym;
208-
}
209-
case MCExpr::Unary: {
210-
const MCExpr *SubExpr =
211-
static_cast<const MCUnaryExpr *>(this)->getSubExpr();
212-
return SubExpr->isSymbolUsedInExpression(Sym);
213-
}
214-
case MCExpr::Specifier:
215-
return static_cast<const MCSpecifierExpr *>(this)->isSymbolUsedInExpression(
216-
Sym);
217-
}
218-
219-
llvm_unreachable("Unknown expr kind!");
220-
}
221-
222190
/* *** */
223191

224192
const MCBinaryExpr *MCBinaryExpr::create(Opcode Opc, const MCExpr *LHS,

llvm/lib/Target/AMDGPU/AMDGPUMCResourceInfo.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ void MCResourceInfo::assignResourceInfoExpr(
127127
// Avoid constructing recursive definitions by detecting whether `Sym` is
128128
// found transitively within any of its `CalleeValSym`.
129129
if (!CalleeValSym->isVariable() ||
130-
!CalleeValSym->getVariableValue()->isSymbolUsedInExpression(Sym)) {
130+
!AMDGPUMCExpr::isSymbolUsedInExpression(
131+
Sym, CalleeValSym->getVariableValue())) {
131132
LLVM_DEBUG(dbgs() << "MCResUse: " << Sym->getName() << ": Adding "
132133
<< CalleeValSym->getName() << " as callee\n");
133134
ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext));
@@ -243,7 +244,8 @@ void MCResourceInfo::gatherResourceInfo(
243244
// Avoid constructing recursive definitions by detecting whether `Sym`
244245
// is found transitively within any of its `CalleeValSym`.
245246
if (!CalleeValSym->isVariable() ||
246-
!CalleeValSym->getVariableValue()->isSymbolUsedInExpression(Sym)) {
247+
!AMDGPUMCExpr::isSymbolUsedInExpression(
248+
Sym, CalleeValSym->getVariableValue())) {
247249
LLVM_DEBUG(dbgs() << "MCResUse: " << Sym->getName() << ": Adding "
248250
<< CalleeValSym->getName() << " as callee\n");
249251
ArgExprs.push_back(MCSymbolRefExpr::create(CalleeValSym, OutContext));

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.cpp

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,37 @@ bool AMDGPUMCExpr::evaluateOccupancy(MCValue &Res,
214214
return true;
215215
}
216216

217+
bool AMDGPUMCExpr::isSymbolUsedInExpression(const MCSymbol *Sym,
218+
const MCExpr *E) {
219+
switch (E->getKind()) {
220+
case MCExpr::Constant:
221+
return false;
222+
case MCExpr::Unary:
223+
return isSymbolUsedInExpression(
224+
Sym, static_cast<const MCUnaryExpr *>(E)->getSubExpr());
225+
case MCExpr::Binary: {
226+
const MCBinaryExpr *BE = static_cast<const MCBinaryExpr *>(E);
227+
return isSymbolUsedInExpression(Sym, BE->getLHS()) ||
228+
isSymbolUsedInExpression(Sym, BE->getRHS());
229+
}
230+
case MCExpr::SymbolRef: {
231+
const MCSymbol &S = static_cast<const MCSymbolRefExpr *>(E)->getSymbol();
232+
if (S.isVariable())
233+
return isSymbolUsedInExpression(Sym, S.getVariableValue());
234+
return &S == Sym;
235+
}
236+
case MCExpr::Specifier:
237+
case MCExpr::Target: {
238+
auto *TE = static_cast<const AMDGPUMCExpr *>(E);
239+
for (const MCExpr *E : TE->getArgs())
240+
if (isSymbolUsedInExpression(Sym, E))
241+
return true;
242+
return false;
243+
}
244+
}
245+
llvm_unreachable("Unknown expr kind!");
246+
}
247+
217248
bool AMDGPUMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
218249
const MCAssembler *Asm) const {
219250
std::optional<int64_t> Total;
@@ -303,14 +334,6 @@ const AMDGPUMCExpr *AMDGPUMCExpr::createOccupancy(unsigned InitOcc,
303334
Ctx);
304335
}
305336

306-
bool AMDGPUMCExpr::isSymbolUsedInExpression(const MCSymbol *Sym) const {
307-
for (const MCExpr *E : getArgs()) {
308-
if (E->isSymbolUsedInExpression(Sym))
309-
return true;
310-
}
311-
return false;
312-
}
313-
314337
static KnownBits fromOptionalToKnownBits(std::optional<bool> CompareResult) {
315338
static constexpr unsigned BitWidth = 64;
316339
const APInt True(BitWidth, 1);

llvm/lib/Target/AMDGPU/MCTargetDesc/AMDGPUMCExpr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ class AMDGPUMCExpr : public MCTargetExpr {
106106
void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
107107
bool evaluateAsRelocatableImpl(MCValue &Res,
108108
const MCAssembler *Asm) const override;
109-
bool isSymbolUsedInExpression(const MCSymbol *Sym) const override;
110109
void visitUsedExpr(MCStreamer &Streamer) const override;
111110
MCFragment *findAssociatedFragment() const override;
112111

113112
static bool classof(const MCExpr *E) {
114113
return E->getKind() == MCExpr::Target;
115114
}
115+
static bool isSymbolUsedInExpression(const MCSymbol *Sym, const MCExpr *E);
116116
};
117117

118118
namespace AMDGPU {

0 commit comments

Comments
 (0)