[llvm] r275676 - Re-commit [AMDGPU] Add metadata for runtime

Liu, Yaxun (Sam) via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 19 06:51:15 PDT 2016


That function is only used to translate types shown up in __attribute__((vec_type_hint(T))). Only OpenCL builtin types need to be supported. Probably we could return "ix" where x is number of bits for non-opencl-builtin types?

Sam

-----Original Message-----
From: Arsenault, Matthew 
Sent: Monday, July 18, 2016 7:52 PM
To: Liu, Yaxun (Sam) <Yaxun.Liu at amd.com>; llvm-commits at lists.llvm.org
Subject: Re: [llvm] r275676 - Re-commit [AMDGPU] Add metadata for runtime

On 07/15/2016 10:09 PM, Yaxun Liu via llvm-commits wrote:
> Author: yaxunl
> Date: Sat Jul 16 00:09:21 2016
> New Revision: 275676
>
> URL: http://llvm.org/viewvc/llvm-project?rev=275676&view=rev
> Log:
> Re-commit [AMDGPU] Add metadata for runtime
>
> Attempting to fix lit test failure on ppc.
>
>
> Added:
>      llvm/trunk/lib/Target/AMDGPU/AMDGPURuntimeMetadata.h
>      llvm/trunk/test/CodeGen/AMDGPU/runtime-metadata.ll
> Modified:
>      llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
>      llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.h
>
> Modified: llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/AMDGP
> UAsmPrinter.cpp?rev=275676&r1=275675&r2=275676&view=diff
> ======================================================================
> ========
> --- llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp (original)
> +++ llvm/trunk/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp Sat Jul 16 
> +++ 00:09:21 2016
> @@ -39,7 +39,9 @@
>   #include "llvm/Support/MathExtras.h"
>   #include "llvm/Support/TargetRegistry.h"
>   #include "llvm/Target/TargetLoweringObjectFile.h"
> +#include "AMDGPURuntimeMetadata.h"
>   
> +using namespace ::AMDGPU;
>   using namespace llvm;
>   
>   // TODO: This should get the default rounding mode from the kernel. 
> We just set @@ -111,6 +113,7 @@ void AMDGPUAsmPrinter::EmitStartOfAsmFil
>     AMDGPU::IsaVersion ISA = AMDGPU::getIsaVersion(STI->getFeatureBits());
>     TS->EmitDirectiveHSACodeObjectISA(ISA.Major, ISA.Minor, ISA.Stepping,
>                                       "AMD", "AMDGPU");
> +  emitStartOfRuntimeMetadata(M);
>   }
>   
>   void AMDGPUAsmPrinter::EmitFunctionBodyStart() { @@ -244,6 +247,8 @@ 
> bool AMDGPUAsmPrinter::runOnMachineFunct
>       }
>     }
>   
> +  emitRuntimeMetadata(*MF.getFunction());
> +
>     return false;
>   }
>   
> @@ -740,3 +745,227 @@ bool AMDGPUAsmPrinter::PrintAsmOperand(c
>                      *TM.getSubtargetImpl(*MF->getFunction())->getRegisterInfo());
>     return false;
>   }
> +
> +// Emit a key and an integer value for runtime metadata.
> +static void emitRuntimeMDIntValue(std::unique_ptr<MCStreamer> &Streamer,
> +                                  RuntimeMD::Key K, uint64_t V,
> +                                  unsigned Size) {
> +  Streamer->EmitIntValue(K, 1);
> +  Streamer->EmitIntValue(V, Size);
> +}
> +
> +// Emit a key and a string value for runtime metadata.
> +static void emitRuntimeMDStringValue(std::unique_ptr<MCStreamer> &Streamer,
> +                                     RuntimeMD::Key K, StringRef S) {
> +  Streamer->EmitIntValue(K, 1);
> +  Streamer->EmitIntValue(S.size(), 4);
> +  Streamer->EmitBytes(S);
> +}
> +
> +// Emit a key and three integer values for runtime metadata.
> +// The three integer values are obtained from MDNode \p Node; static 
> +void emitRuntimeMDThreeIntValues(std::unique_ptr<MCStreamer> &Streamer,
> +                                        RuntimeMD::Key K, MDNode *Node,
> +                                        unsigned Size) {
> +  Streamer->EmitIntValue(K, 1);
> +  Streamer->EmitIntValue(mdconst::extract<ConstantInt>(
> +    Node->getOperand(0))->getZExtValue(), Size);
> +  Streamer->EmitIntValue(mdconst::extract<ConstantInt>(
> +    Node->getOperand(1))->getZExtValue(), Size);
> +  Streamer->EmitIntValue(mdconst::extract<ConstantInt>(
> +    Node->getOperand(2))->getZExtValue(), Size); }
> +
> +void AMDGPUAsmPrinter::emitStartOfRuntimeMetadata(const Module &M) {
> +  OutStreamer->SwitchSection(getObjFileLowering().getContext()
> +    .getELFSection(RuntimeMD::SectionName, ELF::SHT_PROGBITS, 0));
> +
> +  emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyMDVersion,
> +                        RuntimeMD::MDVersion << 8 | 
> +RuntimeMD::MDRevision, 2);
> +  if (auto MD = M.getNamedMetadata("opencl.ocl.version")) {
> +    emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyLanguage,
> +                          RuntimeMD::OpenCL_C, 1);
> +    auto Node = MD->getOperand(0);
> +    unsigned short Major = mdconst::extract<ConstantInt>(Node->getOperand(0))
> +                             ->getZExtValue();
> +    unsigned short Minor = mdconst::extract<ConstantInt>(Node->getOperand(1))
> +                             ->getZExtValue();
> +    emitRuntimeMDIntValue(OutStreamer, RuntimeMD::KeyLanguageVersion,
> +                          Major * 100 + Minor * 10, 2);
> +  }
> +}
> +
> +static std::string getOCLTypeName(Type *Ty, bool isSigned) {
> +  if (VectorType* VecTy = dyn_cast<VectorType>(Ty)) {
> +    Type* EleTy = VecTy->getElementType();
> +    unsigned Size = VecTy->getVectorNumElements();
> +    return (Twine(getOCLTypeName(EleTy, isSigned)) + 
> +Twine(Size)).str();
> +  }
> +  switch (Ty->getTypeID()) {
> +  case Type::HalfTyID:   return "half";
> +  case Type::FloatTyID:  return "float";
> +  case Type::DoubleTyID: return "double";
> +  case Type::IntegerTyID: {
> +    if (!isSigned)
> +      return (Twine('u') + Twine(getOCLTypeName(Ty, true))).str();
> +    auto IntTy = cast<IntegerType>(Ty);
> +    auto BW = IntTy->getIntegerBitWidth();
> +    switch (BW) {
> +    case 8:
> +      return "char";
> +    case 16:
> +      return "short";
> +    case 32:
> +      return "int";
> +    case 64:
> +      return "long";
> +    default:
> +      return (Twine('i') + Twine(BW)).str();
> +    }
> +  }
> +  default:
> +    llvm_unreachable("invalid type");
> +  }
> +}
There are missing tests for some of these still:
http://llvm.org/reports/coverage/lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp.gcov.html

half, float, double, char, short, long, and other bitwidth aren't hit.

We should also be able to switch over every type ID and handle them, so the unreachable should be a warning unless it is after the switch. Array types at least are not handled so need a test

-Matt



More information about the llvm-commits mailing list