mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-15 23:40:54 +00:00
Rename OpBase -> Op.
PiperOrigin-RevId: 214676460
This commit is contained in:
parent
501462ac47
commit
aed24ff553
@ -16,7 +16,7 @@
|
||||
// =============================================================================
|
||||
//
|
||||
// This file implements helper classes for implementing the "Op" types. This
|
||||
// includes the OpBase type, which is the base class for Op class definitions,
|
||||
// includes the Op type, which is the base class for Op class definitions,
|
||||
// as well as number of traits in the OpTrait namespace that provide a
|
||||
// declarative way to specify properties of Ops.
|
||||
//
|
||||
@ -93,7 +93,7 @@ private:
|
||||
///
|
||||
/// This also has the fallback implementations of customization hooks for when
|
||||
/// they aren't customized.
|
||||
class OpBaseState {
|
||||
class OpState {
|
||||
public:
|
||||
/// Return the operation that this refers to.
|
||||
const Operation *getOperation() const { return state; }
|
||||
@ -153,7 +153,7 @@ protected:
|
||||
|
||||
/// Mutability management is handled by the OpWrapper/OpConstWrapper classes,
|
||||
/// so we can cast it away here.
|
||||
explicit OpBaseState(const Operation *state)
|
||||
explicit OpState(const Operation *state)
|
||||
: state(const_cast<Operation *>(state)) {}
|
||||
|
||||
private:
|
||||
@ -227,7 +227,7 @@ protected:
|
||||
// be able to disambiguate the path for the C++ compiler.
|
||||
auto *trait = static_cast<TraitType<ConcreteType> *>(this);
|
||||
auto *concrete = static_cast<ConcreteType *>(trait);
|
||||
auto *base = static_cast<OpBaseState *>(concrete);
|
||||
auto *base = static_cast<OpState *>(concrete);
|
||||
return base->getOperation();
|
||||
}
|
||||
const Operation *getOperation() const {
|
||||
@ -281,7 +281,7 @@ public:
|
||||
/// This class provides the API for ops that are known to have a specified
|
||||
/// number of operands. This is used as a trait like this:
|
||||
///
|
||||
/// class FooOp : public OpBase<FooOp, OpTrait::NOperands<2>::Impl> {
|
||||
/// class FooOp : public Op<FooOp, OpTrait::NOperands<2>::Impl> {
|
||||
///
|
||||
template <unsigned N> class NOperands {
|
||||
public:
|
||||
@ -311,7 +311,7 @@ public:
|
||||
/// This class provides the API for ops that are known to have a at least a
|
||||
/// specified number of operands. This is used as a trait like this:
|
||||
///
|
||||
/// class FooOp : public OpBase<FooOp, OpTrait::AtLeastNOperands<2>::Impl> {
|
||||
/// class FooOp : public Op<FooOp, OpTrait::AtLeastNOperands<2>::Impl> {
|
||||
///
|
||||
template <unsigned N> class AtLeastNOperands {
|
||||
public:
|
||||
@ -451,7 +451,7 @@ public:
|
||||
/// This class provides the API for ops that are known to have a specified
|
||||
/// number of results. This is used as a trait like this:
|
||||
///
|
||||
/// class FooOp : public OpBase<FooOp, OpTrait::NResults<2>::Impl> {
|
||||
/// class FooOp : public Op<FooOp, OpTrait::NResults<2>::Impl> {
|
||||
///
|
||||
template <unsigned N> class NResults {
|
||||
public:
|
||||
@ -479,7 +479,7 @@ public:
|
||||
/// This class provides the API for ops that are known to have at least a
|
||||
/// specified number of results. This is used as a trait like this:
|
||||
///
|
||||
/// class FooOp : public OpBase<FooOp, OpTrait::AtLeastNResults<2>::Impl> {
|
||||
/// class FooOp : public Op<FooOp, OpTrait::AtLeastNResults<2>::Impl> {
|
||||
///
|
||||
template <unsigned N> class AtLeastNResults {
|
||||
public:
|
||||
@ -576,17 +576,16 @@ public:
|
||||
/// argument 'ConcreteType' should be the concrete type by CRTP and the others
|
||||
/// are base classes by the policy pattern.
|
||||
template <typename ConcreteType, template <typename T> class... Traits>
|
||||
class OpBase
|
||||
: public OpBaseState,
|
||||
public Traits<ConcreteType>...,
|
||||
public ConstFoldingHook<
|
||||
ConcreteType,
|
||||
typelist_contains<OpTrait::OneResult<ConcreteType>, OpBaseState,
|
||||
Traits<ConcreteType>...>::value> {
|
||||
class Op : public OpState,
|
||||
public Traits<ConcreteType>...,
|
||||
public ConstFoldingHook<
|
||||
ConcreteType,
|
||||
typelist_contains<OpTrait::OneResult<ConcreteType>, OpState,
|
||||
Traits<ConcreteType>...>::value> {
|
||||
public:
|
||||
/// Return the operation that this refers to.
|
||||
const Operation *getOperation() const { return OpBaseState::getOperation(); }
|
||||
Operation *getOperation() { return OpBaseState::getOperation(); }
|
||||
const Operation *getOperation() const { return OpState::getOperation(); }
|
||||
Operation *getOperation() { return OpState::getOperation(); }
|
||||
|
||||
/// Return true if this "op class" can match against the specified operation.
|
||||
/// This hook can be overridden with a more specific implementation in
|
||||
@ -625,7 +624,7 @@ public:
|
||||
// TODO: Provide a dump() method.
|
||||
|
||||
protected:
|
||||
explicit OpBase(const Operation *state) : OpBaseState(state) {}
|
||||
explicit Op(const Operation *state) : OpState(state) {}
|
||||
|
||||
private:
|
||||
template <typename... Types> struct BaseVerifier;
|
||||
@ -664,9 +663,9 @@ void printBinaryOp(const Operation *op, OpAsmPrinter *p);
|
||||
/// From this structure, subclasses get a standard builder, parser and printer.
|
||||
///
|
||||
template <typename ConcreteType, template <typename T> class... Traits>
|
||||
class BinaryOp : public OpBase<ConcreteType, OpTrait::NOperands<2>::Impl,
|
||||
OpTrait::OneResult,
|
||||
OpTrait::SameOperandsAndResultType, Traits...> {
|
||||
class BinaryOp
|
||||
: public Op<ConcreteType, OpTrait::NOperands<2>::Impl, OpTrait::OneResult,
|
||||
OpTrait::SameOperandsAndResultType, Traits...> {
|
||||
public:
|
||||
static void build(Builder *builder, OperationState *result, SSAValue *lhs,
|
||||
SSAValue *rhs) {
|
||||
@ -681,8 +680,8 @@ public:
|
||||
|
||||
protected:
|
||||
explicit BinaryOp(const Operation *state)
|
||||
: OpBase<ConcreteType, OpTrait::NOperands<2>::Impl, OpTrait::OneResult,
|
||||
OpTrait::SameOperandsAndResultType, Traits...>(state) {}
|
||||
: Op<ConcreteType, OpTrait::NOperands<2>::Impl, OpTrait::OneResult,
|
||||
OpTrait::SameOperandsAndResultType, Traits...>(state) {}
|
||||
};
|
||||
|
||||
} // end namespace mlir
|
||||
|
@ -63,8 +63,8 @@ private:
|
||||
/// #map42 = (d0)->(d0+1)
|
||||
/// %y = affine_apply #map42(%x)
|
||||
///
|
||||
class AffineApplyOp : public OpBase<AffineApplyOp, OpTrait::VariadicOperands,
|
||||
OpTrait::VariadicResults> {
|
||||
class AffineApplyOp : public Op<AffineApplyOp, OpTrait::VariadicOperands,
|
||||
OpTrait::VariadicResults> {
|
||||
public:
|
||||
/// Builds an affine apply op with the specified map and operands.
|
||||
static void build(Builder *builder, OperationState *result, AffineMap *map,
|
||||
@ -93,7 +93,7 @@ public:
|
||||
|
||||
private:
|
||||
friend class Operation;
|
||||
explicit AffineApplyOp(const Operation *state) : OpBase(state) {}
|
||||
explicit AffineApplyOp(const Operation *state) : Op(state) {}
|
||||
};
|
||||
|
||||
/// The "alloc" operation allocates a region of memory, as specified by its
|
||||
@ -116,7 +116,7 @@ private:
|
||||
/// This operation returns a single ssa value of memref type, which can be used
|
||||
/// by subsequent load and store operations.
|
||||
class AllocOp
|
||||
: public OpBase<AllocOp, OpTrait::VariadicOperands, OpTrait::OneResult> {
|
||||
: public Op<AllocOp, OpTrait::VariadicOperands, OpTrait::OneResult> {
|
||||
public:
|
||||
SSAValue *getMemRef() { return getOperation()->getResult(0); }
|
||||
const SSAValue *getMemRef() const { return getOperation()->getResult(0); }
|
||||
@ -132,7 +132,7 @@ public:
|
||||
|
||||
private:
|
||||
friend class Operation;
|
||||
explicit AllocOp(const Operation *state) : OpBase(state) {}
|
||||
explicit AllocOp(const Operation *state) : Op(state) {}
|
||||
};
|
||||
|
||||
/// The "call" operation represents a direct call to a function. The operands
|
||||
@ -141,8 +141,8 @@ private:
|
||||
///
|
||||
/// %31 = call @my_add(%0, %1)
|
||||
/// : (tensor<16xf32>, tensor<16xf32>) -> tensor<16xf32>
|
||||
class CallOp : public OpBase<CallOp, OpTrait::VariadicOperands,
|
||||
OpTrait::VariadicResults> {
|
||||
class CallOp
|
||||
: public Op<CallOp, OpTrait::VariadicOperands, OpTrait::VariadicResults> {
|
||||
public:
|
||||
static StringRef getOperationName() { return "call"; }
|
||||
|
||||
@ -160,7 +160,7 @@ public:
|
||||
|
||||
protected:
|
||||
friend class Operation;
|
||||
explicit CallOp(const Operation *state) : OpBase(state) {}
|
||||
explicit CallOp(const Operation *state) : Op(state) {}
|
||||
};
|
||||
|
||||
/// The "call_indirect" operation represents an indirect call to a value of
|
||||
@ -171,8 +171,8 @@ protected:
|
||||
/// %31 = call_indirect %15(%0, %1)
|
||||
/// : (tensor<16xf32>, tensor<16xf32>) -> tensor<16xf32>
|
||||
///
|
||||
class CallIndirectOp : public OpBase<CallIndirectOp, OpTrait::VariadicOperands,
|
||||
OpTrait::VariadicResults> {
|
||||
class CallIndirectOp : public Op<CallIndirectOp, OpTrait::VariadicOperands,
|
||||
OpTrait::VariadicResults> {
|
||||
public:
|
||||
static StringRef getOperationName() { return "call_indirect"; }
|
||||
|
||||
@ -189,7 +189,7 @@ public:
|
||||
|
||||
protected:
|
||||
friend class Operation;
|
||||
explicit CallIndirectOp(const Operation *state) : OpBase(state) {}
|
||||
explicit CallIndirectOp(const Operation *state) : Op(state) {}
|
||||
};
|
||||
|
||||
/// The "constant" operation requires a single attribute named "value".
|
||||
@ -199,7 +199,7 @@ protected:
|
||||
/// %2 = "constant"(){value: @foo} : (f32)->f32
|
||||
///
|
||||
class ConstantOp
|
||||
: public OpBase<ConstantOp, OpTrait::ZeroOperands, OpTrait::OneResult> {
|
||||
: public Op<ConstantOp, OpTrait::ZeroOperands, OpTrait::OneResult> {
|
||||
public:
|
||||
/// Builds a constant op with the specified attribute value and result type.
|
||||
static void build(Builder *builder, OperationState *result, Attribute *value,
|
||||
@ -218,7 +218,7 @@ public:
|
||||
|
||||
protected:
|
||||
friend class Operation;
|
||||
explicit ConstantOp(const Operation *state) : OpBase(state) {}
|
||||
explicit ConstantOp(const Operation *state) : Op(state) {}
|
||||
};
|
||||
|
||||
/// This is a refinement of the "constant" op for the case where it is
|
||||
@ -297,7 +297,7 @@ private:
|
||||
/// dealloc %0 : memref<8x64xf32, (d0, d1) -> (d0, d1), 1>
|
||||
///
|
||||
class DeallocOp
|
||||
: public OpBase<DeallocOp, OpTrait::OneOperand, OpTrait::ZeroResult> {
|
||||
: public Op<DeallocOp, OpTrait::OneOperand, OpTrait::ZeroResult> {
|
||||
public:
|
||||
SSAValue *getMemRef() { return getOperand(); }
|
||||
const SSAValue *getMemRef() const { return getOperand(); }
|
||||
@ -312,7 +312,7 @@ public:
|
||||
|
||||
private:
|
||||
friend class Operation;
|
||||
explicit DeallocOp(const Operation *state) : OpBase(state) {}
|
||||
explicit DeallocOp(const Operation *state) : Op(state) {}
|
||||
};
|
||||
|
||||
/// The "dim" operation takes a memref or tensor operand and returns an
|
||||
@ -321,7 +321,7 @@ private:
|
||||
///
|
||||
/// %1 = dim %0, 2 : tensor<?x?x?xf32>
|
||||
///
|
||||
class DimOp : public OpBase<DimOp, OpTrait::OneOperand, OpTrait::OneResult> {
|
||||
class DimOp : public Op<DimOp, OpTrait::OneOperand, OpTrait::OneResult> {
|
||||
public:
|
||||
/// This returns the dimension number that the 'dim' is inspecting.
|
||||
unsigned getIndex() const {
|
||||
@ -337,7 +337,7 @@ public:
|
||||
|
||||
private:
|
||||
friend class Operation;
|
||||
explicit DimOp(const Operation *state) : OpBase(state) {}
|
||||
explicit DimOp(const Operation *state) : Op(state) {}
|
||||
};
|
||||
|
||||
/// The "extract_element" op reads a tensor or vector and returns one element
|
||||
@ -351,9 +351,8 @@ private:
|
||||
///
|
||||
/// %3 = extract_element %0[%1, %2] : vector<4x4xi32>
|
||||
///
|
||||
class ExtractElementOp
|
||||
: public OpBase<ExtractElementOp, OpTrait::VariadicOperands,
|
||||
OpTrait::OneResult> {
|
||||
class ExtractElementOp : public Op<ExtractElementOp, OpTrait::VariadicOperands,
|
||||
OpTrait::OneResult> {
|
||||
public:
|
||||
static void build(Builder *builder, OperationState *result,
|
||||
SSAValue *aggregate, ArrayRef<SSAValue *> indices = {});
|
||||
@ -378,7 +377,7 @@ public:
|
||||
|
||||
private:
|
||||
friend class Operation;
|
||||
explicit ExtractElementOp(const Operation *state) : OpBase(state) {}
|
||||
explicit ExtractElementOp(const Operation *state) : Op(state) {}
|
||||
};
|
||||
|
||||
/// The "load" op reads an element from a memref specified by an index list. The
|
||||
@ -390,7 +389,7 @@ private:
|
||||
/// %3 = load %0[%1, %1] : memref<4x4xi32>
|
||||
///
|
||||
class LoadOp
|
||||
: public OpBase<LoadOp, OpTrait::VariadicOperands, OpTrait::OneResult> {
|
||||
: public Op<LoadOp, OpTrait::VariadicOperands, OpTrait::OneResult> {
|
||||
public:
|
||||
SSAValue *getMemRef() { return getOperand(0); }
|
||||
const SSAValue *getMemRef() const { return getOperand(0); }
|
||||
@ -414,7 +413,7 @@ public:
|
||||
|
||||
private:
|
||||
friend class Operation;
|
||||
explicit LoadOp(const Operation *state) : OpBase(state) {}
|
||||
explicit LoadOp(const Operation *state) : Op(state) {}
|
||||
};
|
||||
|
||||
/// The "mulf" operation takes two operands and returns one result, each of
|
||||
@ -446,7 +445,7 @@ private:
|
||||
/// return %0, %1 : i32, f8
|
||||
///
|
||||
class ReturnOp
|
||||
: public OpBase<ReturnOp, OpTrait::VariadicOperands, OpTrait::ZeroResult> {
|
||||
: public Op<ReturnOp, OpTrait::VariadicOperands, OpTrait::ZeroResult> {
|
||||
public:
|
||||
static StringRef getOperationName() { return "return"; }
|
||||
|
||||
@ -460,7 +459,7 @@ public:
|
||||
|
||||
private:
|
||||
friend class Operation;
|
||||
explicit ReturnOp(const Operation *state) : OpBase(state) {}
|
||||
explicit ReturnOp(const Operation *state) : Op(state) {}
|
||||
};
|
||||
|
||||
/// The "shape_cast" operation converts a tensor from one type to an equivalent
|
||||
@ -474,7 +473,7 @@ private:
|
||||
/// %2 = shape_cast %1 : tensor<??f32> to tensor<?x?xf32>
|
||||
///
|
||||
class ShapeCastOp
|
||||
: public OpBase<ShapeCastOp, OpTrait::OneOperand, OpTrait::OneResult> {
|
||||
: public Op<ShapeCastOp, OpTrait::OneOperand, OpTrait::OneResult> {
|
||||
public:
|
||||
static StringRef getOperationName() { return "shape_cast"; }
|
||||
|
||||
@ -493,7 +492,7 @@ public:
|
||||
|
||||
private:
|
||||
friend class Operation;
|
||||
explicit ShapeCastOp(const Operation *state) : OpBase(state) {}
|
||||
explicit ShapeCastOp(const Operation *state) : Op(state) {}
|
||||
};
|
||||
|
||||
/// The "store" op writes an element to a memref specified by an index list.
|
||||
@ -507,7 +506,7 @@ private:
|
||||
/// store %v, %A[%i, %j] : memref<4x128xf32, (d0, d1) -> (d0, d1), 0>
|
||||
///
|
||||
class StoreOp
|
||||
: public OpBase<StoreOp, OpTrait::VariadicOperands, OpTrait::ZeroResult> {
|
||||
: public Op<StoreOp, OpTrait::VariadicOperands, OpTrait::ZeroResult> {
|
||||
public:
|
||||
SSAValue *getValueToStore() { return getOperand(0); }
|
||||
const SSAValue *getValueToStore() const { return getOperand(0); }
|
||||
@ -535,7 +534,7 @@ public:
|
||||
|
||||
private:
|
||||
friend class Operation;
|
||||
explicit StoreOp(const Operation *state) : OpBase(state) {}
|
||||
explicit StoreOp(const Operation *state) : Op(state) {}
|
||||
};
|
||||
|
||||
/// Install the standard operations in the specified operation set.
|
||||
|
@ -193,32 +193,32 @@ bool Operation::constantFold(ArrayRef<Attribute *> operands,
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// OpBaseState trait class.
|
||||
// OpState trait class.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/// Emit an error about fatal conditions with this operation, reporting up to
|
||||
/// any diagnostic handlers that may be listening. NOTE: This may terminate
|
||||
/// the containing application, only use when the IR is in an inconsistent
|
||||
/// state.
|
||||
void OpBaseState::emitError(const Twine &message) const {
|
||||
void OpState::emitError(const Twine &message) const {
|
||||
getOperation()->emitError(message);
|
||||
}
|
||||
|
||||
/// Emit an error with the op name prefixed, like "'dim' op " which is
|
||||
/// convenient for verifiers.
|
||||
bool OpBaseState::emitOpError(const Twine &message) const {
|
||||
bool OpState::emitOpError(const Twine &message) const {
|
||||
return getOperation()->emitOpError(message);
|
||||
}
|
||||
|
||||
/// Emit a warning about this operation, reporting up to any diagnostic
|
||||
/// handlers that may be listening.
|
||||
void OpBaseState::emitWarning(const Twine &message) const {
|
||||
void OpState::emitWarning(const Twine &message) const {
|
||||
getOperation()->emitWarning(message);
|
||||
}
|
||||
|
||||
/// Emit a note about this operation, reporting up to any diagnostic
|
||||
/// handlers that may be listening.
|
||||
void OpBaseState::emitNote(const Twine &message) const {
|
||||
void OpState::emitNote(const Twine &message) const {
|
||||
getOperation()->emitNote(message);
|
||||
}
|
||||
|
||||
|
@ -42,12 +42,12 @@ void mlir::initializeAllRegisteredOps(MLIRContext *context) {
|
||||
OpAsmParser::~OpAsmParser() {}
|
||||
|
||||
// The fallback for the printer is to reject the short form.
|
||||
bool OpBaseState::parse(OpAsmParser *parser, OperationState *result) {
|
||||
bool OpState::parse(OpAsmParser *parser, OperationState *result) {
|
||||
return parser->emitError(parser->getNameLoc(), "has no concise form");
|
||||
}
|
||||
|
||||
// The fallback for the printer is to print it the longhand form.
|
||||
void OpBaseState::print(OpAsmPrinter *p) const {
|
||||
void OpState::print(OpAsmPrinter *p) const {
|
||||
p->printDefaultOp(getOperation());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user