Search code examples
compiler-constructionclangllvminline-assembly

What is a clobber?


Clang TargetInfo has a method called getClobbers:

Returns a string of target-specific clobbers, in LLVM format.

So, what is a clobber?


Solution

  • A clobbered register is a register which is trashed i.e. modified in unpredictable way by inline assembler. This usually happens when you need a temp. register or use particular instruction which happens to modify some register as a by-product.

    Usually programmer explicitly declares registers which are clobbered by his inline asm code but some may be considered to be trashed by default and that's where getClobbers come into play.

    getClobbers returns empty result for most targets. On MIPS GCC has historically not used $1 in generated code so most programmers didn't bother to declare it as clobbered. To reduce portability costs, LLVM considers $1 to be always clobbered in inline asm. Another example is arithmetic flags register (cc) which is considered to be always clobbered by inline asm by GCC on i386 and x86_64 targets.