1
+ /* ===================== begin_copyright_notice ==================================
2
+
3
+ Copyright (c) 2017 Intel Corporation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a
6
+ copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included
14
+ in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+
25
+ ======================= end_copyright_notice ==================================*/
26
+
27
+ #include " Compiler/IGCPassSupport.h"
28
+ #include " common/LLVMWarningsPush.hpp"
29
+ #include " llvm/IR/InstIterator.h"
30
+ #include " common/LLVMWarningsPop.hpp"
31
+ #include " GenISAIntrinsics/GenIntrinsicInst.h"
32
+ #include " Compiler/CodeGenPublicEnums.h"
33
+ #include " Compiler/CISACodeGen/helper.h"
34
+
35
+ #include < llvm/IR/PassManager.h>
36
+
37
+ using namespace IGC ;
38
+ using namespace llvm ;
39
+
40
+ class RemoveNonPositionOutput : public llvm ::FunctionPass
41
+ {
42
+ public:
43
+ static char ID;
44
+
45
+ RemoveNonPositionOutput ();
46
+
47
+ ~RemoveNonPositionOutput () {}
48
+
49
+ virtual void getAnalysisUsage (llvm::AnalysisUsage &AU) const override
50
+ {
51
+ AU.setPreservesCFG ();
52
+ }
53
+
54
+ virtual bool runOnFunction (llvm::Function &F) override ;
55
+
56
+ virtual llvm::StringRef getPassName () const override
57
+ {
58
+ return " remove non-position output in vertex shader" ;
59
+ }
60
+ };
61
+
62
+ llvm::FunctionPass* createRemoveNonPositionOutputPass ()
63
+ {
64
+ return new RemoveNonPositionOutput ();
65
+ }
66
+
67
+ // Register pass to igc-opt
68
+ #define PASS_FLAG_POSH " igc-remove-nonposition-output"
69
+ #define PASS_DESCRIPTION_POSH " Custom Pass for Position-Only Shader"
70
+ #define PASS_CFG_ONLY_POSH false
71
+ #define PASS_ANALYSIS_POSH false
72
+ IGC_INITIALIZE_PASS_BEGIN (RemoveNonPositionOutput, PASS_FLAG_POSH, PASS_DESCRIPTION_POSH, PASS_CFG_ONLY_POSH, PASS_ANALYSIS_POSH)
73
+ IGC_INITIALIZE_PASS_END(RemoveNonPositionOutput, PASS_FLAG_POSH, PASS_DESCRIPTION_POSH, PASS_CFG_ONLY_POSH, PASS_ANALYSIS_POSH)
74
+
75
+ char RemoveNonPositionOutput::ID = 0;
76
+
77
+ RemoveNonPositionOutput::RemoveNonPositionOutput () : FunctionPass(ID)
78
+ {
79
+ initializeRemoveNonPositionOutputPass (*PassRegistry::getPassRegistry ());
80
+ }
81
+
82
+ bool RemoveNonPositionOutput::runOnFunction (Function &F)
83
+ {
84
+ // Initialize the worklist to all of the instructions ready to process...
85
+ SmallVector<Instruction*, 10 > instructionToRemove;
86
+ for (inst_iterator II = inst_begin (F), E = inst_end (F); II != E; ++II)
87
+ {
88
+ if (GenIntrinsicInst *inst = dyn_cast<GenIntrinsicInst>(&*II))
89
+ {
90
+ if (inst->getIntrinsicID () == GenISAIntrinsic::GenISA_OUTPUT)
91
+ {
92
+ const ShaderOutputType usage = static_cast <ShaderOutputType>(
93
+ llvm::cast<llvm::ConstantInt>(inst->getOperand (4 ))->getZExtValue ());
94
+ if (usage != SHADER_OUTPUT_TYPE_POSITION &&
95
+ usage != SHADER_OUTPUT_TYPE_POINTWIDTH &&
96
+ usage != SHADER_OUTPUT_TYPE_VIEWPORT_ARRAY_INDEX &&
97
+ usage != SHADER_OUTPUT_TYPE_CLIPDISTANCE_LO &&
98
+ usage != SHADER_OUTPUT_TYPE_CLIPDISTANCE_HI)
99
+ {
100
+ instructionToRemove.push_back (inst);
101
+ }
102
+ }
103
+ }
104
+ }
105
+ bool changed = false ;
106
+ uint num = instructionToRemove.size ();
107
+ for (uint i = 0 ; i < num; ++i)
108
+ {
109
+ instructionToRemove[i]->eraseFromParent ();
110
+ changed = true ;
111
+ }
112
+ return changed;
113
+ }
0 commit comments