[LLVMdev] Fwd: Multiply i8 operands promotes to i32

Borja Ferrer borja.ferav at gmail.com
Mon Oct 8 07:10:55 PDT 2012

Hello Pedro,

As others have said we're assuming that you're using Clang as the frontend,
the MSP430TargetInfo class inside lib/Basic/Targets.cpp (clang codebase)
set ints to be 16 bits wide, so you should get 16bit mults straight away
without promotion. But anyways for 8bit multiplicantions you can do the
following to bypass argument promotion:

1) go to the lib/CodeGen/TargetInfo.cpp (clang codebase)

2) implement a MSP430ABIInfo class derived from ABIInfo, check how other
targets do it in the same file. The important part here is how you
implement the classifyReturnType and classifyArgumentType functions, they
should basically look like this:

class MSP430ABIInfo : public ABIInfo
  MSP430ABIInfo (CodeGenTypes &CGT) : ABIInfo(CGT) {}

  ABIArgInfo classifyReturnType(QualType RetTy) const;
  ABIArgInfo classifyArgumentType(QualType RetTy) const;

  virtual void computeInfo(CGFunctionInfo &FI) const {
    FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
    for (CGFunctionInfo::arg_iterator it = FI.arg_begin(), ie =
         it != ie; ++it)
      it->info = classifyArgumentType(it->type);

  virtual llvm::Value *EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
                                 CodeGenFunction &CGF) const { return 0; }

ABIArgInfo MSP430ABIInfo::classifyReturnType(QualType RetTy) const {
  if (RetTy->isVoidType())
    return ABIArgInfo::getIgnore();
  if (isAggregateTypeForABI(RetTy))
    return ABIArgInfo::getIndirect(0);

  return ABIArgInfo::getDirect();

ABIArgInfo MSP430ABIInfo::classifyArgumentType(QualType Ty) const {
  if (isAggregateTypeForABI(Ty))
    return ABIArgInfo::getIndirect(0);

  return ABIArgInfo::getDirect();

3) Register your new MSP430ABIInfo class in the TargetCodeGenInfo
constructor inside MSP430TargetCodeGenInfo by replacing DefaultABIInfo.

Hope this helps.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121008/a1ec7539/attachment.html>

More information about the llvm-dev mailing list