From f83512e3057ad7fb5aa7a321612ca45bddc31b23 Mon Sep 17 00:00:00 2001 From: Su Xing Date: Fri, 24 Mar 2023 15:43:46 +0800 Subject: [PATCH] Refine IR --- src/IR.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/IR.cpp b/src/IR.cpp index 0e5312a..99dd5cb 100644 --- a/src/IR.cpp +++ b/src/IR.cpp @@ -52,7 +52,7 @@ PointerType *PointerType::get(Type *baseType) { return iter->second.get(); auto type = new PointerType(baseType); assert(type); - auto result = pointerTypes.try_emplace(baseType, type); + auto result = pointerTypes.emplace(baseType, type); return result.first->second.get(); } @@ -84,16 +84,25 @@ void Value::replaceAllUsesWith(Value *value) { } ConstantValue *ConstantValue::getInt(int value, const std::string &name) { - static std::map intConstants; - + static std::map> intConstants; + auto iter = intConstants.find(value); + if (iter != intConstants.end()) + return iter->second.get(); auto inst = new ConstantValue(value); assert(inst); - return inst; + auto result = intConstants.emplace(value, inst); + return result.first->second.get(); } + ConstantValue *ConstantValue::getFloat(float value, const std::string &name) { + static std::map> floatConstants; + auto iter = floatConstants.find(value); + if (iter != floatConstants.end()) + return iter->second.get(); auto inst = new ConstantValue(value); assert(inst); - return inst; + auto result = floatConstants.emplace(value, inst); + return result.first->second.get(); } void User::setOperand(int index, Value *value) {