-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aefa62e
commit bd4afac
Showing
19 changed files
with
334 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// 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. | ||
#include "paddle/pir/core/block_argument.h" | ||
#include "paddle/pir/core/enforce.h" | ||
#include "paddle/pir/core/value_impl.h" | ||
|
||
#define CHECK_NULL_IMPL(func_name) \ | ||
IR_ENFORCE(impl_, "impl_ is null when called BlockArgument:" #func_name) | ||
|
||
#define IMPL_ static_cast<detail::BlockArgumentImpl *>(impl_) | ||
|
||
namespace pir { | ||
|
||
namespace detail { | ||
/// | ||
/// \brief BlockArgumentImpl is the implementation of an block argument. | ||
/// | ||
class BlockArgumentImpl : public ValueImpl { | ||
public: | ||
static bool classof(const ValueImpl &value) { | ||
return value.kind() == BLOCK_ARGUMENT_INDEX; | ||
} | ||
|
||
private: | ||
BlockArgumentImpl(Type type, Block *owner, uint32_t index) | ||
: ValueImpl(type, BLOCK_ARGUMENT_INDEX), owner_(owner), index_(index) {} | ||
|
||
~BlockArgumentImpl(); | ||
// access construction and owner | ||
friend BlockArgument; | ||
Block *owner_; | ||
uint32_t index_; | ||
}; | ||
|
||
BlockArgumentImpl::~BlockArgumentImpl() { | ||
if (!use_empty()) { | ||
LOG(FATAL) << "Destoryed a blockargument that is still in use."; | ||
} | ||
} | ||
|
||
} // namespace detail | ||
|
||
BlockArgument::BlockArgument(detail::BlockArgumentImpl *impl) : Value(impl) {} | ||
|
||
bool BlockArgument::classof(Value value) { | ||
return value && detail::BlockArgumentImpl::classof(*value.impl()); | ||
} | ||
|
||
Block *BlockArgument::owner() const { | ||
CHECK_NULL_IMPL(owner); | ||
return IMPL_->owner_; | ||
} | ||
|
||
uint32_t BlockArgument::arg_index() const { | ||
CHECK_NULL_IMPL(arg_index); | ||
return IMPL_->index_; | ||
} | ||
|
||
BlockArgument BlockArgument::Create(Type type, Block *owner, uint32_t index) { | ||
return new detail::BlockArgumentImpl(type, owner, index); | ||
} | ||
/// Destroy the argument. | ||
void BlockArgument::Destroy() { | ||
if (impl_) { | ||
LOG(WARNING) << "Destroying a null block argument."; | ||
} else { | ||
delete IMPL_; | ||
} | ||
} | ||
|
||
void BlockArgument::set_arg_index(uint32_t index) { | ||
CHECK_NULL_IMPL(set_arg_number); | ||
IMPL_->index_ = index; | ||
} | ||
|
||
BlockArgument BlockArgument::dyn_cast_from(Value value) { | ||
if (classof(value)) { | ||
return static_cast<detail::BlockArgumentImpl *>(value.impl()); | ||
} else { | ||
return nullptr; | ||
} | ||
} | ||
|
||
} // namespace pir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// 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 | ||
|
||
#include "paddle/pir/core/value.h" | ||
namespace pir { | ||
class Block; | ||
|
||
namespace detail { | ||
class BlockArgumentImpl; | ||
} // namespace detail | ||
|
||
/// | ||
/// \brief BlockArgument class represents the value defined by a result of | ||
/// operation. This class only provides interfaces, for specific implementation, | ||
/// see Impl class. | ||
/// | ||
class IR_API BlockArgument : public Value { | ||
public: | ||
BlockArgument() = default; | ||
Block *owner() const; | ||
uint32_t arg_index() const; | ||
|
||
private: | ||
/// constructor | ||
BlockArgument(detail::BlockArgumentImpl *impl); // NOLINT | ||
|
||
/// create a new argument with the given type and owner. | ||
static BlockArgument Create(Type type, Block *owner, uint32_t index); | ||
/// Destroy the argument. | ||
void Destroy(); | ||
/// set the position in the block argument list. | ||
void set_arg_index(uint32_t index); | ||
// Access create annd destroy. | ||
friend Block; | ||
|
||
// Access classof annd dyn_cast_from. | ||
friend Value; | ||
static bool classof(Value value); | ||
static BlockArgument dyn_cast_from(Value value); | ||
}; | ||
|
||
} // namespace pir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.