@@ -37,7 +37,6 @@ JointMatrixFuncsResolutionPass::JointMatrixFuncsResolutionPass(OpenCLProgramCont
37
37
38
38
bool JointMatrixFuncsResolutionPass::runOnFunction (Function& F)
39
39
{
40
- PlaceholderInstructions.clear ();
41
40
ResolvedValues.clear ();
42
41
InstsToErase.clear ();
43
42
Changed = false ;
@@ -485,62 +484,37 @@ Value *JointMatrixFuncsResolutionPass::ResolveCall(CallInst *CI) {
485
484
} else if (funcName.startswith (JointMatrixSliceExtract)) {
486
485
NewValue = ResolveSliceExtract (CI);
487
486
}
487
+
488
+ CacheResolvedValue (CI, NewValue);
488
489
return NewValue;
489
490
}
490
491
491
- Instruction *JointMatrixFuncsResolutionPass::CreatePlaceholder (Value *v) {
492
- Type *type = ResolveType (v->getType (), nullptr );
493
- Instruction *predecesor = nullptr ;
494
- if (Instruction *inst = dyn_cast<Instruction>(v)) {
495
- predecesor = inst;
496
- }
497
- /* I'm using bit-casts as placeholder values. Undefs of each type are unique per
498
- * module and cannot be used as unique placeholders. */
499
- return BitCastInst::Create (Instruction::BitCast, UndefValue::get (type),
500
- type, " tmp.value" , predecesor);
492
+ void JointMatrixFuncsResolutionPass::CacheResolvedValue (Value *oldValue, Value *newValue) {
493
+ ResolvedValues[oldValue] = newValue;
501
494
}
502
495
503
496
Value *JointMatrixFuncsResolutionPass::Resolve (Value *v)
504
497
{
505
498
if (ResolvedValues.count (v) > 0 ) {
506
- Value *value = ResolvedValues[v];
507
- if (value == v) {
508
- /* We are still resolving 'v'. Create a dummy value that will be
509
- * replaced later when 'v' is finally resolved. */
510
- Instruction *placeholder = CreatePlaceholder (v);
511
- PlaceholderInstructions[v] = placeholder;
512
- return placeholder;
513
- }
514
499
return ResolvedValues[v];
515
500
}
516
501
517
502
if (CallInst *CI = dyn_cast<CallInst>(v)) {
518
503
return ResolveCall (CI);
519
504
} else if (PHINode *PN = dyn_cast<PHINode>(v)) {
520
505
unsigned IncomingCount = PN->getNumIncomingValues ();
521
- ResolvedValues[v] = v;
522
- Value *First = Resolve (PN->getIncomingValue (0 ));
523
506
524
- PHINode *NewPN = PHINode::Create (First->getType (), IncomingCount, " matrix.phi.node" , PN);
525
- ResolvedValues[v] = NewPN;
507
+ Type *type = ResolveType (v->getType (), nullptr );
508
+ PHINode *NewPN = PHINode::Create (type, IncomingCount, " matrix.phi.node" , PN);
509
+ CacheResolvedValue (v, NewPN);
526
510
527
- if (PlaceholderInstructions.count (v) > 0 ) {
528
- Instruction *placeholder = PlaceholderInstructions[v];
529
- PlaceholderInstructions.erase (v);
530
- placeholder->replaceAllUsesWith (NewPN);
531
- InstsToErase.insert (placeholder);
532
- }
533
-
534
- NewPN->addIncoming (First, PN->getIncomingBlock (0 ));
535
- for (unsigned i = 1 ; i < IncomingCount; i++) {
511
+ for (unsigned i = 0 ; i < IncomingCount; i++) {
536
512
Value *oldOperand = PN->getIncomingValue (i);
537
513
Value *operand = Resolve (oldOperand);
538
514
NewPN->addIncoming (operand, PN->getIncomingBlock (i));
539
515
}
540
516
541
- PN->replaceAllUsesWith (UndefValue::get (PN->getType ()));
542
- PN->eraseFromParent ();
543
-
517
+ InstsToErase.insert (PN);
544
518
return NewPN;
545
519
}
546
520
@@ -555,11 +529,11 @@ void JointMatrixFuncsResolutionPass::visitCallInst(CallInst& CI)
555
529
return ;
556
530
557
531
StringRef funcName = func->getName ();
558
- /* Look for store functions and then recursively trace values that are used
559
- * by them. In future when returning and passing matrices by argument is
560
- * supported this also basic block terminators should be used as
532
+ /* Resolve calls to JointMatrix BIs that haven't been resolved yet. In
533
+ * future when returning and passing matrices by argument is
534
+ * supported also basic block terminators should be used as
561
535
* transformation starting point */
562
- if (funcName.startswith (CommonBIPrefix)) {
536
+ if (funcName.startswith (CommonBIPrefix) && ResolvedValues. count (&CI) <= 0 ) {
563
537
ResolveCall (&CI);
564
538
}
565
539
}
0 commit comments