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) {