@@ -115,7 +115,6 @@ static bool markLoopInfo(Module &M, Function *marker, function_ref<LoopInfo &(Fu
115115
116116 LoopInfo &LI = GetLI (*I->getParent ()->getParent ());
117117 Loop *L = LI.getLoopFor (I->getParent ());
118- I->removeFromParent ();
119118 if (!L)
120119 continue ;
121120
@@ -131,7 +130,7 @@ static bool markLoopInfo(Module &M, Function *marker, function_ref<LoopInfo &(Fu
131130 TempMDTuple TempNode = MDNode::getTemporary (Lh->getContext (), None);
132131 MDs.push_back (TempNode.get ());
133132
134- // Walk `julia.loopinfo` metadata and filter out `julia.simdloop` and `julia.ivdep`
133+ // Walk `julia.loopinfo` metadata and filter out `julia.simdloop`
135134 if (I->hasMetadataOtherThanDebugLoc ()) {
136135 MDNode *JLMD= I->getMetadata (" julia.loopinfo" );
137136 if (JLMD) {
@@ -144,8 +143,6 @@ static bool markLoopInfo(Module &M, Function *marker, function_ref<LoopInfo &(Fu
144143 if (S->getString ().startswith (" julia" )) {
145144 if (S->getString ().equals (" julia.simdloop" ))
146145 simd = true ;
147- if (S->getString ().equals (" julia.ivdep" ))
148- ivdep = true ;
149146 continue ;
150147 }
151148 }
@@ -154,7 +151,10 @@ static bool markLoopInfo(Module &M, Function *marker, function_ref<LoopInfo &(Fu
154151 }
155152 }
156153
157- LLVM_DEBUG (dbgs () << " LSL: simd: " << simd << " ivdep: " << ivdep << " \n " );
154+ if (!simd)
155+ continue ;
156+
157+ LLVM_DEBUG (dbgs () << " LSL: Transform start.\n " );
158158
159159 MDNode *n = L->getLoopID ();
160160 if (n) {
@@ -173,35 +173,44 @@ static bool markLoopInfo(Module &M, Function *marker, function_ref<LoopInfo &(Fu
173173
174174 MDNode *m = MDNode::get (Lh->getContext (), ArrayRef<Metadata *>(LoopID));
175175
176- // If ivdep is true we assume that there is no memory dependency between loop iterations
177- // This is a fairly strong assumption and does often not hold true for generic code.
178- if (ivdep) {
179- // Mark memory references so that Loop::isAnnotatedParallel will return true for this loop.
180- for (BasicBlock *BB : L->blocks ()) {
181- for (Instruction &I : *BB) {
182- if (I.mayReadOrWriteMemory ()) {
183- I.setMetadata (LLVMContext::MD_mem_parallel_loop_access, m);
184- }
185- }
186- }
187- assert (L->isAnnotatedParallel ());
176+ // Mark floating-point reductions as okay to reassociate/commute.
177+ for (BasicBlock::iterator I = Lh->begin (), E = Lh->end (); I != E; ++I) {
178+ if (PHINode *Phi = dyn_cast<PHINode>(I))
179+ enableUnsafeAlgebraIfReduction (Phi, L);
180+ else
181+ break ;
188182 }
189183
190- if (simd) {
191- // Mark floating-point reductions as okay to reassociate/commute.
192- for (BasicBlock::iterator I = Lh->begin (), E = Lh->end (); I != E; ++I) {
193- if (PHINode *Phi = dyn_cast<PHINode>(I))
194- enableUnsafeAlgebraIfReduction (Phi, L);
195- else
196- break ;
184+ for (BasicBlock *BB : L->blocks ()) {
185+ for (Instruction &I : *BB) {
186+ // find julia.ivdep.begin/end block
187+ if (I.hasMetadataOtherThanDebugLoc ()) {
188+ MDNode *JLMD= I.getMetadata (" julia.loopinfo" );
189+ if (JLMD) {
190+ for (unsigned i = 0 , ie = JLMD->getNumOperands (); i < ie; ++i) {
191+ Metadata *Op = JLMD->getOperand (i);
192+ const MDString *S = dyn_cast<MDString>(Op);
193+ if (S && S->getString ().startswith (" julia.ivdep" )) {
194+ if (S->getString ().equals (" julia.ivdep.begin" ))
195+ ivdep = true ; // turn on ivdep
196+ if (S->getString ().equals (" julia.ivdep.end" ))
197+ ivdep = false ; // turn off ivdep
198+ break ; // only accept 1 julia.ivdep.begin/end
199+ }
200+ }
201+ }
202+ }
203+ if (ivdep && I.mayReadOrWriteMemory ())
204+ I.setMetadata (LLVMContext::MD_mem_parallel_loop_access, m);
197205 }
198206 }
207+ LLVM_DEBUG (dbgs () << " LSL: Transform end.\n " );
199208
200209 Changed = true ;
201210 }
202211
203212 for (Instruction *I : ToDelete)
204- I->deleteValue ();
213+ I->eraseFromParent ();
205214 marker->eraseFromParent ();
206215
207216 return Changed;
0 commit comments