Page MenuHomePhabricator

MSP430 calling convention updates

Authored by Annahita on Nov 3 2015, 12:19 PM.



This code updates the MSP430 target calling convention to conform to the MSP430 EABI in order to make it compatible with the new MSP430-GCC framework.

It includes:

  1. Pass args in R12-R15
  2. Return args in R12-R15
  3. Store on stack and pass in registers starting with least significant word
  4. 32-bit argument may be split between register (R15) and stack if no args placed on stack yet
  5. Register ‘holes’ may be back-filled (but only by arguments that fit entirely in regs, no split args once first arg placed on stack)
  6. Only R4 through R10 are callee-saved registers; R11 is updated to be caller-save

Diff Detail

Event Timeline

Annahita updated this revision to Diff 39101.Nov 3 2015, 12:19 PM
Annahita retitled this revision from to MSP430 calling convention updates.
Annahita updated this object.
Annahita added a reviewer: asl.
Annahita added a subscriber: llvm-commits.
asl accepted this revision.Nov 14 2015, 11:52 AM
asl edited edge metadata.

Ok to commit with these 2 small changes. Thanks!


Add comment about backfilling here as well.


Minor nit: space after )

This revision is now accepted and ready to land.Nov 14 2015, 11:52 AM
iains added a subscriber: iains.Nov 25 2015, 3:08 AM

(no comments on the actual patch) .. but...
Is the ABI documented somewhere public?
[I have a patch-in-progress that implements binary output for MSP430, it is likely that I'd need to update it to reflect the ABI]

Is the ABI documented somewhere public?

This patch looks good to me with respect to the MSP430 ABI. I did find one other change that needs to be made. Now that R11 is not preserved by the callee it should be marked as clobbered by the call instructions:

--- a/lib/Target/MSP430/
+++ b/lib/Target/MSP430/
@@ -207,7 +207,7 @@ let isCall = 1 in
   // a use to prevent stack-pointer assignments that appear immediately
   // before calls from potentially appearing dead. Uses for argument
   // registers are added manually.
-  let Defs = [R12, R13, R14, R15, SR],
+  let Defs = [R11, R12, R13, R14, R15, SR],
       Uses = [SP] in {
     def CALLi     : II16i<0x0,
                           (outs), (ins i16imm:$dst),

With that change I was able to run some simple programs compiled with Clang/LLVM against the GDB simulator.

Please note that there are a couple errors in the ABI document.
First, no one is currently passing small structs in registers (GCC or TI) as the document states.
Second, a couple of the C helper functions are listed incorrectly. mspabi_divlu and mspabi_divllu should be mspabi_divul and mspabi_divull. I have local work implementing the C helper function api but it has not yet been submitted for review and in the meantime, GCC has corrected these 2 in a patch as well.

There is also still an omission in the passing of struct args-- the address of the struct should be passed as an argument, which is currently not implemented.

Also, please note that we are stalled on committing this patch until my supervisor gets some additional feedback on patent issues.

Anna Youssefi