Changeset View
Standalone View
lib/IR/IntrinsicInst.cpp
Show All 15 Lines | |||||
// hack working. | // hack working. | ||||
// | // | ||||
// In some cases, arguments to intrinsics need to be generic and are defined as | // In some cases, arguments to intrinsics need to be generic and are defined as | ||||
// type pointer to empty struct { }*. To access the real item of interest the | // type pointer to empty struct { }*. To access the real item of interest the | ||||
// cast instruction needs to be stripped away. | // cast instruction needs to be stripped away. | ||||
// | // | ||||
//===----------------------------------------------------------------------===// | //===----------------------------------------------------------------------===// | ||||
#include "llvm/ADT/StringSwitch.h" | |||||
#include "llvm/IR/IntrinsicInst.h" | #include "llvm/IR/IntrinsicInst.h" | ||||
#include "llvm/IR/Constants.h" | #include "llvm/IR/Constants.h" | ||||
#include "llvm/IR/GlobalVariable.h" | #include "llvm/IR/GlobalVariable.h" | ||||
#include "llvm/IR/Metadata.h" | #include "llvm/IR/Metadata.h" | ||||
#include "llvm/IR/Module.h" | #include "llvm/IR/Module.h" | ||||
#include "llvm/Support/raw_ostream.h" | #include "llvm/Support/raw_ostream.h" | ||||
using namespace llvm; | using namespace llvm; | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
Value *InstrProfIncrementInst::getStep() const { | 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 | |||||
ConstrainedFPIntrinsic::getRoundingMode() const { | |||||
Metadata *RoundingMD = cast<MetadataAsValue>(getOperand(2))->getMetadata(); | |||||
StringRef RoundingArg = cast<MDString>(RoundingMD)->getString(); | |||||
// For dynamic rounding mode, we use round to nearest but we will set the | |||||
// 'exact' SDNodeFlag so that the value will not be rounded. | |||||
return StringSwitch<RoundingMode>(RoundingArg) | |||||
.Case("round.dynamic", rmDynamic) | |||||
.Case("round.tonearest", rmToNearest) | |||||
craig.topper: Don't use 'else' after an 'if' containing a 'return' per coding standards. | |||||
Not Done ReplyInline ActionsI can make that change. What I wanted to convey here is that this is effectively a switch statement with no uncovered cases. I suppose since there is no way to get the compiler to warn if that ever changes there is no particular benefit in doing it this way. andrew.w.kaylor: I can make that change. What I wanted to convey here is that this is effectively a switch… | |||||
.Case("round.downward", rmDownward) | |||||
Not Done ReplyInline ActionsYou could maybe use a StringSwitch. craig.topper: You could maybe use a StringSwitch. | |||||
Not Done ReplyInline ActionsThat would be perfect, but can I put an llvm_unreachable() in a StringSwitch? andrew.w.kaylor: That would be perfect, but can I put an llvm_unreachable() in a StringSwitch? | |||||
Not Done ReplyInline ActionsI think StringSwitch will assert if it doesn't find a match and there is no default specified. craig.topper: I think StringSwitch will assert if it doesn't find a match and there is no default specified. | |||||
Not Done ReplyInline ActionsYes, I saw that in the code. I wanted something that was informative in non-assert mode too. I guess the obvious solution to that is to add something like an UnreachableDefault() method to StringSwitch. andrew.w.kaylor: Yes, I saw that in the code. I wanted something that was informative in non-assert mode too. | |||||
Not Done ReplyInline Actions"Informative" as in "triggers a runtime failure"? Unreachable isn't the right solution, it is UB in release mode AFAIK. mehdi_amini: "Informative" as in "triggers a runtime failure"? Unreachable isn't the right solution, it is… | |||||
.Case("round.upward", rmUpward) | |||||
.Case("round.towardzero", rmTowardZero) | |||||
.UnreachableDefault("Unexpected rounding mode argument in FP intrinsic!"); | |||||
} | |||||
ConstrainedFPIntrinsic::ExceptionBehavior | |||||
ConstrainedFPIntrinsic::getExceptionBehavior() const { | |||||
Metadata *ExceptionMD = cast<MetadataAsValue>(getOperand(3))->getMetadata(); | |||||
StringRef ExceptionArg = cast<MDString>(ExceptionMD)->getString(); | |||||
return StringSwitch<ExceptionBehavior>(ExceptionArg) | |||||
.Case("fpexcept.ignore", ebIgnore) | |||||
.Case("fpexcept.maytrap", ebMayTrap) | |||||
.Case("fpexcept.strict", ebStrict) | |||||
.UnreachableDefault( | |||||
"Unexpected exception behavior argument in FP intrinsic!"); | |||||
} |
Don't use 'else' after an 'if' containing a 'return' per coding standards.