diff options
author | Janek van Oirschot <janek.vanoirschot@amd.com> | 2024-11-15 18:40:05 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-15 18:40:05 +0000 |
commit | bd9145c8c21334e099d51b3e66f49d51d24931ee (patch) | |
tree | 7d14bffdd5b52159a7b0c2a3585f8c46df1589b6 /llvm/lib/MC/MCExpr.cpp | |
parent | 098b0d18add97dea94e16006486b2fded65e228d (diff) | |
download | llvm-bd9145c8c21334e099d51b3e66f49d51d24931ee.zip llvm-bd9145c8c21334e099d51b3e66f49d51d24931ee.tar.gz llvm-bd9145c8c21334e099d51b3e66f49d51d24931ee.tar.bz2 |
Reapply [AMDGPU] Avoid resource propagation for recursion through multiple functions (#112251)
I was wrong last patch. I viewed the `Visited` set purely as a possible
recursion deterrent where functions calling a callee multiple times are
handled elsewhere. This doesn't consider cases where a function is
called multiple times by different callers still part of the same call
graph. New test shows the aforementioned case.
Reapplies #111004, fixes #115562.
Diffstat (limited to 'llvm/lib/MC/MCExpr.cpp')
-rw-r--r-- | llvm/lib/MC/MCExpr.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp index c9d5f65..ede7655 100644 --- a/llvm/lib/MC/MCExpr.cpp +++ b/llvm/lib/MC/MCExpr.cpp @@ -177,6 +177,35 @@ LLVM_DUMP_METHOD void MCExpr::dump() const { } #endif +bool MCExpr::isSymbolUsedInExpression(const MCSymbol *Sym) const { + switch (getKind()) { + case MCExpr::Binary: { + const MCBinaryExpr *BE = static_cast<const MCBinaryExpr *>(this); + return BE->getLHS()->isSymbolUsedInExpression(Sym) || + BE->getRHS()->isSymbolUsedInExpression(Sym); + } + case MCExpr::Target: { + const MCTargetExpr *TE = static_cast<const MCTargetExpr *>(this); + return TE->isSymbolUsedInExpression(Sym); + } + case MCExpr::Constant: + return false; + case MCExpr::SymbolRef: { + const MCSymbol &S = static_cast<const MCSymbolRefExpr *>(this)->getSymbol(); + if (S.isVariable() && !S.isWeakExternal()) + return S.getVariableValue()->isSymbolUsedInExpression(Sym); + return &S == Sym; + } + case MCExpr::Unary: { + const MCExpr *SubExpr = + static_cast<const MCUnaryExpr *>(this)->getSubExpr(); + return SubExpr->isSymbolUsedInExpression(Sym); + } + } + + llvm_unreachable("Unknown expr kind!"); +} + /* *** */ const MCBinaryExpr *MCBinaryExpr::create(Opcode Opc, const MCExpr *LHS, |