@@ -115,7 +115,6 @@ static bool markLoopInfo(Module &M, Function *marker, function_ref<LoopInfo &(Fu
115
115
116
116
LoopInfo &LI = GetLI (*I->getParent ()->getParent ());
117
117
Loop *L = LI.getLoopFor (I->getParent ());
118
- I->removeFromParent ();
119
118
if (!L)
120
119
continue ;
121
120
@@ -131,7 +130,7 @@ static bool markLoopInfo(Module &M, Function *marker, function_ref<LoopInfo &(Fu
131
130
TempMDTuple TempNode = MDNode::getTemporary (Lh->getContext (), None);
132
131
MDs.push_back (TempNode.get ());
133
132
134
- // Walk `julia.loopinfo` metadata and filter out `julia.simdloop` and `julia.ivdep`
133
+ // Walk `julia.loopinfo` metadata and filter out `julia.simdloop`
135
134
if (I->hasMetadataOtherThanDebugLoc ()) {
136
135
MDNode *JLMD= I->getMetadata (" julia.loopinfo" );
137
136
if (JLMD) {
@@ -144,8 +143,6 @@ static bool markLoopInfo(Module &M, Function *marker, function_ref<LoopInfo &(Fu
144
143
if (S->getString ().startswith (" julia" )) {
145
144
if (S->getString ().equals (" julia.simdloop" ))
146
145
simd = true ;
147
- if (S->getString ().equals (" julia.ivdep" ))
148
- ivdep = true ;
149
146
continue ;
150
147
}
151
148
}
@@ -154,7 +151,10 @@ static bool markLoopInfo(Module &M, Function *marker, function_ref<LoopInfo &(Fu
154
151
}
155
152
}
156
153
157
- LLVM_DEBUG (dbgs () << " LSL: simd: " << simd << " ivdep: " << ivdep << " \n " );
154
+ if (!simd)
155
+ continue ;
156
+
157
+ LLVM_DEBUG (dbgs () << " LSL: Transform start.\n " );
158
158
159
159
MDNode *n = L->getLoopID ();
160
160
if (n) {
@@ -173,35 +173,44 @@ static bool markLoopInfo(Module &M, Function *marker, function_ref<LoopInfo &(Fu
173
173
174
174
MDNode *m = MDNode::get (Lh->getContext (), ArrayRef<Metadata *>(LoopID));
175
175
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 ;
188
182
}
189
183
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);
197
205
}
198
206
}
207
+ LLVM_DEBUG (dbgs () << " LSL: Transform end.\n " );
199
208
200
209
Changed = true ;
201
210
}
202
211
203
212
for (Instruction *I : ToDelete)
204
- I->deleteValue ();
213
+ I->eraseFromParent ();
205
214
marker->eraseFromParent ();
206
215
207
216
return Changed;
0 commit comments