aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/compiler/xla/service/cpu/ir_emitter.h
diff options
context:
space:
mode:
authorGravatar Sanjoy Das <sanjoy@google.com>2018-05-01 18:46:31 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-05-01 18:49:56 -0700
commit69b2c639f55b065a5dbf829351034441bebc8437 (patch)
tree89869d4af178dba875557e4280ece30a642bf20b /tensorflow/compiler/xla/service/cpu/ir_emitter.h
parentc8ae9e86f33053484b05e405dadd2c8a98b8b41b (diff)
[XLA:CPU] Re-use the same llvm::GlobalVariable for identical literals
This isn't necessary today, but it will be after an optimization change I'm about to make. LLVM has a constant merging pass too, but one of the motivations here is to avoid the LLVM compile time overhead of having many large arrays in the IR. PiperOrigin-RevId: 195032900
Diffstat (limited to 'tensorflow/compiler/xla/service/cpu/ir_emitter.h')
-rw-r--r--tensorflow/compiler/xla/service/cpu/ir_emitter.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/tensorflow/compiler/xla/service/cpu/ir_emitter.h b/tensorflow/compiler/xla/service/cpu/ir_emitter.h
index 0f2f3d1817..5a04076080 100644
--- a/tensorflow/compiler/xla/service/cpu/ir_emitter.h
+++ b/tensorflow/compiler/xla/service/cpu/ir_emitter.h
@@ -530,6 +530,8 @@ class IrEmitter : public DfsHloVisitorWithDefault {
Status EmitXfeedTransfer(XfeedKind kind, const Shape& shape,
llvm::Value* program_buffer_address);
+ llvm::GlobalVariable* EmitGlobalForLiteral(const Literal& literal);
+
const HloModuleConfig& hlo_module_config_;
bool is_top_level_computation_;
@@ -539,6 +541,20 @@ class IrEmitter : public DfsHloVisitorWithDefault {
int64 external_global_constant_counter_ = 0;
ExternalConstantPool* external_constant_pool_;
+ struct LiteralPtrHashFunctor {
+ size_t operator()(const Literal* literal) const { return literal->Hash(); }
+ };
+
+ struct LiteralPtrEqualityFunctor {
+ bool operator()(const Literal* lhs, const Literal* rhs) const {
+ return *lhs == *rhs;
+ }
+ };
+
+ tensorflow::gtl::FlatMap<const Literal*, llvm::GlobalVariable*,
+ LiteralPtrHashFunctor, LiteralPtrEqualityFunctor>
+ emitted_literals_;
+
TF_DISALLOW_COPY_AND_ASSIGN(IrEmitter);
};