From: 박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 Date: Mon, 1 Oct 2018 07:19:53 +0000 (+0900) Subject: [enco] Introduce Dead Object Elimination (#1691) X-Git-Tag: nncc_backup~1665 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=29c8370661a7dba309efca6b5e179e6bee8d54d5;p=platform%2Fcore%2Fml%2Fnnfw.git [enco] Introduce Dead Object Elimination (#1691) * [enco] Introduce Dead Object Elimination This commit introduces Dead Object Elimination (DOE) pass in enco compilation pipeline. DOE is a special case of Dead Bag Elimination (DBE), but inserted in order to reduce compilation overhead. Signed-off-by: Jonghyun Park * Fix a typo (updater -> producer) --- diff --git a/contrib/enco/core/src/Backend.cpp b/contrib/enco/core/src/Backend.cpp index 81a6ff0..2dbb66f 100644 --- a/contrib/enco/core/src/Backend.cpp +++ b/contrib/enco/core/src/Backend.cpp @@ -23,6 +23,7 @@ #include "Transforms/FeatureUnification.h" #include "Transforms/Rewrite.h" #include "Transforms/Normalize.h" +#include "Transforms/DeadObjectElimination.h" #include "Transforms/Optimizations.h" #include "Transforms/Split.h" @@ -100,6 +101,12 @@ void BackendImpl::compile(coco::Module *m, coco::Data *d) NormalizePass normalize; normalize.runOnCode(&code); + // Eliminate dead object + // + // NOTE Dead Object Elimination (DOE) is performed before Copy lowering + // in order to reduce compilation overhead. + eliminate_dead_object(&code); + // Lower Copy as Shuffle lower_copy(&code); diff --git a/contrib/enco/core/src/Transforms/DeadObjectElimination.cpp b/contrib/enco/core/src/Transforms/DeadObjectElimination.cpp new file mode 100644 index 0000000..1f5970e --- /dev/null +++ b/contrib/enco/core/src/Transforms/DeadObjectElimination.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. 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 "DeadObjectElimination.h" + +#include + +namespace +{ + +std::set dead_objects(const coco::Module *m) +{ + std::set res; + + for (uint32_t n = 0; n < m->entity()->object()->size(); ++n) + { + auto obj = m->entity()->object()->at(n); + auto bag = obj->bag(); + + if (coco::readers(bag).empty() && !(bag->isOutput())) + { + res.insert(obj); + } + } + + return res; +} + +} // namespace + +namespace enco +{ + +void eliminate_dead_object(enco::Code *code) +{ + auto m = code->module(); + + // Destroy a dead object and its producer + for (auto obj : dead_objects(m)) + { + if (auto producer = coco::producer(obj)) + { + auto ins = producer->loc(); + assert(ins != nullptr); + + ins->detach(); + m->entity()->instr()->destroy(ins); + } + + m->entity()->object()->destroy(obj); + } +} + +} // namespace enco diff --git a/contrib/enco/core/src/Transforms/DeadObjectElimination.h b/contrib/enco/core/src/Transforms/DeadObjectElimination.h new file mode 100644 index 0000000..8cefe92 --- /dev/null +++ b/contrib/enco/core/src/Transforms/DeadObjectElimination.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. 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. + */ + +#ifndef __ENCO_TRANSFORM_DEAD_OBJECT_ELIMINATION_H__ +#define __ENCO_TRANSFORM_DEAD_OBJECT_ELIMINATION_H__ + +#include "Code.h" + +namespace enco +{ + +/** + * @brief Eliminate dead objects in IR + * + * An object whose backing bag is unused is referred to as a dead object. + * + * Dead Object Elimination (DOE) eliminates such dead objects along with their producer. + */ +void eliminate_dead_object(enco::Code *code); + +} // namespace enco + +#endif // __ENCO_TRANSFORM_DEAD_OBJECT_ELIMINATION_H__