llvm.org GIT mirror llvm / 6e0e354
Move clone_params around git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@260846 91177308-0d34-0410-b5e6-96231b3b80d8 Amaury Sechet 4 years ago
1 changed file(s) with 76 addition(s) and 78 deletion(s). Raw diff Collapse all Expand all
148148 }
149149 };
150150
151 static ValueMap clone_params(LLVMValueRef Src, LLVMValueRef Dst);
151 static ValueMap clone_params(LLVMValueRef Src, LLVMValueRef Dst) {
152 unsigned Count = LLVMCountParams(Src);
153 if (Count != LLVMCountParams(Dst)) {
154 fprintf(stderr, "Parameter count mismatch\n");
155 exit(-1);
156 }
157
158 ValueMap VMap;
159 if (Count == 0)
160 return VMap;
161
162 LLVMValueRef SrcFirst = LLVMGetFirstParam(Src);
163 LLVMValueRef DstFirst = LLVMGetFirstParam(Dst);
164 LLVMValueRef SrcLast = LLVMGetLastParam(Src);
165 LLVMValueRef DstLast = LLVMGetLastParam(Dst);
166
167 LLVMValueRef SrcCur = SrcFirst;
168 LLVMValueRef DstCur = DstFirst;
169 LLVMValueRef SrcNext = nullptr;
170 LLVMValueRef DstNext = nullptr;
171 while (true) {
172 const char *Name = LLVMGetValueName(SrcCur);
173 LLVMSetValueName(DstCur, Name);
174
175 VMap[SrcCur] = DstCur;
176
177 Count--;
178 SrcNext = LLVMGetNextParam(SrcCur);
179 DstNext = LLVMGetNextParam(DstCur);
180 if (SrcNext == nullptr && DstNext == nullptr) {
181 if (SrcCur != SrcLast) {
182 fprintf(stderr, "SrcLast param does not match End\n");
183 exit(-1);
184 }
185
186 if (DstCur != DstLast) {
187 fprintf(stderr, "DstLast param does not match End\n");
188 exit(-1);
189 }
190
191 break;
192 }
193
194 if (SrcNext == nullptr) {
195 fprintf(stderr, "SrcNext was unexpectedly null\n");
196 exit(-1);
197 }
198
199 if (DstNext == nullptr) {
200 fprintf(stderr, "DstNext was unexpectedly null\n");
201 exit(-1);
202 }
203
204 LLVMValueRef SrcPrev = LLVMGetPreviousParam(SrcNext);
205 if (SrcPrev != SrcCur) {
206 fprintf(stderr, "SrcNext.Previous param is not Current\n");
207 exit(-1);
208 }
209
210 LLVMValueRef DstPrev = LLVMGetPreviousParam(DstNext);
211 if (DstPrev != DstCur) {
212 fprintf(stderr, "DstNext.Previous param is not Current\n");
213 exit(-1);
214 }
215
216 SrcCur = SrcNext;
217 DstCur = DstNext;
218 }
219
220 if (Count != 0) {
221 fprintf(stderr, "Parameter count does not match iteration\n");
222 exit(-1);
223 }
224
225 return VMap;
226 }
152227
153228 struct FunCloner {
154229 LLVMValueRef Fun;
534609 }
535610 };
536611
537 static ValueMap clone_params(LLVMValueRef Src, LLVMValueRef Dst) {
538 unsigned Count = LLVMCountParams(Src);
539 if (Count != LLVMCountParams(Dst)) {
540 fprintf(stderr, "Parameter count mismatch\n");
541 exit(-1);
542 }
543
544 ValueMap VMap;
545 if (Count == 0)
546 return VMap;
547
548 LLVMValueRef SrcFirst = LLVMGetFirstParam(Src);
549 LLVMValueRef DstFirst = LLVMGetFirstParam(Dst);
550 LLVMValueRef SrcLast = LLVMGetLastParam(Src);
551 LLVMValueRef DstLast = LLVMGetLastParam(Dst);
552
553 LLVMValueRef SrcCur = SrcFirst;
554 LLVMValueRef DstCur = DstFirst;
555 LLVMValueRef SrcNext = nullptr;
556 LLVMValueRef DstNext = nullptr;
557 while (true) {
558 const char *Name = LLVMGetValueName(SrcCur);
559 LLVMSetValueName(DstCur, Name);
560
561 VMap[SrcCur] = DstCur;
562
563 Count--;
564 SrcNext = LLVMGetNextParam(SrcCur);
565 DstNext = LLVMGetNextParam(DstCur);
566 if (SrcNext == nullptr && DstNext == nullptr) {
567 if (SrcCur != SrcLast) {
568 fprintf(stderr, "SrcLast param does not match End\n");
569 exit(-1);
570 }
571
572 if (DstCur != DstLast) {
573 fprintf(stderr, "DstLast param does not match End\n");
574 exit(-1);
575 }
576
577 break;
578 }
579
580 if (SrcNext == nullptr) {
581 fprintf(stderr, "SrcNext was unexpectedly null\n");
582 exit(-1);
583 }
584
585 if (DstNext == nullptr) {
586 fprintf(stderr, "DstNext was unexpectedly null\n");
587 exit(-1);
588 }
589
590 LLVMValueRef SrcPrev = LLVMGetPreviousParam(SrcNext);
591 if (SrcPrev != SrcCur) {
592 fprintf(stderr, "SrcNext.Previous param is not Current\n");
593 exit(-1);
594 }
595
596 LLVMValueRef DstPrev = LLVMGetPreviousParam(DstNext);
597 if (DstPrev != DstCur) {
598 fprintf(stderr, "DstNext.Previous param is not Current\n");
599 exit(-1);
600 }
601
602 SrcCur = SrcNext;
603 DstCur = DstNext;
604 }
605
606 if (Count != 0) {
607 fprintf(stderr, "Parameter count does not match iteration\n");
608 exit(-1);
609 }
610
611 return VMap;
612 }
613
614612 static LLVMValueRef clone_function(LLVMValueRef Src, LLVMModuleRef M) {
615613 const char *Name = LLVMGetValueName(Src);
616614 LLVMValueRef Fun = LLVMGetNamedFunction(M, Name);