# HG changeset patch # User Frits van Bommel # Date 1234825700 -3600 # Node ID 985104c0f1dbda80656569bb75b2299b76df724b # Parent fb31a4afa2df52ff57d89e6de6f05a526a3956de Fix the problems exposed by the callingconv1.d test case. The first was that unless otherwise specified, inputs are assumed to be in registers even if they specify a "matching output" that's in memory. While testing that fix, I also ran into a bug causing the generated "matching output" for any input was always the first one instead of the correct one. diff -r fb31a4afa2df -r 985104c0f1db gen/asmstmt.cpp --- a/gen/asmstmt.cpp Mon Feb 16 23:56:56 2009 +0100 +++ b/gen/asmstmt.cpp Tue Feb 17 00:08:20 2009 +0100 @@ -385,18 +385,25 @@ for(it i = output_constraints.begin(), e = output_constraints.end(); i != e; ++i, ++n) { // rewrite update constraint to in and out constraints if((*i)[0] == '+') { - (*i)[0] = '='; - std::string input_constraint; - std::stringstream ss; - ss << n; - ss >> input_constraint; - //FIXME: I think multiple inout constraints will mess up the order! - input_constraints.push_front(input_constraint); + assert(*i == mrw_cns && "What else are we updating except memory?"); + /* LLVM doesn't support updating operands, so split into an input + * and an output operand. + */ + + // Change update operand to pure output operand. + *i = mw_cns; + + // Add input operand with same value, with original as "matching output". + std::ostringstream ss; + ss << m_cns << (n + asmblock->outputcount); + input_constraints.push_front(ss.str()); input_values.push_front(output_values[n]); } llvmOutConstraints += *i; llvmOutConstraints += ","; } + asmblock->outputcount += n; + for(it i = input_constraints.begin(), e = input_constraints.end(); i != e; ++i) { llvmInConstraints += *i; llvmInConstraints += ","; diff -r fb31a4afa2df -r 985104c0f1db gen/irstate.h --- a/gen/irstate.h Mon Feb 16 23:56:56 2009 +0100 +++ b/gen/irstate.h Tue Feb 17 00:08:20 2009 +0100 @@ -81,6 +81,7 @@ { std::deque s; std::set clobs; + size_t outputcount; // stores the labels within the asm block std::vector internalLabels; @@ -92,7 +93,9 @@ LLValue* (*retfixup)(IRBuilderHelper b, LLValue* orig); // Modifies retval IRAsmBlock(AsmBlockStatement* b) - : asmBlock(b), retty(NULL), retn(0), retemu(false), retfixup(NULL) {} + : asmBlock(b), retty(NULL), retn(0), retemu(false), retfixup(NULL), + outputcount(0) + {} }; // llvm::CallInst and llvm::InvokeInst don't share a common base