[llvm] r205090 - ARM64: initial backend import

Pasi Parviainen pasi.parviainen at iki.fi
Sat Mar 29 16:30:50 PDT 2014


On 29.3.2014 12:18, Tim Northover wrote:

> Added: llvm/trunk/lib/Target/ARM64/AsmParser/ARM64AsmParser.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM64/AsmParser/ARM64AsmParser.cpp?rev=205090&view=auto
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM64/AsmParser/ARM64AsmParser.cpp (added)
> +++ llvm/trunk/lib/Target/ARM64/AsmParser/ARM64AsmParser.cpp Sat Mar 29 05:18:08 2014

...

> +  void addMemoryRegisterOffsetOperands(MCInst &Inst, unsigned N, bool DoShift) {
> +    assert(N == 3 && "Invalid number of operands!");
> +
> +    Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
> +    Inst.addOperand(MCOperand::CreateReg(Mem.OffsetRegNum));
> +    unsigned ExtendImm = ARM64_AM::getMemExtendImm(Mem.ExtType, DoShift);
> +    Inst.addOperand(MCOperand::CreateImm(ExtendImm));
> +  }

Used at here...

> Added: llvm/trunk/lib/Target/ARM64/MCTargetDesc/ARM64AddressingModes.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM64/MCTargetDesc/ARM64AddressingModes.h?rev=205090&view=auto
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM64/MCTargetDesc/ARM64AddressingModes.h (added)
> +++ llvm/trunk/lib/Target/ARM64/MCTargetDesc/ARM64AddressingModes.h Sat Mar 29 05:18:08 2014

...

> +//===----------------------------------------------------------------------===//
> +// Extends
> +//
> +
> +enum ExtendType {
> +  InvalidExtend = -1,
> +  UXTB = 0,
> +  UXTH = 1,
> +  UXTW = 2,
> +  UXTX = 3,
> +  SXTB = 4,
> +  SXTH = 5,
> +  SXTW = 6,
> +  SXTX = 7
> +};
> +
> +/// getExtendName - Get the string encoding for the extend type.
> +static inline const char *getExtendName(ARM64_AM::ExtendType ET) {
> +  switch (ET) {
> +  default: assert(false && "unhandled extend type!");
> +  case ARM64_AM::UXTB: return "uxtb";
> +  case ARM64_AM::UXTH: return "uxth";
> +  case ARM64_AM::UXTW: return "uxtw";
> +  case ARM64_AM::UXTX: return "uxtx";
> +  case ARM64_AM::SXTB: return "sxtb";
> +  case ARM64_AM::SXTH: return "sxth";
> +  case ARM64_AM::SXTW: return "sxtw";
> +  case ARM64_AM::SXTX: return "sxtx";
> +  }
> +  return 0;
> +}
> +
> +/// getArithShiftValue - get the arithmetic shift value.
> +static inline unsigned getArithShiftValue(unsigned Imm) {
> +  return Imm & 0x7;
> +}
> +
> +/// getExtendType - Extract the extend type for operands of arithmetic ops.
> +static inline ARM64_AM::ExtendType getArithExtendType(unsigned Imm) {
> +  return ARM64_AM::ExtendType((Imm >> 3) & 0x7);
> +}
> +
> +/// getArithExtendImm - Encode the extend type and shift amount for an
> +///                     arithmetic instruction:
> +///   imm:     3-bit extend amount
> +///   shifter: 000 ==> uxtb
> +///            001 ==> uxth
> +///            010 ==> uxtw
> +///            011 ==> uxtx
> +///            100 ==> sxtb
> +///            101 ==> sxth
> +///            110 ==> sxtw
> +///            111 ==> sxtx
> +///   {5-3}  = shifter
> +///   {2-0}  = imm3
> +static inline unsigned getArithExtendImm(ARM64_AM::ExtendType ET,
> +                                         unsigned Imm) {
> +  assert((Imm & 0x7) == Imm && "Illegal shifted immedate value!");
> +  return (unsigned(ET) << 3) | (Imm & 0x7);
> +}
> +
> +/// getMemDoShift - Extract the "do shift" flag value for load/store
> +/// instructions.
> +static inline bool getMemDoShift(unsigned Imm) {
> +  return (Imm & 0x1) != 0;
> +}
> +
> +/// getExtendType - Extract the extend type for the offset operand of
> +/// loads/stores.
> +static inline ARM64_AM::ExtendType getMemExtendType(unsigned Imm) {
> +  return ARM64_AM::ExtendType((Imm >> 1) & 0x7);
> +}
> +
> +/// getExtendImm - Encode the extend type and amount for a load/store inst:
> +///   imm:     3-bit extend amount
> +///   shifter: 000 ==> uxtb
> +///            001 ==> uxth
> +///            010 ==> uxtw
> +///            011 ==> uxtx
> +///            100 ==> sxtb
> +///            101 ==> sxth
> +///            110 ==> sxtw
> +///            111 ==> sxtx
> +///   {3-1}  = shifter
> +///   {0}  = imm3
> +static inline unsigned getMemExtendImm(ARM64_AM::ExtendType ET, bool Imm) {
> +  assert((Imm & 0x7) == Imm && "Illegal shifted immedate value!");
> +  return (unsigned(ET) << 1) | (Imm & 0x7);
> +}

MSVC gives following warning for this function for expression '(Imm & 0x7):

warning C4806: '&' : unsafe operation: no value of type 'bool' promoted 
to type 'int' can equal the given constant

And seems like it's on to something, since this function and its 
comments (partially) seems really suspicious. Implementation is a direct 
copy from getArithExtendImm function above and testing a boolean value 
with it self modulo 8 is a dead give away.

Pasi.




More information about the llvm-commits mailing list