80 std::vector<BinaryOperator *> LogicOpsWorklist;
82 std::set<Instruction *> PossibleJunk;
97 ConvertedInsts[
I] = std::make_tuple(V, Mask, Worthy);
99 auto &Ctx =
M.getContext();
100 for (
auto *U : I->
users()) {
103 (LI->getOpcode() == Instruction::And ||
104 LI->getOpcode() == Instruction::Or ||
105 LI->getOpcode() == Instruction::Xor)) {
106 LogicOpsWorklist.push_back(LI);
116 "SystemZ Test Data Class optimization",
false,
false)
119 return new SystemZTDCPass();
122 void SystemZTDCPass::convertFCmp(
CmpInst &I) {
132 APFloat NegSmallest = Smallest;
136 if (Const->isZero()) {
139 }
else if (Const->isInfinity()) {
141 WhichConst = Const->isNegative() ? 2 : 1;
142 }
else if (Const->isExactlyValue(Smallest)) {
148 }
else if (Const->isExactlyValue(NegSmallest)) {
159 static const int Masks[][4] = {
206 Mask |= Masks[WhichConst][0];
208 Mask |= Masks[WhichConst][1];
210 Mask |= Masks[WhichConst][2];
212 Mask |= Masks[WhichConst][3];
216 if (
CallInst *CI = dyn_cast<CallInst>(Op0)) {
222 Op0 = CI->getArgOperand(0);
225 Worthy = WhichConst != 0;
226 PossibleJunk.insert(CI);
229 converted(&I, Op0, Mask, Worthy);
232 void SystemZTDCPass::convertICmp(
CmpInst &I) {
239 if (
auto *Cast = dyn_cast<BitCastInst>(Op0)) {
241 if (!Cast->getSrcTy()->isFloatTy() &&
242 !Cast->getSrcTy()->isDoubleTy() &&
243 !Cast->getSrcTy()->isFP128Ty())
245 Value *V = Cast->getOperand(0);
257 PossibleJunk.insert(Cast);
258 converted(&I, V, Mask,
true);
259 }
else if (
auto *CI = dyn_cast<CallInst>(Op0)) {
264 if (!Const->isZero())
266 Value *V = CI->getArgOperand(0);
282 PossibleJunk.insert(CI);
283 converted(&I, V, Mask,
false);
290 bool Worthy0, Worthy1;
291 std::tie(Op0, Mask0, Worthy0) = ConvertedInsts[cast<Instruction>(I.
getOperand(0))];
292 std::tie(Op1, Mask1, Worthy1) = ConvertedInsts[cast<Instruction>(I.
getOperand(1))];
297 case Instruction::And:
298 Mask = Mask0 & Mask1;
300 case Instruction::Or:
301 Mask = Mask0 | Mask1;
303 case Instruction::Xor:
304 Mask = Mask0 ^ Mask1;
309 converted(&I, Op0, Mask,
true);
313 ConvertedInsts.
clear();
314 LogicOpsWorklist.clear();
315 PossibleJunk.clear();
320 convertFCmp(cast<CmpInst>(I));
321 else if (I.
getOpcode() == Instruction::ICmp)
322 convertICmp(cast<CmpInst>(I));
326 if (ConvertedInsts.
empty())
330 while (!LogicOpsWorklist.empty()) {
332 LogicOpsWorklist.pop_back();
337 !ConvertedInsts.
count(Op))
347 bool MadeChange =
false;
348 for (
auto &It :
reverse(ConvertedInsts)) {
353 std::tie(V, Mask, Worthy) = It.second;
377 for (
auto *I : PossibleJunk)
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
This class is the base class for the comparison instructions.
static IntegerType * getInt1Ty(LLVMContext &C)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
This class represents lattice values for constants.
BinaryOps getOpcode() const
const unsigned TDCMASK_ZERO
A Module instance is used to store all the information related to an LLVM module. ...
void initializeSystemZTDCPassPass(PassRegistry &)
const unsigned TDCMASK_NEGATIVE
This class represents a function call, abstracting a target machine's calling convention.
0 1 0 0 True if ordered and less than
This class implements a map that also provides access to all stored values in a deterministic order...
static IntegerType * getInt64Ty(LLVMContext &C)
const unsigned TDCMASK_POSITIVE
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
FunctionPass * createSystemZTDCPass()
LLVMContext & getContext() const
Get the global data context.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
0 1 0 1 True if ordered and less than or equal
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
Type * getType() const
All values are typed, get the type of this value.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Value * getOperand(unsigned i) const
static bool runOnFunction(Function &F, bool PostInlining)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
const unsigned TDCMASK_NORMAL_PLUS
This file contains the declarations for the subclasses of Constant, which represent the different fla...
const unsigned TDCMASK_SUBNORMAL_MINUS
ConstantFP - Floating Point Values [float, double].
FunctionPass class - This class is used to implement most global optimizations.
const Function * getFunction() const
Return the function this instruction belongs to.
const unsigned TDCMASK_NAN
const unsigned TDCMASK_INFINITY_PLUS
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
0 0 1 0 True if ordered and greater than
This is the shared class of boolean and integer constants.
const unsigned TDCMASK_ALL
Module.h This file contains the declarations for the Module class.
size_type count(const KeyT &Key) const
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
iterator_range< user_iterator > users()
Predicate getPredicate() const
Return the predicate for this instruction.
INITIALIZE_PASS(SystemZTDCPass, "systemz-tdc", "SystemZ Test Data Class optimization", false, false) FunctionPass *llvm
static IntegerType * getInt32Ty(LLVMContext &C)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static APFloat getSmallestNormalized(const fltSemantics &Sem, bool Negative=false)
Returns the smallest (by magnitude) normalized finite number in the given semantics.
0 0 0 1 True if ordered and equal
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
const unsigned TDCMASK_INFINITY_MINUS
const unsigned TDCMASK_NORMAL_MINUS
inst_range instructions(Function *F)
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
0 0 1 1 True if ordered and greater than or equal
const unsigned TDCMASK_PLUS
const unsigned TDCMASK_MINUS
const unsigned TDCMASK_SUBNORMAL_PLUS
const fltSemantics & getFltSemantics() const