comparison gen/asmstmt.cpp @ 979:523bf4f166bc

Fix some assembler issues: The assembler was miscompiling "add" (specifically, the "add reg/mem, imm" variations). The change that caused this seems to have been made because without it, some "add"s didn't compile at all. This patch reverts the previous change, and makes sure assembler operands are remapped correctly even though the input operands auto-generated due to updating operations aren't explicitly used.
author Frits van Bommel <fvbommel wxs.nl>
date Wed, 18 Feb 2009 21:46:14 +0100
parents 6a32d2e18175
children ae710cba0884
comparison
equal deleted inserted replaced
978:6a32d2e18175 979:523bf4f166bc
394 *i = mw_cns; 394 *i = mw_cns;
395 395
396 // Add input operand with same value, with original as "matching output". 396 // Add input operand with same value, with original as "matching output".
397 std::ostringstream ss; 397 std::ostringstream ss;
398 ss << '*' << (n + asmblock->outputcount); 398 ss << '*' << (n + asmblock->outputcount);
399 input_constraints.push_front(ss.str()); 399 // Must be at the back; unused operands before used ones screw up numbering.
400 input_values.push_front(output_values[n]); 400 input_constraints.push_back(ss.str());
401 input_values.push_back(output_values[n]);
401 } 402 }
402 llvmOutConstraints += *i; 403 llvmOutConstraints += *i;
403 llvmOutConstraints += ","; 404 llvmOutConstraints += ",";
404 } 405 }
405 asmblock->outputcount += n; 406 asmblock->outputcount += n;
438 439
439 abiret = NULL; 440 abiret = NULL;
440 } 441 }
441 442
442 // rewrite argument indices to the block scope indices 443 // rewrite argument indices to the block scope indices
443 static void remap_outargs(std::string& insnt, size_t nargs, size_t& idx) 444 static void remap_outargs(std::string& insnt, size_t nargs, size_t idx)
444 { 445 {
445 static const std::string digits[10] = 446 static const std::string digits[10] =
446 { 447 {
447 "0","1","2","3","4", 448 "0","1","2","3","4",
448 "5","6","7","8","9" 449 "5","6","7","8","9"
463 insnt.replace(pos, needle.size(), buf); 464 insnt.replace(pos, needle.size(), buf);
464 } 465 }
465 } 466 }
466 467
467 // rewrite argument indices to the block scope indices 468 // rewrite argument indices to the block scope indices
468 static void remap_inargs(std::string& insnt, size_t nargs, size_t& idx) 469 static void remap_inargs(std::string& insnt, size_t nargs, size_t idx)
469 { 470 {
470 static const std::string digits[10] = 471 static const std::string digits[10] =
471 { 472 {
472 "0","1","2","3","4", 473 "0","1","2","3","4",
473 "5","6","7","8","9" 474 "5","6","7","8","9"
642 if (!a->out_c.empty()) 643 if (!a->out_c.empty())
643 { 644 {
644 out_c += a->out_c; 645 out_c += a->out_c;
645 } 646 }
646 remap_outargs(a->code, onn+a->in.size(), asmIdx); 647 remap_outargs(a->code, onn+a->in.size(), asmIdx);
648 asmIdx += onn;
647 } 649 }
648 650
649 Logger::println("do inputs"); 651 Logger::println("do inputs");
650 for (size_t i=0; i<n; ++i) 652 for (size_t i=0; i<n; ++i)
651 { 653 {
660 if (!a->in_c.empty()) 662 if (!a->in_c.empty())
661 { 663 {
662 in_c += a->in_c; 664 in_c += a->in_c;
663 } 665 }
664 remap_inargs(a->code, inn+a->out.size(), asmIdx); 666 remap_inargs(a->code, inn+a->out.size(), asmIdx);
667 asmIdx += inn;
665 if (!code.empty()) 668 if (!code.empty())
666 code += "\n\t"; 669 code += "\n\t";
667 code += a->code; 670 code += a->code;
668 } 671 }
669 asmblock->s.clear(); 672 asmblock->s.clear();
705 args.insert(args.end(), inargs.begin(), inargs.end()); 708 args.insert(args.end(), inargs.begin(), inargs.end());
706 709
707 if (Logger::enabled()) { 710 if (Logger::enabled()) {
708 Logger::cout() << "Arguments:" << '\n'; 711 Logger::cout() << "Arguments:" << '\n';
709 Logger::indent(); 712 Logger::indent();
710 for (std::vector<LLValue*>::iterator b = args.begin(), i = b, e = args.end(); i != e; ++i) 713 for (std::vector<LLValue*>::iterator b = args.begin(), i = b, e = args.end(); i != e; ++i) {
711 Logger::cout() << '$' << (i - b) << " ==> " << **i; 714 std::ostream& cout = Logger::cout();
715 cout << '$' << (i - b) << " ==> " << **i;
716 if (llvm::isa<LLConstant>(*i))
717 cout << '\n';
718 }
712 Logger::undent(); 719 Logger::undent();
713 } 720 }
714 721
715 llvm::InlineAsm* ia = llvm::InlineAsm::get(fty, code, out_c, true); 722 llvm::InlineAsm* ia = llvm::InlineAsm::get(fty, code, out_c, true);
716 723