builtin_attribute.h 2.5 KB
Newer Older
Z
zhangbo9674 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

17 18 19
#include "paddle/ir/core/attribute.h"
#include "paddle/ir/core/builtin_attribute_storage.h"
#include "paddle/ir/core/utils.h"
Z
zhangbo9674 已提交
20 21

namespace ir {
22
class StrAttribute : public Attribute {
Z
zhangbo9674 已提交
23 24 25 26 27
 public:
  using Attribute::Attribute;

  DECLARE_ATTRIBUTE_UTILITY_FUNCTOR(StrAttribute, StrAttributeStorage);

28
  bool operator<(const StrAttribute& right) const {
Z
zhangbo9674 已提交
29 30 31 32 33 34 35 36
    return storage() < right.storage();
  }

  std::string data() const;

  uint32_t size() const;
};

37 38 39
class BoolAttribute : public Attribute {
 public:
  using Attribute::Attribute;
Z
zhangbo9674 已提交
40

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  DECLARE_ATTRIBUTE_UTILITY_FUNCTOR(BoolAttribute, BoolAttributeStorage);

  bool data() const;
};

class FloatAttribute : public Attribute {
 public:
  using Attribute::Attribute;

  DECLARE_ATTRIBUTE_UTILITY_FUNCTOR(FloatAttribute, FloatAttributeStorage);

  float data() const;
};

class DoubleAttribute : public Attribute {
 public:
  using Attribute::Attribute;

  DECLARE_ATTRIBUTE_UTILITY_FUNCTOR(DoubleAttribute, DoubleAttributeStorage);

  double data() const;
};

Z
zhangbo9674 已提交
64
class Int32Attribute : public Attribute {
65 66 67
 public:
  using Attribute::Attribute;

Z
zhangbo9674 已提交
68
  DECLARE_ATTRIBUTE_UTILITY_FUNCTOR(Int32Attribute, Int32AttributeStorage);
69 70 71 72

  int32_t data() const;
};

Z
zhangbo9674 已提交
73
class Int64Attribute : public Attribute {
74 75 76
 public:
  using Attribute::Attribute;

Z
zhangbo9674 已提交
77
  DECLARE_ATTRIBUTE_UTILITY_FUNCTOR(Int64Attribute, Int64AttributeStorage);
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94

  int64_t data() const;
};

class ArrayAttribute : public Attribute {
 public:
  using Attribute::Attribute;

  DECLARE_ATTRIBUTE_UTILITY_FUNCTOR(ArrayAttribute, ArrayAttributeStorage);

  std::vector<Attribute> data() const;

  size_t size() const { return data().size(); }

  bool empty() const { return data().empty(); }

  Attribute operator[](size_t index) const { return data()[index]; }
Z
zhangbo9674 已提交
95
};
96

97 98 99 100 101 102 103 104 105
class PointerAttribute : public Attribute {
 public:
  using Attribute::Attribute;

  DECLARE_ATTRIBUTE_UTILITY_FUNCTOR(PointerAttribute, PointerAttributeStorage);

  void* data() const;
};

106
}  // namespace ir