[llvm] [AMDGPU] Add AMDGPU specific variadic operation MCExprs (PR #82022)
Pierre van Houtryve via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 26 04:31:14 PST 2024
================
@@ -0,0 +1,69 @@
+//===- AMDGPUMCExpr.h - AMDGPU specific MC expression classes ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUMCEXPR_H
+#define LLVM_LIB_TARGET_AMDGPU_MCTARGETDESC_AMDGPUMCEXPR_H
+
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/MC/MCExpr.h"
+
+namespace llvm {
+
+/// AMDGPU target specific variadic MCExpr operations.
+///
+/// Takes in a minimum of 1 argument to be used with an operation. The supported
+/// operations are:
+/// - (logic) or
+/// - max
+///
+class AMDGPUVariadicMCExpr : public MCTargetExpr {
+public:
+ enum AMDGPUVariadicKind { AGVK_None, AGVK_Or, AGVK_Max };
+
+private:
+ AMDGPUVariadicKind Kind;
+ SmallVector<const MCExpr *, 2> Args;
+
+ AMDGPUVariadicMCExpr(AMDGPUVariadicKind Kind, ArrayRef<const MCExpr *> Args)
+ : Kind(Kind), Args(Args) {
+ assert(Args.size() >= 1 && "Needs a minimum of one expression.");
+ }
+
+public:
+ static const AMDGPUVariadicMCExpr *create(AMDGPUVariadicKind Kind,
+ ArrayRef<const MCExpr *> Args,
+ MCContext &Ctx);
+
+ static const AMDGPUVariadicMCExpr *createOr(ArrayRef<const MCExpr *> Args,
+ MCContext &Ctx) {
+ return create(AMDGPUVariadicKind::AGVK_Or, Args, Ctx);
+ }
+
+ static const AMDGPUVariadicMCExpr *createMax(ArrayRef<const MCExpr *> Args,
+ MCContext &Ctx) {
+ return create(AMDGPUVariadicKind::AGVK_Max, Args, Ctx);
+ }
+
+ AMDGPUVariadicKind getKind() const { return Kind; }
+ const MCExpr *getSubExpr(size_t index) const;
+
+ void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
+ bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
+ const MCFixup *Fixup) const override;
+ void visitUsedExpr(MCStreamer &Streamer) const override;
+ MCFragment *findAssociatedFragment() const override;
+ static bool classof(const MCExpr *E) {
----------------
Pierre-vh wrote:
move this at the bottom with a newline before it, it's just the RTTI helper so it should be isolated
I also think it's better for style to not mix one-liners (the decls) with multiple line functions (this def) without a newline in between
https://github.com/llvm/llvm-project/pull/82022
More information about the llvm-commits
mailing list