Removed unused dependencies in side effect analysis and converted some pointers to refs (NFC).
PiperOrigin-RevId: 334600822 Change-Id: I93ae888692433dc27ff73a4152ea16d261c1e461
This commit is contained in:
parent
3db7b6d07b
commit
1c9964097d
@ -812,7 +812,6 @@ cc_library(
|
|||||||
":tensorflow",
|
":tensorflow",
|
||||||
":tensorflow_types",
|
":tensorflow_types",
|
||||||
"//tensorflow/core:framework",
|
"//tensorflow/core:framework",
|
||||||
"@com_google_absl//absl/strings",
|
|
||||||
"@llvm-project//llvm:Support",
|
"@llvm-project//llvm:Support",
|
||||||
"@llvm-project//mlir:Analysis",
|
"@llvm-project//mlir:Analysis",
|
||||||
"@llvm-project//mlir:IR",
|
"@llvm-project//mlir:IR",
|
||||||
|
@ -18,21 +18,18 @@ limitations under the License.
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
|
||||||
#include "absl/strings/str_cat.h"
|
#include "llvm/ADT/ArrayRef.h"
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
#include "llvm/ADT/DenseSet.h"
|
|
||||||
#include "llvm/ADT/Optional.h"
|
#include "llvm/ADT/Optional.h"
|
||||||
#include "llvm/ADT/SCCIterator.h"
|
#include "llvm/ADT/SCCIterator.h"
|
||||||
#include "llvm/ADT/STLExtras.h"
|
#include "llvm/ADT/STLExtras.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include "llvm/ADT/iterator_range.h"
|
#include "llvm/ADT/iterator_range.h"
|
||||||
#include "llvm/Support/Casting.h"
|
#include "llvm/Support/Casting.h"
|
||||||
#include "llvm/Support/Debug.h"
|
|
||||||
#include "mlir/Analysis/CallGraph.h" // from @llvm-project
|
#include "mlir/Analysis/CallGraph.h" // from @llvm-project
|
||||||
#include "mlir/IR/Attributes.h" // from @llvm-project
|
#include "mlir/IR/Attributes.h" // from @llvm-project
|
||||||
#include "mlir/IR/Block.h" // from @llvm-project
|
#include "mlir/IR/Block.h" // from @llvm-project
|
||||||
#include "mlir/IR/Builders.h" // from @llvm-project
|
|
||||||
#include "mlir/IR/Location.h" // from @llvm-project
|
|
||||||
#include "mlir/IR/Module.h" // from @llvm-project
|
#include "mlir/IR/Module.h" // from @llvm-project
|
||||||
#include "mlir/IR/Operation.h" // from @llvm-project
|
#include "mlir/IR/Operation.h" // from @llvm-project
|
||||||
#include "mlir/IR/StandardTypes.h" // from @llvm-project
|
#include "mlir/IR/StandardTypes.h" // from @llvm-project
|
||||||
@ -248,22 +245,25 @@ bool IsResourceHandleAnonymous(VarHandleOp handle) {
|
|||||||
// Returns a string unique identifier for a non-anonymous VarHandleOp.
|
// Returns a string unique identifier for a non-anonymous VarHandleOp.
|
||||||
std::string GetVarHandleStringId(VarHandleOp handle) {
|
std::string GetVarHandleStringId(VarHandleOp handle) {
|
||||||
auto device = handle.getAttrOfType<StringAttr>("device");
|
auto device = handle.getAttrOfType<StringAttr>("device");
|
||||||
return absl::StrCat(handle.container().str(), "/", handle.shared_name().str(),
|
return llvm::join(
|
||||||
"/", device ? device.getValue().str() : std::string(""));
|
llvm::ArrayRef<llvm::StringRef>{
|
||||||
|
handle.container(), handle.shared_name(),
|
||||||
|
device ? device.getValue() : llvm::StringRef()},
|
||||||
|
"/");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finds a unique ID for a VarHandleOp's output. If it is anonymous, always
|
// Finds a unique ID for a VarHandleOp's output. If it is anonymous, always
|
||||||
// creates a new ID; otherwise, tries to reuse the existing ID for the
|
// creates a new ID; otherwise, tries to reuse the existing ID for the
|
||||||
// referenced variable if it exists, or creates a new one if not.
|
// referenced variable if it exists, or creates a new one if not.
|
||||||
int64_t GetOrCreateIdForVarHandle(VarHandleOp handle, int64_t* next_id,
|
int64_t GetOrCreateIdForVarHandle(VarHandleOp handle, int64_t& next_id,
|
||||||
llvm::StringMap<int64_t>* name_id_map) {
|
llvm::StringMap<int64_t>& name_id_map) {
|
||||||
// Always create a new ID for anonymous handle.
|
// Always create a new ID for anonymous handle.
|
||||||
if (IsResourceHandleAnonymous(handle)) return (*next_id)++;
|
if (IsResourceHandleAnonymous(handle)) return next_id++;
|
||||||
|
|
||||||
auto name = GetVarHandleStringId(handle);
|
auto name = GetVarHandleStringId(handle);
|
||||||
auto emplace_res = name_id_map->try_emplace(name, *next_id);
|
auto emplace_res = name_id_map.try_emplace(name, next_id);
|
||||||
// New ID created, increment next_id.
|
// New ID created, increment next_id.
|
||||||
if (emplace_res.second) ++(*next_id);
|
if (emplace_res.second) ++next_id;
|
||||||
return emplace_res.first->second;
|
return emplace_res.first->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,8 +343,8 @@ ResourceAliasAnalysisInfo::ResourceAliasAnalysisInfo(
|
|||||||
if (auto var_handle = dyn_cast<VarHandleOp>(op)) {
|
if (auto var_handle = dyn_cast<VarHandleOp>(op)) {
|
||||||
AddValueUniqueIDMapping(
|
AddValueUniqueIDMapping(
|
||||||
var_handle.resource(),
|
var_handle.resource(),
|
||||||
GetOrCreateIdForVarHandle(var_handle, &next_unique_id,
|
GetOrCreateIdForVarHandle(var_handle, next_unique_id,
|
||||||
&var_handle_name_id_map));
|
var_handle_name_id_map));
|
||||||
} else if (llvm::isa<IdentityNOp, IdentityOp>(op)) {
|
} else if (llvm::isa<IdentityNOp, IdentityOp>(op)) {
|
||||||
for (auto result : filter_resources(op->getResults()))
|
for (auto result : filter_resources(op->getResults()))
|
||||||
PropagateInputToOutput(op->getOperand(result.getResultNumber()),
|
PropagateInputToOutput(op->getOperand(result.getResultNumber()),
|
||||||
|
@ -18,7 +18,6 @@ limitations under the License.
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
|
||||||
#include "absl/strings/str_cat.h"
|
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
#include "llvm/ADT/DenseSet.h"
|
#include "llvm/ADT/DenseSet.h"
|
||||||
#include "llvm/ADT/Optional.h"
|
#include "llvm/ADT/Optional.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user