Changeset View
Changeset View
Standalone View
Standalone View
llvm/trunk/lib/IR/IntrinsicInst.cpp
Show First 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | Value *InstrProfIncrementInst::getStep() const { | ||||
if (InstrProfIncrementInstStep::classof(this)) { | if (InstrProfIncrementInstStep::classof(this)) { | ||||
return const_cast<Value *>(getArgOperand(4)); | return const_cast<Value *>(getArgOperand(4)); | ||||
} | } | ||||
const Module *M = getModule(); | const Module *M = getModule(); | ||||
LLVMContext &Context = M->getContext(); | LLVMContext &Context = M->getContext(); | ||||
return ConstantInt::get(Type::getInt64Ty(Context), 1); | return ConstantInt::get(Type::getInt64Ty(Context), 1); | ||||
} | } | ||||
ConstrainedFPIntrinsic::RoundingMode | Optional<ConstrainedFPIntrinsic::RoundingMode> | ||||
ConstrainedFPIntrinsic::getRoundingMode() const { | ConstrainedFPIntrinsic::getRoundingMode() const { | ||||
unsigned NumOperands = getNumArgOperands(); | unsigned NumOperands = getNumArgOperands(); | ||||
Metadata *MD = | Metadata *MD = | ||||
dyn_cast<MetadataAsValue>(getArgOperand(NumOperands - 2))->getMetadata(); | dyn_cast<MetadataAsValue>(getArgOperand(NumOperands - 2))->getMetadata(); | ||||
if (!MD || !isa<MDString>(MD)) | if (!MD || !isa<MDString>(MD)) | ||||
return rmInvalid; | return None; | ||||
StringRef RoundingArg = cast<MDString>(MD)->getString(); | return StrToRoundingMode(cast<MDString>(MD)->getString()); | ||||
} | |||||
Optional<ConstrainedFPIntrinsic::RoundingMode> | |||||
ConstrainedFPIntrinsic::StrToRoundingMode(StringRef RoundingArg) { | |||||
// For dynamic rounding mode, we use round to nearest but we will set the | // For dynamic rounding mode, we use round to nearest but we will set the | ||||
// 'exact' SDNodeFlag so that the value will not be rounded. | // 'exact' SDNodeFlag so that the value will not be rounded. | ||||
return StringSwitch<RoundingMode>(RoundingArg) | return StringSwitch<Optional<RoundingMode>>(RoundingArg) | ||||
.Case("round.dynamic", rmDynamic) | .Case("round.dynamic", rmDynamic) | ||||
.Case("round.tonearest", rmToNearest) | .Case("round.tonearest", rmToNearest) | ||||
.Case("round.downward", rmDownward) | .Case("round.downward", rmDownward) | ||||
.Case("round.upward", rmUpward) | .Case("round.upward", rmUpward) | ||||
.Case("round.towardzero", rmTowardZero) | .Case("round.towardzero", rmTowardZero) | ||||
.Default(rmInvalid); | .Default(None); | ||||
} | } | ||||
ConstrainedFPIntrinsic::ExceptionBehavior | Optional<StringRef> | ||||
ConstrainedFPIntrinsic::RoundingModeToStr(RoundingMode UseRounding) { | |||||
Optional<StringRef> RoundingStr = None; | |||||
switch (UseRounding) { | |||||
case ConstrainedFPIntrinsic::rmDynamic: | |||||
RoundingStr = "round.dynamic"; | |||||
break; | |||||
case ConstrainedFPIntrinsic::rmToNearest: | |||||
RoundingStr = "round.tonearest"; | |||||
break; | |||||
case ConstrainedFPIntrinsic::rmDownward: | |||||
RoundingStr = "round.downward"; | |||||
break; | |||||
case ConstrainedFPIntrinsic::rmUpward: | |||||
RoundingStr = "round.upward"; | |||||
break; | |||||
case ConstrainedFPIntrinsic::rmTowardZero: | |||||
RoundingStr = "round.tozero"; | |||||
break; | |||||
} | |||||
return RoundingStr; | |||||
} | |||||
Optional<ConstrainedFPIntrinsic::ExceptionBehavior> | |||||
ConstrainedFPIntrinsic::getExceptionBehavior() const { | ConstrainedFPIntrinsic::getExceptionBehavior() const { | ||||
unsigned NumOperands = getNumArgOperands(); | unsigned NumOperands = getNumArgOperands(); | ||||
Metadata *MD = | Metadata *MD = | ||||
dyn_cast<MetadataAsValue>(getArgOperand(NumOperands - 1))->getMetadata(); | dyn_cast<MetadataAsValue>(getArgOperand(NumOperands - 1))->getMetadata(); | ||||
if (!MD || !isa<MDString>(MD)) | if (!MD || !isa<MDString>(MD)) | ||||
return ebInvalid; | return None; | ||||
StringRef ExceptionArg = cast<MDString>(MD)->getString(); | return StrToExceptionBehavior(cast<MDString>(MD)->getString()); | ||||
return StringSwitch<ExceptionBehavior>(ExceptionArg) | } | ||||
Optional<ConstrainedFPIntrinsic::ExceptionBehavior> | |||||
ConstrainedFPIntrinsic::StrToExceptionBehavior(StringRef ExceptionArg) { | |||||
return StringSwitch<Optional<ExceptionBehavior>>(ExceptionArg) | |||||
.Case("fpexcept.ignore", ebIgnore) | .Case("fpexcept.ignore", ebIgnore) | ||||
.Case("fpexcept.maytrap", ebMayTrap) | .Case("fpexcept.maytrap", ebMayTrap) | ||||
.Case("fpexcept.strict", ebStrict) | .Case("fpexcept.strict", ebStrict) | ||||
.Default(ebInvalid); | .Default(None); | ||||
} | |||||
Optional<StringRef> | |||||
ConstrainedFPIntrinsic::ExceptionBehaviorToStr(ExceptionBehavior UseExcept) { | |||||
Optional<StringRef> ExceptStr = None; | |||||
switch (UseExcept) { | |||||
case ConstrainedFPIntrinsic::ebStrict: | |||||
ExceptStr = "fpexcept.strict"; | |||||
break; | |||||
case ConstrainedFPIntrinsic::ebIgnore: | |||||
ExceptStr = "fpexcept.ignore"; | |||||
break; | |||||
case ConstrainedFPIntrinsic::ebMayTrap: | |||||
ExceptStr = "fpexcept.maytrap"; | |||||
break; | |||||
} | |||||
return ExceptStr; | |||||
} | } | ||||
bool ConstrainedFPIntrinsic::isUnaryOp() const { | bool ConstrainedFPIntrinsic::isUnaryOp() const { | ||||
switch (getIntrinsicID()) { | switch (getIntrinsicID()) { | ||||
default: | default: | ||||
return false; | return false; | ||||
case Intrinsic::experimental_constrained_fptrunc: | case Intrinsic::experimental_constrained_fptrunc: | ||||
case Intrinsic::experimental_constrained_fpext: | case Intrinsic::experimental_constrained_fpext: | ||||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |