swr/rast: Code generation cleanup
authorGeorge Kyriazis <george.kyriazis@intel.com>
Wed, 14 Feb 2018 01:22:03 +0000 (19:22 -0600)
committerGeorge Kyriazis <george.kyriazis@intel.com>
Wed, 28 Feb 2018 17:42:37 +0000 (11:42 -0600)
Generate more compact code from gen_llvm.hpp.

Reviewed-By: Bruce Cherniak <bruce.cherniak@intel.com>
src/gallium/drivers/swr/rasterizer/codegen/templates/gen_llvm.hpp

index d61194dae11211ff39c20d7921ddd6723911bc42..190e660ad1cfaccf5630ca91655a7b23acba99b1 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
-* Copyright (C) 2014-2017 Intel Corporation.   All Rights Reserved.
+* Copyright (C) 2014-2018 Intel Corporation.   All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
@@ -39,19 +39,19 @@ namespace SwrJit
 %for type in types:
     INLINE static StructType *Gen_${type['name']}(JitManager* pJitMgr)
     {
+        %if needs_ctx(type):
         LLVMContext& ctx = pJitMgr->mContext;
-       (void) ctx;
 
+        %endif
         StructType* pRetType = pJitMgr->mpCurrentModule->getTypeByName("${type['name']}");
         if (pRetType == nullptr)
         {
-            std::vector<Type*> members;
-            <%
-                (max_type_len, max_name_len) = calc_max_len(type['members'])
-            %>
-            %for member in type['members']:
-            /* ${member['name']} ${pad(len(member['name']), max_name_len)}*/ members.push_back(${ member['type'] });
-            %endfor
+            std::vector<Type*> members =<% (max_type_len, max_name_len) = calc_max_len(type['members']) %>
+            {
+                %for member in type['members']:
+                /* ${member['name']} ${pad(len(member['name']), max_name_len)}*/ ${member['type']},
+                %endfor
+            };
 
             pRetType = StructType::create(members, "${type['name']}", false);
 
@@ -59,13 +59,13 @@ namespace SwrJit
             llvm::DIBuilder builder(*pJitMgr->mpCurrentModule);
             llvm::DIFile* pFile = builder.createFile("${input_file}", "${os.path.normpath(input_dir).replace('\\', '/')}");
 
-            std::vector<std::pair<std::string, uint32_t>> dbgMembers;
-            %for member in type['members']:
-            dbgMembers.push_back(std::make_pair("${member['name']}", ${ member['lineNum'] }));
-            %endfor
-            
+            std::vector<std::pair<std::string, uint32_t>> dbgMembers =
+            {
+                %for member in type['members']:
+                std::make_pair("${member['name']}", ${pad(len(member['name']), max_name_len)}${member['lineNum']}),
+                %endfor
+            };
             pJitMgr->CreateDebugStructType(pRetType, "${type['name']}", pFile, ${type['lineNum']}, dbgMembers);
-
         }
 
         return pRetType;
@@ -80,6 +80,12 @@ namespace SwrJit
 
 <%! # Global function definitions
     import os
+    def needs_ctx(struct_type):
+        for m in struct_type.get('members', []):
+            if '(ctx)' in m.get('type', ''):
+                return True
+        return False
+
     def calc_max_len(fields):
         max_type_len = 0
         max_name_len = 0