28#ifndef ENZYME_TYPE_ANALYSIS_CONCRETE_TYPE_H
29#define ENZYME_TYPE_ANALYSIS_CONCRETE_TYPE_H 1
33#include "llvm/IR/InstrTypes.h"
34#include "llvm/IR/Type.h"
35#include "llvm/Support/ErrorHandling.h"
52 assert(!llvm::isa<llvm::VectorType>(
SubType));
53 if (!
SubType->isFloatingPointTy()) {
54 llvm::errs() <<
" passing in non FP SubType: " << *
SubType <<
"\n";
56 assert(
SubType->isFloatingPointTy());
69 auto Sep = Str.find(
'@');
70 if (Sep != llvm::StringRef::npos) {
72 assert(Str.substr(0, Sep) ==
"Float");
73 auto SubName = Str.substr(Sep + 1);
74 if (SubName ==
"half") {
75 SubType = llvm::Type::getHalfTy(C);
76 }
else if (SubName ==
"float") {
77 SubType = llvm::Type::getFloatTy(C);
78 }
else if (SubName ==
"double") {
79 SubType = llvm::Type::getDoubleTy(C);
80 }
else if (SubName ==
"fp80") {
81 SubType = llvm::Type::getX86_FP80Ty(C);
82 }
else if (SubName ==
"bf16") {
83 SubType = llvm::Type::getBFloatTy(C);
84 }
else if (SubName ==
"fp128") {
85 SubType = llvm::Type::getFP128Ty(C);
86 }
else if (SubName ==
"ppc128") {
87 SubType = llvm::Type::getPPC_FP128Ty(C);
89 llvm_unreachable(
"unknown data SubType");
98 std::string
str()
const {
103 }
else if (
SubType->isFloatTy()) {
105 }
else if (
SubType->isDoubleTy()) {
107 }
else if (
SubType->isX86_FP80Ty()) {
109 }
else if (
SubType->isBFloatTy()) {
111 }
else if (
SubType->isFP128Ty()) {
113 }
else if (
SubType->isPPC_FP128Ty()) {
116 llvm_unreachable(
"unknown data SubType");
152 "Cannot do comparision between ConcreteType and BaseType::Float");
154 "Cannot do comparision between ConcreteType and BaseType::Float");
164 "Cannot do comparision between ConcreteType and BaseType::Float");
166 "Cannot do comparision between ConcreteType and BaseType::Float");
182 bool changed =
false;
216 if (PointerIntSame) {
241 bool Result =
checkedOrIn(CT, PointerIntSame, Legal);
243 llvm::errs() <<
"Illegal orIn: " <<
str() <<
" right: " << CT.
str()
244 <<
" PointerIntSame=" << PointerIntSame <<
"\n";
245 assert(0 &&
"Performed illegal ConcreteType::orIn");
246 llvm_unreachable(
"Performed illegal ConcreteType::orIn");
255 return orIn(CT,
false);
300 llvm::BinaryOperator::BinaryOps Op) {
301 bool Changed =
false;
302 using namespace llvm;
351 case BinaryOperator::Add:
352 case BinaryOperator::Sub:
353 case BinaryOperator::Mul:
354 case BinaryOperator::And:
355 case BinaryOperator::Or:
356 case BinaryOperator::Xor:
364 case BinaryOperator::UDiv:
365 case BinaryOperator::SDiv:
366 case BinaryOperator::URem:
367 case BinaryOperator::SRem:
368 case BinaryOperator::Shl:
369 case BinaryOperator::AShr:
370 case BinaryOperator::LShr:
397 case BinaryOperator::Sub:
401 case BinaryOperator::Add:
402 case BinaryOperator::Mul:
403 case BinaryOperator::UDiv:
404 case BinaryOperator::SDiv:
405 case BinaryOperator::URem:
406 case BinaryOperator::SRem:
407 case BinaryOperator::And:
408 case BinaryOperator::Or:
409 case BinaryOperator::Xor:
410 case BinaryOperator::Shl:
411 case BinaryOperator::AShr:
412 case BinaryOperator::LShr:
447 case BinaryOperator::Sub:
464 case BinaryOperator::Add:
465 case BinaryOperator::Mul:
471 case BinaryOperator::UDiv:
472 case BinaryOperator::SDiv:
473 case BinaryOperator::URem:
474 case BinaryOperator::SRem:
483 case BinaryOperator::And:
484 case BinaryOperator::Or:
485 case BinaryOperator::Xor:
486 case BinaryOperator::Shl:
487 case BinaryOperator::AShr:
488 case BinaryOperator::LShr:
static BaseType parseBaseType(llvm::StringRef str)
Convert string to BaseType.
BaseType
Categories of potential types.
static std::string to_string(const ConcreteType dt)
Concrete SubType of a given value.
bool operator|=(const ConcreteType CT)
Set this to the logical or of itself and CT, returning whether this value changed This assumes that p...
bool isIntegral() const
Whether this ConcreteType must an integer.
bool operator==(const BaseType BT) const
Return if this is known to be the BaseType BT This cannot be called with BaseType::Float as it lacks ...
bool isPossiblePointer() const
Whether this ConcreteType could be a pointer (SubTypeEnum is unknown or a pointer)
bool binopIn(bool &Legal, const ConcreteType RHS, llvm::BinaryOperator::BinaryOps Op)
Set this to the logical binop of itself and RHS, using the Binop Op, returning true if this was chang...
ConcreteType(BaseType SubTypeEnum)
Construct a non-floating Concrete type from a BaseType.
bool operator=(const ConcreteType CT)
Set this to the given ConcreteType, returning true if this ConcreteType has changed.
bool isKnown() const
Whether this ConcreteType has information (is not unknown)
llvm::Type * SubType
Floating point type, if relevant, otherwise nullptr.
bool isPossibleFloat() const
Whether this ConcreteType could be a float (SubTypeEnum is unknown or a float)
bool operator==(const ConcreteType CT) const
Return if this is known to be the ConcreteType CT.
bool operator&=(const ConcreteType CT)
Set this to the logical and of itself and CT, returning whether this value changed If this and CT are...
ConcreteType(llvm::Type *SubType)
Construct a ConcreteType from an existing FloatingPoint Type.
bool operator!=(const ConcreteType CT) const
Return if this is known not to be the ConcreteType CT.
std::string str() const
Convert the ConcreteType to a string.
ConcreteType PurgeAnything() const
Keep only mappings where the type is not an Anything
bool operator!=(const BaseType BT) const
Return if this is known not to be the BaseType BT This cannot be called with BaseType::Float as it la...
BaseType SubTypeEnum
Category of underlying type.
bool checkedOrIn(const ConcreteType CT, bool PointerIntSame, bool &LegalOr)
Set this to the logical or of itself and CT, returning whether this value changed Setting PointerIntS...
ConcreteType(llvm::StringRef Str, llvm::LLVMContext &C)
Construct a ConcreteType from a string A Concrete Type's string representation is given by the string...
bool andIn(const ConcreteType CT)
Set this to the logical and of itself and CT, returning whether this value changed If this and CT are...
bool operator<(const ConcreteType dt) const
Compare concrete types for use in map's.
bool orIn(const ConcreteType CT, bool PointerIntSame)
Set this to the logical or of itself and CT, returning whether this value changed Setting PointerIntS...
llvm::Type * isFloat() const
Return the floating point type, if this is a float.
bool operator=(const BaseType BT)
Set this to the given BaseType, returning true if this ConcreteType has changed.