Inline Assembler

From Dmz-portal

Jump to: navigation, search

Inline Assembly Info

Inline Source Assembler

This is for assembly code that is embedded in C/C++ files and dumped out in the .s file.

Evidently there are at least 2 flavors of the in-line assembly code:

  1. Simple string wrapped in an asm directive

    extern int bar();
    int foo (int input)
    input += 9;
    __asm__(" jalr $25\n\t"
    " nop\n\t"
    " add $7,$8,$9");
    return input + bar();
  2. Extended Asm that has more interaction with the compiler
    This is the syntax for calling asm() in your C/C++ code:

    asm ( assembler template
     : output operands (optional)
     : input operands (optional)
     : clobbered registers list (optional)

In LLVM there seems to be currently a limited number of constraint types that all the possible input constraints get funneled into. These are defined in include/llvm/Target/TargetLowering.h:

 enum ConstraintType {
   C_Register,            // Constraint represents specific register(s).
   C_RegisterClass,       // Constraint represents any of register(s) in class.
   C_Memory,              // Memory constraint.
   C_Other,               // Something else.
   C_Unknown              // Unsupported constraint.
 enum ConstraintWeight {
   // Generic weights.
   CW_Invalid  = -1,     // No match.
   CW_Okay     = 0,      // Acceptable.
   CW_Good     = 1,      // Good weight.
   CW_Better   = 2,      // Better weight.
   CW_Best     = 3,      // Best weight.
   // Well-known weights.
   CW_SpecificReg  = CW_Okay,    // Specific register operands.
   CW_Register     = CW_Good,    // Register operands.
   CW_Memory       = CW_Better,  // Memory operands.
   CW_Constant     = CW_Best,    // Constant operand.
   CW_Default      = CW_Okay     // Default or don't know type.

At least initially, the Mips constraint variants need to be funneled into one of the above types and weights through routines in MipsISelLowering.cpp:

Special case registers such as condition result will get picked in getRegForInlineAsmConstraint(). Immediates will need more work. X86 has the method LowerAsmOperandForConstraint() to deal with it.

Both X86 and ARM only seem to have single letter constraints whereas mips have single and double. To make things worse, Chris D. believes a lot of the user encoding is wrong, but not wrong enough to have it not work.

links and docs

Personal tools