swr/rast: Use metadata to communicate between passes
authorAlok Hota <alok.hota@intel.com>
Fri, 25 May 2018 15:19:45 +0000 (10:19 -0500)
committerTim Rowley <timothy.o.rowley@intel.com>
Fri, 25 May 2018 15:56:37 +0000 (10:56 -0500)
Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
src/gallium/drivers/swr/rasterizer/jitter/builder.h

index 6ca128d38f1f77935e45988e6185ff0219ad8812..08a3a6e473424004d7a60589feb8947afb272ee1 100644 (file)
@@ -124,6 +124,34 @@ namespace SwrJit
         bool SetTexelMaskEvaluate(Instruction* inst);
         bool IsTexelMaskEvaluate(Instruction* inst);
         Type* GetVectorType(Type* pType);
+        void SetMetadata(StringRef s, uint32_t val)
+        {
+            llvm::NamedMDNode *metaData = mpJitMgr->mpCurrentModule->getOrInsertNamedMetadata(s);
+            Constant* cval = mpIRBuilder->getInt32(val);
+            llvm::MDNode *mdNode = llvm::MDNode::get(mpJitMgr->mpCurrentModule->getContext(), llvm::ConstantAsMetadata::get(cval));
+            if (metaData->getNumOperands())
+            {
+                metaData->setOperand(0, mdNode);
+            }
+            else
+            {
+                metaData->addOperand(mdNode);
+            }
+        }
+        uint32_t GetMetadata(StringRef s)
+        {
+            NamedMDNode* metaData = mpJitMgr->mpCurrentModule->getNamedMetadata(s);
+            if (metaData)
+            {
+                MDNode* mdNode = metaData->getOperand(0);
+                Metadata* val = mdNode->getOperand(0);
+                return mdconst::dyn_extract<ConstantInt>(val)->getZExtValue();
+            }
+            else
+            {
+                return 0;
+            }
+        }
 
 #include "gen_builder.hpp"
 #include "gen_builder_meta.hpp"