From 84e7fe576ca8dd03f463fa6d75ff13357675dd9a Mon Sep 17 00:00:00 2001 From: William Moses Date: Tue, 19 Jul 2022 13:08:03 -0400 Subject: [PATCH] Simplify store type handling (#742) --- enzyme/Enzyme/AdjointGenerator.h | 38 +++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/enzyme/Enzyme/AdjointGenerator.h b/enzyme/Enzyme/AdjointGenerator.h index 550f171b8e8bd..7974df31a0741 100644 --- a/enzyme/Enzyme/AdjointGenerator.h +++ b/enzyme/Enzyme/AdjointGenerator.h @@ -940,25 +940,27 @@ class AdjointGenerator if (valType->isFPOrFPVectorTy()) { FT = valType->getScalarType(); } else if (!valType->isPointerTy()) { - if (looseTypeAnalysis) { - auto fp = TR.firstPointer(storeSize, orig_ptr, /*errifnotfound*/ false, - /*pointerIntSame*/ true); - if (fp.isKnown()) { - FT = fp.isFloat(); - } else if (isa(orig_val) || - valType->isIntOrIntVectorTy()) { - llvm::errs() << "assuming type as integral for store: " << I << "\n"; - FT = nullptr; - } else { - TR.firstPointer(storeSize, orig_ptr, /*errifnotfound*/ true, - /*pointerIntSame*/ true); - llvm::errs() << "cannot deduce type of store " << I << "\n"; - assert(0 && "cannot deduce"); - } + auto fp = TR.firstPointer(storeSize, orig_ptr, /*errifnotfound*/ false, + /*pointerIntSame*/ true); + if (fp.isKnown()) { + FT = fp.isFloat(); + } else if (looseTypeAnalysis && (isa(orig_val) || + valType->isIntOrIntVectorTy())) { + llvm::errs() << "assuming type as integral for store: " << I << "\n"; + FT = nullptr; } else { - FT = TR.firstPointer(storeSize, orig_ptr, /*errifnotfound*/ true, - /*pointerIntSame*/ true) - .isFloat(); + + if (CustomErrorHandler) { + std::string str; + raw_string_ostream ss(str); + ss << "Cannot deduce type of store " << I; + CustomErrorHandler(str.c_str(), wrap(&I), ErrorType::NoType, + &TR.analyzer); + } + EmitFailure("CannotDeduceType", I.getDebugLoc(), &I, + "failed to deduce type of store ", I); + TR.firstPointer(storeSize, orig_ptr, /*errifnotfound*/ true, + /*pointerIntSame*/ true); } }