annotate lib/Transforms/Vectorize/VecUtils.cpp @ 20:a5b470e0d09d

set FastCC(Calling Convention) when the function is code segment and set GuaranteedTailCallOpt. but llvm still output not jmp but call...
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Sun, 06 Oct 2013 18:16:15 +0900
parents 9ad51c7bc036
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 //===- VecUtils.cpp --- Vectorization Utilities ---------------------------===//
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 //
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 //
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 //
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 #define DEBUG_TYPE "SLP"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 #include "VecUtils.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 #include "llvm/ADT/DenseMap.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 #include "llvm/ADT/SmallPtrSet.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 #include "llvm/ADT/SmallSet.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 #include "llvm/ADT/SmallVector.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 #include "llvm/Analysis/AliasAnalysis.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 #include "llvm/Analysis/ScalarEvolution.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 #include "llvm/Analysis/TargetTransformInfo.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 #include "llvm/Analysis/Verifier.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "llvm/Analysis/LoopInfo.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "llvm/IR/Constants.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 #include "llvm/IR/DataLayout.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #include "llvm/IR/Function.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #include "llvm/IR/Instructions.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 #include "llvm/IR/Module.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include "llvm/IR/Type.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #include "llvm/IR/Value.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 #include "llvm/Pass.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 #include "llvm/Support/CommandLine.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 #include "llvm/Support/Debug.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 #include "llvm/Support/raw_ostream.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 #include "llvm/Target/TargetLibraryInfo.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 #include "llvm/Transforms/Scalar.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 #include "llvm/Transforms/Utils/Local.h"
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 #include <algorithm>
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 #include <map>
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 using namespace llvm;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 static const unsigned MinVecRegSize = 128;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 static const unsigned RecursionMaxDepth = 6;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 namespace llvm {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 BoUpSLP::BoUpSLP(BasicBlock *Bb, ScalarEvolution *S, DataLayout *Dl,
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 TargetTransformInfo *Tti, AliasAnalysis *Aa, Loop *Lp) :
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 BB(Bb), SE(S), DL(Dl), TTI(Tti), AA(Aa), L(Lp) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 numberInstructions();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 void BoUpSLP::numberInstructions() {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 int Loc = 0;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 InstrIdx.clear();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 InstrVec.clear();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 // Number the instructions in the block.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 for (BasicBlock::iterator it=BB->begin(), e=BB->end(); it != e; ++it) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 InstrIdx[it] = Loc++;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 InstrVec.push_back(it);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 assert(InstrVec[InstrIdx[it]] == it && "Invalid allocation");
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 Value *BoUpSLP::getPointerOperand(Value *I) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 if (LoadInst *LI = dyn_cast<LoadInst>(I)) return LI->getPointerOperand();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 if (StoreInst *SI = dyn_cast<StoreInst>(I)) return SI->getPointerOperand();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 return 0;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 unsigned BoUpSLP::getAddressSpaceOperand(Value *I) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 if (LoadInst *L=dyn_cast<LoadInst>(I)) return L->getPointerAddressSpace();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
73 if (StoreInst *S=dyn_cast<StoreInst>(I)) return S->getPointerAddressSpace();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 return -1;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 bool BoUpSLP::isConsecutiveAccess(Value *A, Value *B) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 Value *PtrA = getPointerOperand(A);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 Value *PtrB = getPointerOperand(B);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
80 unsigned ASA = getAddressSpaceOperand(A);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 unsigned ASB = getAddressSpaceOperand(B);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 // Check that the address spaces match and that the pointers are valid.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 if (!PtrA || !PtrB || (ASA != ASB)) return false;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 // Check that A and B are of the same type.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 if (PtrA->getType() != PtrB->getType()) return false;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 // Calculate the distance.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 const SCEV *PtrSCEVA = SE->getSCEV(PtrA);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 const SCEV *PtrSCEVB = SE->getSCEV(PtrB);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 const SCEV *OffsetSCEV = SE->getMinusSCEV(PtrSCEVA, PtrSCEVB);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
93 const SCEVConstant *ConstOffSCEV = dyn_cast<SCEVConstant>(OffsetSCEV);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 // Non constant distance.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 if (!ConstOffSCEV) return false;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 int64_t Offset = ConstOffSCEV->getValue()->getSExtValue();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 Type *Ty = cast<PointerType>(PtrA->getType())->getElementType();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 // The Instructions are connsecutive if the size of the first load/store is
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101 // the same as the offset.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 int64_t Sz = DL->getTypeStoreSize(Ty);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 return ((-Offset) == Sz);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 bool BoUpSLP::vectorizeStoreChain(ArrayRef<Value *> Chain, int CostThreshold) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 Type *StoreTy = cast<StoreInst>(Chain[0])->getValueOperand()->getType();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
108 unsigned Sz = DL->getTypeSizeInBits(StoreTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 unsigned VF = MinVecRegSize / Sz;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 if (!isPowerOf2_32(Sz) || VF < 2) return false;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 bool Changed = false;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 // Look for profitable vectorizable trees at all offsets, starting at zero.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
115 for (unsigned i = 0, e = Chain.size(); i < e; ++i) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 if (i + VF > e) return Changed;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117 DEBUG(dbgs()<<"SLP: Analyzing " << VF << " stores at offset "<< i << "\n");
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 ArrayRef<Value *> Operands = Chain.slice(i, VF);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 int Cost = getTreeCost(Operands);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 DEBUG(dbgs() << "SLP: Found cost=" << Cost << " for VF=" << VF << "\n");
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 if (Cost < CostThreshold) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 DEBUG(dbgs() << "SLP: Decided to vectorize cost=" << Cost << "\n");
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 vectorizeTree(Operands, VF);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 i += VF - 1;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 Changed = true;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
129
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 return Changed;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
132
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133 bool BoUpSLP::vectorizeStores(ArrayRef<StoreInst *> Stores, int costThreshold) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 ValueSet Heads, Tails;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
135 SmallDenseMap<Value*, Value*> ConsecutiveChain;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
136
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 // We may run into multiple chains that merge into a single chain. We mark the
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 // stores that we vectorized so that we don't visit the same store twice.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 ValueSet VectorizedStores;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 bool Changed = false;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
141
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 // Do a quadratic search on all of the given stores and find
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 // all of the pairs of loads that follow each other.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 for (unsigned i = 0, e = Stores.size(); i < e; ++i)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 for (unsigned j = 0; j < e; ++j) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 if (i == j) continue;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 if (isConsecutiveAccess(Stores[i], Stores[j])) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 Tails.insert(Stores[j]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 Heads.insert(Stores[i]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 ConsecutiveChain[Stores[i]] = Stores[j];
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 // For stores that start but don't end a link in the chain:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 for (ValueSet::iterator it = Heads.begin(), e = Heads.end();it != e; ++it) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 if (Tails.count(*it)) continue;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 // We found a store instr that starts a chain. Now follow the chain and try
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 // to vectorize it.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 ValueList Operands;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 Value *I = *it;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 // Collect the chain into a list.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 while (Tails.count(I) || Heads.count(I)) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 if (VectorizedStores.count(I)) break;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 Operands.push_back(I);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 // Move to the next value in the chain.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 I = ConsecutiveChain[I];
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
169
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 bool Vectorized = vectorizeStoreChain(Operands, costThreshold);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
171
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 // Mark the vectorized stores so that we don't vectorize them again.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 if (Vectorized)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 VectorizedStores.insert(Operands.begin(), Operands.end());
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 Changed |= Vectorized;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
177
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 return Changed;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
180
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 int BoUpSLP::getScalarizationCost(ArrayRef<Value *> VL) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 // Find the type of the operands in VL.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 Type *ScalarTy = VL[0]->getType();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 if (StoreInst *SI = dyn_cast<StoreInst>(VL[0]))
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 ScalarTy = SI->getValueOperand()->getType();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 VectorType *VecTy = VectorType::get(ScalarTy, VL.size());
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 // Find the cost of inserting/extracting values from the vector.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
188 return getScalarizationCost(VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
190
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
191 int BoUpSLP::getScalarizationCost(Type *Ty) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
192 int Cost = 0;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 for (unsigned i = 0, e = cast<VectorType>(Ty)->getNumElements(); i < e; ++i)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 Cost += TTI->getVectorInstrCost(Instruction::InsertElement, Ty, i);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 return Cost;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
197
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 AliasAnalysis::Location BoUpSLP::getLocation(Instruction *I) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 if (StoreInst *SI = dyn_cast<StoreInst>(I)) return AA->getLocation(SI);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 if (LoadInst *LI = dyn_cast<LoadInst>(I)) return AA->getLocation(LI);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 return AliasAnalysis::Location();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
203
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
204 Value *BoUpSLP::isUnsafeToSink(Instruction *Src, Instruction *Dst) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 assert(Src->getParent() == Dst->getParent() && "Not the same BB");
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 BasicBlock::iterator I = Src, E = Dst;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 /// Scan all of the instruction from SRC to DST and check if
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
208 /// the source may alias.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 for (++I; I != E; ++I) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 // Ignore store instructions that are marked as 'ignore'.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
211 if (MemBarrierIgnoreList.count(I)) continue;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 if (Src->mayWriteToMemory()) /* Write */ {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 if (!I->mayReadOrWriteMemory()) continue;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
214 } else /* Read */ {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 if (!I->mayWriteToMemory()) continue;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
217 AliasAnalysis::Location A = getLocation(&*I);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 AliasAnalysis::Location B = getLocation(Src);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
219
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
220 if (!A.Ptr || !B.Ptr || AA->alias(A, B))
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 return I;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 return 0;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
225
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 void BoUpSLP::vectorizeArith(ArrayRef<Value *> Operands) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 Value *Vec = vectorizeTree(Operands, Operands.size());
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 BasicBlock::iterator Loc = cast<Instruction>(Vec);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 IRBuilder<> Builder(++Loc);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 // After vectorizing the operands we need to generate extractelement
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
231 // instructions and replace all of the uses of the scalar values with
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 // the values that we extracted from the vectorized tree.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
233 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 Value *S = Builder.CreateExtractElement(Vec, Builder.getInt32(i));
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
235 Operands[i]->replaceAllUsesWith(S);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
238
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 int BoUpSLP::getTreeCost(ArrayRef<Value *> VL) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 // Get rid of the list of stores that were removed, and from the
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 // lists of instructions with multiple users.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
242 MemBarrierIgnoreList.clear();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 LaneMap.clear();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 MultiUserVals.clear();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245 MustScalarize.clear();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 MustExtract.clear();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
247
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 // Find the location of the last root.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 unsigned LastRootIndex = InstrIdx[GetLastInstr(VL, VL.size())];
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
250
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251 // Scan the tree and find which value is used by which lane, and which values
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 // must be scalarized.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 getTreeUses_rec(VL, 0);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
254
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 // Check that instructions with multiple users can be vectorized. Mark unsafe
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 // instructions.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 for (ValueSet::iterator it = MultiUserVals.begin(),
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 e = MultiUserVals.end(); it != e; ++it) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 // Check that all of the users of this instr are within the tree
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 // and that they are all from the same lane.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 int Lane = -1;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 for (Value::use_iterator I = (*it)->use_begin(), E = (*it)->use_end();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 I != E; ++I) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 if (LaneMap.find(*I) == LaneMap.end()) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 DEBUG(dbgs()<<"SLP: Instr " << **it << " has multiple users.\n");
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 // We don't have an ordering problem if the user is not in this basic
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 // block.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 Instruction *Inst = cast<Instruction>(*I);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 if (Inst->getParent() == BB) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 // We don't have an ordering problem if the user is after the last
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 // root.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 unsigned Idx = InstrIdx[Inst];
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 if (Idx < LastRootIndex) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 MustScalarize.insert(*it);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 DEBUG(dbgs()<<"SLP: Adding to MustScalarize "
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 "because of an unsafe out of tree usage.\n");
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 break;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
281
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 DEBUG(dbgs()<<"SLP: Adding to MustExtract "
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 "because of a safe out of tree usage.\n");
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 MustExtract.insert(*it);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285 continue;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 if (Lane == -1) Lane = LaneMap[*I];
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 if (Lane != LaneMap[*I]) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 MustScalarize.insert(*it);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 DEBUG(dbgs()<<"SLP: Adding " << **it <<
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 " to MustScalarize because multiple lane use it: "
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 << Lane << " and " << LaneMap[*I] << ".\n");
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 break;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
297
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 // Now calculate the cost of vectorizing the tree.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 return getTreeCost_rec(VL, 0);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
301
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 void BoUpSLP::getTreeUses_rec(ArrayRef<Value *> VL, unsigned Depth) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 if (Depth == RecursionMaxDepth) return;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
304
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 // Don't handle vectors.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 if (VL[0]->getType()->isVectorTy()) return;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 if (StoreInst *SI = dyn_cast<StoreInst>(VL[0]))
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 if (SI->getValueOperand()->getType()->isVectorTy()) return;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
309
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 // Check if all of the operands are constants.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 bool AllConst = true;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 bool AllSameScalar = true;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 for (unsigned i = 0, e = VL.size(); i < e; ++i) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 AllConst &= isa<Constant>(VL[i]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 AllSameScalar &= (VL[0] == VL[i]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 Instruction *I = dyn_cast<Instruction>(VL[i]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
317 // If one of the instructions is out of this BB, we need to scalarize all.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 if (I && I->getParent() != BB) return;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 // If all of the operands are identical or constant we have a simple solution.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 if (AllConst || AllSameScalar) return;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 // Scalarize unknown structures.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 Instruction *VL0 = dyn_cast<Instruction>(VL[0]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 if (!VL0) return;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
327
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 unsigned Opcode = VL0->getOpcode();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 for (unsigned i = 0, e = VL.size(); i < e; ++i) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 Instruction *I = dyn_cast<Instruction>(VL[i]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 // If not all of the instructions are identical then we have to scalarize.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 if (!I || Opcode != I->getOpcode()) return;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 // Mark instructions with multiple users.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 for (unsigned i = 0, e = VL.size(); i < e; ++i) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 Instruction *I = dyn_cast<Instruction>(VL[i]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 // Remember to check if all of the users of this instr are vectorized
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 // within our tree.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 if (I && I->getNumUses() > 1) MultiUserVals.insert(I);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
342
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 for (int i = 0, e = VL.size(); i < e; ++i) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 // Check that the instruction is only used within
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 // one lane.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 if (LaneMap.count(VL[i]) && LaneMap[VL[i]] != i) return;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347 // Make this instruction as 'seen' and remember the lane.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 LaneMap[VL[i]] = i;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
350
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
351 switch (Opcode) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
352 case Instruction::ZExt:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 case Instruction::SExt:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
354 case Instruction::FPToUI:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 case Instruction::FPToSI:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 case Instruction::FPExt:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 case Instruction::PtrToInt:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 case Instruction::IntToPtr:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 case Instruction::SIToFP:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 case Instruction::UIToFP:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 case Instruction::Trunc:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 case Instruction::FPTrunc:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 case Instruction::BitCast:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
364 case Instruction::Add:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 case Instruction::FAdd:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 case Instruction::Sub:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 case Instruction::FSub:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 case Instruction::Mul:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 case Instruction::FMul:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
370 case Instruction::UDiv:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
371 case Instruction::SDiv:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
372 case Instruction::FDiv:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 case Instruction::URem:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
374 case Instruction::SRem:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 case Instruction::FRem:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 case Instruction::Shl:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 case Instruction::LShr:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 case Instruction::AShr:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 case Instruction::And:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 case Instruction::Or:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 case Instruction::Xor: {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 for (unsigned i = 0, e = VL0->getNumOperands(); i < e; ++i) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
383 ValueList Operands;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 // Prepare the operand vector.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 for (unsigned j = 0; j < VL.size(); ++j)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
386 Operands.push_back(cast<Instruction>(VL[j])->getOperand(i));
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
387
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 getTreeUses_rec(Operands, Depth+1);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 return;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 case Instruction::Store: {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 ValueList Operands;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 for (unsigned j = 0; j < VL.size(); ++j)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 Operands.push_back(cast<Instruction>(VL[j])->getOperand(0));
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 getTreeUses_rec(Operands, Depth+1);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 return;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 default:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 return;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
403
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 int BoUpSLP::getTreeCost_rec(ArrayRef<Value *> VL, unsigned Depth) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
405 Type *ScalarTy = VL[0]->getType();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
406
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
407 if (StoreInst *SI = dyn_cast<StoreInst>(VL[0]))
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 ScalarTy = SI->getValueOperand()->getType();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
409
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 /// Don't mess with vectors.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 if (ScalarTy->isVectorTy()) return max_cost;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 VectorType *VecTy = VectorType::get(ScalarTy, VL.size());
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
413
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 if (Depth == RecursionMaxDepth) return getScalarizationCost(VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
415
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
416 // Check if all of the operands are constants.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 bool AllConst = true;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 bool AllSameScalar = true;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
419 bool MustScalarizeFlag = false;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 for (unsigned i = 0, e = VL.size(); i < e; ++i) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 AllConst &= isa<Constant>(VL[i]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
422 AllSameScalar &= (VL[0] == VL[i]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 // Must have a single use.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 Instruction *I = dyn_cast<Instruction>(VL[i]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 MustScalarizeFlag |= MustScalarize.count(VL[i]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 // This instruction is outside the basic block.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 if (I && I->getParent() != BB)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
428 return getScalarizationCost(VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
430
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
431 // Is this a simple vector constant.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 if (AllConst) return 0;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
433
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 // If all of the operands are identical we can broadcast them.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 Instruction *VL0 = dyn_cast<Instruction>(VL[0]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
436 if (AllSameScalar) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 // If we are in a loop, and this is not an instruction (e.g. constant or
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 // argument) or the instruction is defined outside the loop then assume
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 // that the cost is zero.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
440 if (L && (!VL0 || !L->contains(VL0)))
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 return 0;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
442
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 // We need to broadcast the scalar.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 return TTI->getShuffleCost(TargetTransformInfo::SK_Broadcast, VecTy, 0);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
445 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
446
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 // If this is not a constant, or a scalar from outside the loop then we
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 // need to scalarize it.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
449 if (MustScalarizeFlag)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 return getScalarizationCost(VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
451
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
452 if (!VL0) return getScalarizationCost(VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 assert(VL0->getParent() == BB && "Wrong BB");
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
454
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 unsigned Opcode = VL0->getOpcode();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 for (unsigned i = 0, e = VL.size(); i < e; ++i) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 Instruction *I = dyn_cast<Instruction>(VL[i]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 // If not all of the instructions are identical then we have to scalarize.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 if (!I || Opcode != I->getOpcode()) return getScalarizationCost(VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
461
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
462 // Check if it is safe to sink the loads or the stores.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 if (Opcode == Instruction::Load || Opcode == Instruction::Store) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 int MaxIdx = InstrIdx[VL0];
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
465 for (unsigned i = 1, e = VL.size(); i < e; ++i )
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 MaxIdx = std::max(MaxIdx, InstrIdx[VL[i]]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
467
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
468 Instruction *Last = InstrVec[MaxIdx];
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
469 for (unsigned i = 0, e = VL.size(); i < e; ++i ) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 if (VL[i] == Last) continue;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 Value *Barrier = isUnsafeToSink(cast<Instruction>(VL[i]), Last);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 if (Barrier) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
473 DEBUG(dbgs() << "SLP: Can't sink " << *VL[i] << "\n down to " <<
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 *Last << "\n because of " << *Barrier << "\n");
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 return max_cost;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
476 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
479
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
480 // Calculate the extract cost.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 unsigned ExternalUserExtractCost = 0;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 for (unsigned i = 0, e = VL.size(); i < e; ++i)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 if (MustExtract.count(VL[i]))
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 ExternalUserExtractCost +=
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 TTI->getVectorInstrCost(Instruction::ExtractElement, VecTy, i);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
486
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 switch (Opcode) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 case Instruction::ZExt:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 case Instruction::SExt:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 case Instruction::FPToUI:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 case Instruction::FPToSI:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 case Instruction::FPExt:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 case Instruction::PtrToInt:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 case Instruction::IntToPtr:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 case Instruction::SIToFP:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 case Instruction::UIToFP:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 case Instruction::Trunc:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 case Instruction::FPTrunc:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 case Instruction::BitCast: {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 int Cost = ExternalUserExtractCost;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 ValueList Operands;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 Type *SrcTy = VL0->getOperand(0)->getType();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 // Prepare the operand vector.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
504 for (unsigned j = 0; j < VL.size(); ++j) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 Operands.push_back(cast<Instruction>(VL[j])->getOperand(0));
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 // Check that the casted type is the same for all users.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 if (cast<Instruction>(VL[j])->getOperand(0)->getType() != SrcTy)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 return getScalarizationCost(VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
509 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
510
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 Cost += getTreeCost_rec(Operands, Depth+1);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
512 if (Cost >= max_cost) return max_cost;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
513
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 // Calculate the cost of this instruction.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 int ScalarCost = VL.size() * TTI->getCastInstrCost(VL0->getOpcode(),
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 VL0->getType(), SrcTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
517
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 VectorType *SrcVecTy = VectorType::get(SrcTy, VL.size());
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 int VecCost = TTI->getCastInstrCost(VL0->getOpcode(), VecTy, SrcVecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 Cost += (VecCost - ScalarCost);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 return Cost;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
522 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 case Instruction::Add:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 case Instruction::FAdd:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 case Instruction::Sub:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 case Instruction::FSub:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 case Instruction::Mul:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 case Instruction::FMul:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 case Instruction::UDiv:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 case Instruction::SDiv:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
531 case Instruction::FDiv:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 case Instruction::URem:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 case Instruction::SRem:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 case Instruction::FRem:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 case Instruction::Shl:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 case Instruction::LShr:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
537 case Instruction::AShr:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 case Instruction::And:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 case Instruction::Or:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 case Instruction::Xor: {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 int Cost = ExternalUserExtractCost;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 // Calculate the cost of all of the operands.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 for (unsigned i = 0, e = VL0->getNumOperands(); i < e; ++i) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 ValueList Operands;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 // Prepare the operand vector.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 for (unsigned j = 0; j < VL.size(); ++j)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 Operands.push_back(cast<Instruction>(VL[j])->getOperand(i));
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
548
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 Cost += getTreeCost_rec(Operands, Depth+1);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 if (Cost >= max_cost) return max_cost;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
552
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 // Calculate the cost of this instruction.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 int ScalarCost = VecTy->getNumElements() *
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
555 TTI->getArithmeticInstrCost(Opcode, ScalarTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
556
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 int VecCost = TTI->getArithmeticInstrCost(Opcode, VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 Cost += (VecCost - ScalarCost);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
559 return Cost;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
561 case Instruction::Load: {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 // If we are scalarize the loads, add the cost of forming the vector.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 for (unsigned i = 0, e = VL.size()-1; i < e; ++i)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 if (!isConsecutiveAccess(VL[i], VL[i+1]))
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
565 return getScalarizationCost(VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
566
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
567 // Cost of wide load - cost of scalar loads.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
568 int ScalarLdCost = VecTy->getNumElements() *
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 TTI->getMemoryOpCost(Instruction::Load, ScalarTy, 1, 0);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 int VecLdCost = TTI->getMemoryOpCost(Instruction::Load, ScalarTy, 1, 0);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
571 return VecLdCost - ScalarLdCost + ExternalUserExtractCost;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
572 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 case Instruction::Store: {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 // We know that we can merge the stores. Calculate the cost.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
575 int ScalarStCost = VecTy->getNumElements() *
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 TTI->getMemoryOpCost(Instruction::Store, ScalarTy, 1, 0);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
577 int VecStCost = TTI->getMemoryOpCost(Instruction::Store, ScalarTy, 1,0);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
578 int StoreCost = VecStCost - ScalarStCost;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
579
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 ValueList Operands;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
581 for (unsigned j = 0; j < VL.size(); ++j) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
582 Operands.push_back(cast<Instruction>(VL[j])->getOperand(0));
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 MemBarrierIgnoreList.insert(VL[j]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
585
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 int TotalCost = StoreCost + getTreeCost_rec(Operands, Depth + 1);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 return TotalCost + ExternalUserExtractCost;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 default:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 // Unable to vectorize unknown instructions.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 return getScalarizationCost(VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
594
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 Instruction *BoUpSLP::GetLastInstr(ArrayRef<Value *> VL, unsigned VF) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 int MaxIdx = InstrIdx[BB->getFirstNonPHI()];
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 for (unsigned i = 0; i < VF; ++i )
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 MaxIdx = std::max(MaxIdx, InstrIdx[VL[i]]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 return InstrVec[MaxIdx + 1];
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
601
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
602 Value *BoUpSLP::Scalarize(ArrayRef<Value *> VL, VectorType *Ty) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 IRBuilder<> Builder(GetLastInstr(VL, Ty->getNumElements()));
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 Value *Vec = UndefValue::get(Ty);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 for (unsigned i=0; i < Ty->getNumElements(); ++i) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 // Generate the 'InsertElement' instruction.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 Vec = Builder.CreateInsertElement(Vec, VL[i], Builder.getInt32(i));
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 // Remember that this instruction is used as part of a 'gather' sequence.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 // The caller of the bottom-up slp vectorizer can try to hoist the sequence
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 // if the users are outside of the basic block.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
611 GatherInstructions.push_back(Vec);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
612 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
613
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
614 for (unsigned i = 0; i < Ty->getNumElements(); ++i)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 VectorizedValues[VL[i]] = Vec;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
616
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
617 return Vec;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
618 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
619
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
620 Value *BoUpSLP::vectorizeTree(ArrayRef<Value *> VL, int VF) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
621 Value *V = vectorizeTree_rec(VL, VF);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
622
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
623 Instruction *LastInstr = GetLastInstr(VL, VL.size());
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 int LastInstrIdx = InstrIdx[LastInstr];
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
625 IRBuilder<> Builder(LastInstr);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 for (ValueSet::iterator it = MustExtract.begin(), e = MustExtract.end();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
627 it != e; ++it) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 Instruction *I = cast<Instruction>(*it);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 Value *Vec = VectorizedValues[I];
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 assert(LaneMap.count(I) && "Unable to find the lane for the external use");
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
631 Value *Idx = Builder.getInt32(LaneMap[I]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
632 Value *Extract = Builder.CreateExtractElement(Vec, Idx);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
633 bool Replaced = false;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
634 for (Value::use_iterator U = I->use_begin(), UE = U->use_end(); U != UE;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
635 ++U) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 Instruction *UI = cast<Instruction>(*U);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
637 if (UI->getParent() != I->getParent() || InstrIdx[UI] > LastInstrIdx)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
638 UI->replaceUsesOfWith(I ,Extract);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
639 Replaced = true;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
640 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 assert(Replaced && "Must replace at least one outside user");
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
642 (void)Replaced;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
643 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
644
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 // We moved some instructions around. We have to number them again
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
646 // before we can do any analysis.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
647 numberInstructions();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 MustScalarize.clear();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
649 MustExtract.clear();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
650 VectorizedValues.clear();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 return V;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
652 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
653
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
654 Value *BoUpSLP::vectorizeTree_rec(ArrayRef<Value *> VL, int VF) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
655 Type *ScalarTy = VL[0]->getType();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
656 if (StoreInst *SI = dyn_cast<StoreInst>(VL[0]))
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
657 ScalarTy = SI->getValueOperand()->getType();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
658 VectorType *VecTy = VectorType::get(ScalarTy, VF);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
659
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
660 // Check if all of the operands are constants or identical.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
661 bool AllConst = true;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
662 bool AllSameScalar = true;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
663 for (unsigned i = 0, e = VF; i < e; ++i) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
664 AllConst &= isa<Constant>(VL[i]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
665 AllSameScalar &= (VL[0] == VL[i]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 // The instruction must be in the same BB, and it must be vectorizable.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
667 Instruction *I = dyn_cast<Instruction>(VL[i]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
668 if (MustScalarize.count(VL[i]) || (I && I->getParent() != BB))
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
669 return Scalarize(VL, VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
670 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
671
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
672 // Check that this is a simple vector constant.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
673 if (AllConst || AllSameScalar) return Scalarize(VL, VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
674
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
675 // Scalarize unknown structures.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
676 Instruction *VL0 = dyn_cast<Instruction>(VL[0]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
677 if (!VL0) return Scalarize(VL, VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
678
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
679 if (VectorizedValues.count(VL0)) return VectorizedValues[VL0];
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
680
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 unsigned Opcode = VL0->getOpcode();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
682 for (unsigned i = 0, e = VF; i < e; ++i) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 Instruction *I = dyn_cast<Instruction>(VL[i]);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
684 // If not all of the instructions are identical then we have to scalarize.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
685 if (!I || Opcode != I->getOpcode()) return Scalarize(VL, VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
687
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
688 switch (Opcode) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
689 case Instruction::ZExt:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
690 case Instruction::SExt:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
691 case Instruction::FPToUI:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
692 case Instruction::FPToSI:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
693 case Instruction::FPExt:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
694 case Instruction::PtrToInt:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
695 case Instruction::IntToPtr:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
696 case Instruction::SIToFP:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
697 case Instruction::UIToFP:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
698 case Instruction::Trunc:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
699 case Instruction::FPTrunc:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
700 case Instruction::BitCast: {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
701 ValueList INVL;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
702 for (int i = 0; i < VF; ++i)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
703 INVL.push_back(cast<Instruction>(VL[i])->getOperand(0));
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 Value *InVec = vectorizeTree_rec(INVL, VF);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
705 IRBuilder<> Builder(GetLastInstr(VL, VF));
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 CastInst *CI = dyn_cast<CastInst>(VL0);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 Value *V = Builder.CreateCast(CI->getOpcode(), InVec, VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
708
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 for (int i = 0; i < VF; ++i)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 VectorizedValues[VL[i]] = V;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
711
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
712 return V;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
713 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
714 case Instruction::Add:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
715 case Instruction::FAdd:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
716 case Instruction::Sub:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
717 case Instruction::FSub:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
718 case Instruction::Mul:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
719 case Instruction::FMul:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
720 case Instruction::UDiv:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
721 case Instruction::SDiv:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
722 case Instruction::FDiv:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
723 case Instruction::URem:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
724 case Instruction::SRem:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
725 case Instruction::FRem:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
726 case Instruction::Shl:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
727 case Instruction::LShr:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 case Instruction::AShr:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 case Instruction::And:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
730 case Instruction::Or:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
731 case Instruction::Xor: {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
732 ValueList LHSVL, RHSVL;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
733 for (int i = 0; i < VF; ++i) {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
734 LHSVL.push_back(cast<Instruction>(VL[i])->getOperand(0));
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
735 RHSVL.push_back(cast<Instruction>(VL[i])->getOperand(1));
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
736 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
737
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
738 Value *LHS = vectorizeTree_rec(LHSVL, VF);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
739 Value *RHS = vectorizeTree_rec(RHSVL, VF);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 IRBuilder<> Builder(GetLastInstr(VL, VF));
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
741 BinaryOperator *BinOp = cast<BinaryOperator>(VL0);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
742 Value *V = Builder.CreateBinOp(BinOp->getOpcode(), LHS,RHS);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
743
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
744 for (int i = 0; i < VF; ++i)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
745 VectorizedValues[VL[i]] = V;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
746
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
747 return V;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
748 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
749 case Instruction::Load: {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 LoadInst *LI = cast<LoadInst>(VL0);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
751 unsigned Alignment = LI->getAlignment();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
752
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
753 // Check if all of the loads are consecutive.
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
754 for (unsigned i = 1, e = VF; i < e; ++i)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
755 if (!isConsecutiveAccess(VL[i-1], VL[i]))
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
756 return Scalarize(VL, VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
757
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
758 IRBuilder<> Builder(GetLastInstr(VL, VF));
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
759 Value *VecPtr = Builder.CreateBitCast(LI->getPointerOperand(),
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
760 VecTy->getPointerTo());
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 LI = Builder.CreateLoad(VecPtr);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
762 LI->setAlignment(Alignment);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
763
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
764 for (int i = 0; i < VF; ++i)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
765 VectorizedValues[VL[i]] = LI;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
766
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
767 return LI;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
768 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
769 case Instruction::Store: {
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
770 StoreInst *SI = cast<StoreInst>(VL0);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
771 unsigned Alignment = SI->getAlignment();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
772
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
773 ValueList ValueOp;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
774 for (int i = 0; i < VF; ++i)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
775 ValueOp.push_back(cast<StoreInst>(VL[i])->getValueOperand());
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
776
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
777 Value *VecValue = vectorizeTree_rec(ValueOp, VF);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
778
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
779 IRBuilder<> Builder(GetLastInstr(VL, VF));
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
780 Value *VecPtr = Builder.CreateBitCast(SI->getPointerOperand(),
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
781 VecTy->getPointerTo());
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
782 Builder.CreateStore(VecValue, VecPtr)->setAlignment(Alignment);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
783
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
784 for (int i = 0; i < VF; ++i)
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
785 cast<Instruction>(VL[i])->eraseFromParent();
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
786 return 0;
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
787 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
788 default:
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
789 return Scalarize(VL, VecTy);
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
790 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
791 }
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
792
9ad51c7bc036 1st commit. remove git dir and add all files.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
793 } // end of namespace