Skip to content

Commit 8e2798f

Browse files
sys-igcigcbot
authored andcommitted
[Autobackout][FunctionalRegression]Revert of change: d41f53b: Adding parameter attributes to some IGC intrinsics
This change is to retain information about pointee types for particular arguments in some IGC intrinsics.
1 parent fb6814d commit 8e2798f

File tree

9 files changed

+34
-158
lines changed

9 files changed

+34
-158
lines changed

IGC/GenISAIntrinsics/GenIntrinsicFunctions.cpp

Lines changed: 16 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,23 @@ class IntrinsicFunctionImp : public llvm::Function
101101
return false;
102102
}
103103

104-
static IntrinsicFunctionImp<id>* Get(llvm::Module& module, const llvm::ArrayRef<llvm::Type*>& overloadedTypes, const llvm::ArrayRef<llvm::Type*>& overloadedPointeeTys)
104+
static IntrinsicFunctionImp<id>* Get(llvm::Module& module, const llvm::ArrayRef<llvm::Type*>& overloadedTypes)
105105
{
106-
return llvm::cast<IntrinsicFunctionImp<id>>(GetDeclaration(module, overloadedTypes, overloadedPointeeTys));
106+
return llvm::cast<IntrinsicFunctionImp<id>>(GetDeclaration(module, overloadedTypes));
107107
}
108108

109-
static llvm::Function* GetDeclaration(llvm::Module& module, const llvm::ArrayRef<llvm::Type*>& overloadedTypes, const llvm::ArrayRef<llvm::Type*>& overloadedPointeeTys)
109+
static llvm::Function* GetDeclaration(llvm::Module& module, const llvm::ArrayRef<llvm::Type*>& overloadedTypes)
110110
{
111-
return GetOrInsert(module, overloadedTypes, overloadedPointeeTys);
111+
return GetOrInsert(module, overloadedTypes);
112112
}
113113

114-
static std::string GetName(const llvm::ArrayRef<llvm::Type*>& overloadedTypes, const llvm::ArrayRef<llvm::Type*>& overloadedPointeeTys)
114+
static std::string GetName(const llvm::ArrayRef<llvm::Type*>& overloadedTypes)
115115
{
116116
std::string result = IntrinsicDefinitionT::scFunctionRootName;
117117
for (unsigned i = 0; i < overloadedTypes.size(); ++i)
118118
{
119119
result += "." + getMangledTypeStr(overloadedTypes[i]);
120120
}
121-
for (unsigned i = 0; i < overloadedPointeeTys.size(); ++i)
122-
{
123-
result += "." + getMangledTypeStr(overloadedPointeeTys[i]);
124-
}
125121
return result;
126122
}
127123

@@ -143,12 +139,12 @@ class IntrinsicFunctionImp : public llvm::Function
143139

144140
private:
145141

146-
static llvm::Function* GetOrInsert(llvm::Module& module, const llvm::ArrayRef<llvm::Type*>& overloadedTypes, const llvm::ArrayRef<llvm::Type*>& overloadedPointeeTys)
142+
static llvm::Function* GetOrInsert(llvm::Module& module, const llvm::ArrayRef<llvm::Type*>& overloadedTypes)
147143
{
148144
llvm::LLVMContext& ctx = module.getContext();
149-
std::string funcName = GetName(overloadedTypes, overloadedPointeeTys);
145+
std::string funcName = GetName(overloadedTypes);
150146
llvm::FunctionType* pFuncType = GetType(ctx, overloadedTypes);
151-
llvm::AttributeList attribs = GetAttributeList(ctx, overloadedPointeeTys);
147+
llvm::AttributeList attribs = GetAttributeList(ctx);
152148
// There can never be multiple globals with the same name of different types,
153149
// because intrinsics must be a specific type.
154150
IGCLLVM::Module& M = static_cast<IGCLLVM::Module&>(module);
@@ -205,7 +201,7 @@ class IntrinsicFunctionImp : public llvm::Function
205201
{
206202
for (uint8_t i = 0; i < numArguments; i++)
207203
{
208-
RetrieveType(i + 1, IntrinsicDefinitionT::scArguments[i].m_Type);
204+
RetrieveType(i + 1, IntrinsicDefinitionT::scArgumentTypes[i]);
209205
}
210206
}
211207
// IGC_ASSERT(overloadedTypeIndex == overloadedTypes.size());
@@ -222,60 +218,16 @@ class IntrinsicFunctionImp : public llvm::Function
222218
return llvm::FunctionType::get(resultTy, argTys, false);
223219
}
224220

225-
static llvm::AttributeList GetAttributeList(llvm::LLVMContext& ctx, const llvm::ArrayRef<llvm::Type*>& overloadedPointeeTys)
221+
static llvm::AttributeList GetAttributeList(llvm::LLVMContext& ctx)
226222
{
227223
// 1. Instantiate regular attributes for the given intrinsic
228224
constexpr auto& attributeKinds = IntrinsicDefinitionT::scAttributeKinds;
229225
auto mainAttrList = llvm::AttributeList::get(
230226
ctx, llvm::AttributeList::FunctionIndex, attributeKinds);
231227
// 2. Gather the memory attribute(s) in a separate routine
232228
auto memoryAB = IntrinsicDefinitionT::scMemoryEffects.getAsAttrBuilder(ctx);
233-
mainAttrList = mainAttrList.addFnAttributes(ctx, memoryAB);
234-
// 3. Gather parameter attributes
235-
uint8_t overloadedTypeIndex = 0;
236-
auto RetrieveParamAttr = [&overloadedTypeIndex, &ctx, &overloadedPointeeTys, &mainAttrList](uint8_t index, const ArgumentDescription& arg)
237-
{
238-
if (arg.m_AttrKind == llvm::Attribute::None)
239-
{
240-
return;
241-
}
242-
IGC_ASSERT_MESSAGE(
243-
arg.m_AttrKind == llvm::Attribute::ByRef ||
244-
arg.m_AttrKind == llvm::Attribute::ByVal ||
245-
arg.m_AttrKind == llvm::Attribute::StructRet,
246-
"Used an invalid(?) parameter attribute kind");
247-
switch (arg.m_Type.m_ID)
248-
{
249-
case TypeID::Pointer:
250-
{
251-
llvm::Type* pointeeType = nullptr;
252-
if (overloadedTypeIndex < overloadedPointeeTys.size() && arg.m_Type.IsOverloadable())
253-
{
254-
pointeeType = overloadedPointeeTys[overloadedTypeIndex++];
255-
}
256-
else
257-
{
258-
pointeeType = arg.m_Type.m_Pointer.m_Type.GetType(ctx);
259-
}
260-
mainAttrList = mainAttrList.addParamAttribute(ctx, { index }, llvm::Attribute::get(ctx, arg.m_AttrKind, pointeeType));
261-
break;
262-
}
263-
default:
264-
IGC_ASSERT_MESSAGE(0, "A parameter attribute used for non-pointer function argument.");
265-
break;
266-
}
267-
};
268-
269-
constexpr uint8_t numArguments = static_cast<uint8_t>(Argument::Count);
270-
if constexpr (numArguments > 0)
271-
{
272-
for (uint8_t i = 0; i < numArguments; i++)
273-
{
274-
RetrieveParamAttr(i, IntrinsicDefinitionT::scArguments[i]);
275-
}
276-
}
277-
278-
return mainAttrList;
229+
// Return a merged collection
230+
return mainAttrList.addFnAttributes(ctx, memoryAB);
279231
}
280232
};
281233

@@ -293,14 +245,14 @@ static constexpr auto GetDeclarationFuncArray()
293245
return GetDeclarationFuncArrayImp(seq);
294246
}
295247

296-
llvm::Function* GetDeclaration(llvm::Module* pModule, llvm::GenISAIntrinsic::ID id, llvm::ArrayRef<llvm::Type*> overloadedTys, llvm::ArrayRef<llvm::Type*> overloadedPointeeTys)
248+
llvm::Function* GetDeclaration(llvm::Module* pModule, llvm::GenISAIntrinsic::ID id, llvm::ArrayRef<llvm::Type*> overloadedTys)
297249
{
298250
constexpr auto funcArray = GetDeclarationFuncArray();
299251
llvm::Function* pResult = nullptr;
300252
uint32_t index = static_cast<uint32_t>(id) - scBeginIntrinsicIndex;
301253
if (index < funcArray.size())
302254
{
303-
pResult = funcArray[index](*pModule, overloadedTys, overloadedPointeeTys);
255+
pResult = funcArray[index](*pModule, overloadedTys);
304256
}
305257
return pResult;
306258
}
@@ -319,14 +271,14 @@ static constexpr auto GetNameFuncArray()
319271
return GetNameFuncArrayImp(seq);
320272
}
321273

322-
std::string GetName(llvm::GenISAIntrinsic::ID id, llvm::ArrayRef<llvm::Type*> overloadedTys, llvm::ArrayRef<llvm::Type*> overloadedPointeeTys)
274+
std::string GetName(llvm::GenISAIntrinsic::ID id, llvm::ArrayRef<llvm::Type*> overloadedTys)
323275
{
324276
constexpr auto funcArray = GetNameFuncArray();
325277
std::string result;
326278
uint32_t index = static_cast<uint32_t>(id) - scBeginIntrinsicIndex;
327279
if (index < funcArray.size())
328280
{
329-
result = funcArray[index](overloadedTys, overloadedPointeeTys);
281+
result = funcArray[index](overloadedTys);
330282
}
331283
return result;
332284
}

IGC/GenISAIntrinsics/GenIntrinsicFunctions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ std::string getMangledTypeStr(llvm::Type* Ty);
2828

2929
const char* GetIntrinsicPrefixName();
3030

31-
std::string GetName(llvm::GenISAIntrinsic::ID id, llvm::ArrayRef<llvm::Type*> OverloadedTys, llvm::ArrayRef<llvm::Type*> overloadedPointeeTys);
31+
std::string GetName(llvm::GenISAIntrinsic::ID id, llvm::ArrayRef<llvm::Type*> OverloadedTys);
3232

3333
llvm::GenISAIntrinsic::IntrinsicComments GetIntrinsicComments(llvm::GenISAIntrinsic::ID id);
3434

35-
llvm::Function* GetDeclaration(llvm::Module* pModule, llvm::GenISAIntrinsic::ID id, llvm::ArrayRef<llvm::Type*> overloadedTys, llvm::ArrayRef<llvm::Type*> overloadedPointeeTys);
35+
llvm::Function* GetDeclaration(llvm::Module* pModule, llvm::GenISAIntrinsic::ID id, llvm::ArrayRef<llvm::Type*> overloadedTys);
3636

3737
} // namespace IGC

IGC/GenISAIntrinsics/GenIntrinsics.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,19 @@ namespace llvm
7575
namespace GenISAIntrinsic
7676
{
7777

78-
std::string getName(ID id, ArrayRef<Type*> OverloadedTys /*= None*/, ArrayRef<Type*> OverloadedPointeeTys /*= None*/)
78+
std::string getName(ID id, ArrayRef<Type*> OverloadedTys /*= None*/)
7979
{
80-
return IGC::GetName(id, OverloadedTys, OverloadedPointeeTys);
80+
return IGC::GetName(id, OverloadedTys);
8181
}
8282

8383
IntrinsicComments getIntrinsicComments(ID id)
8484
{
8585
return IGC::GetIntrinsicComments(id);
8686
}
8787

88-
Function* getDeclaration(Module* M, ID id, ArrayRef<Type*> OverloadedTys /*= None*/, ArrayRef<Type*> OverloadedPointeeTys /*= None*/)
88+
Function* getDeclaration(Module* M, ID id, ArrayRef<Type*> OverloadedTys /*= None*/)
8989
{
90-
return IGC::GetDeclaration(M, id, OverloadedTys, OverloadedPointeeTys);
90+
return IGC::GetDeclaration(M, id, OverloadedTys);
9191
}
9292

9393
ID getIntrinsicID(const Function* F, bool useContextWrapper /*= true*/)

IGC/GenISAIntrinsics/GenIntrinsics.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace GenISAIntrinsic
2525

2626
/// Intrinsic::getName(ID) - Return the LLVM name for an intrinsic, such as
2727
/// "llvm.ppc.altivec.lvx".
28-
std::string getName(ID id, ArrayRef<Type*> Tys = {}, ArrayRef<Type*> OverloadedPointeeTys = {});
28+
std::string getName(ID id, ArrayRef<Type*> Tys = {});
2929

3030

3131
struct IntrinsicComments
@@ -53,9 +53,9 @@ IntrinsicComments getIntrinsicComments(ID id);
5353
/// Type Ts[2]{int2, int2}: to resolve to the first instance.
5454
/// Type Ts[2]{int4, int4}: to resolve to the second.
5555
#if defined(ANDROID) || defined(__linux__)
56-
__attribute__ ((visibility ("default"))) Function *getDeclaration(Module *M, ID id, ArrayRef<Type*> OverloadedTys = {}, ArrayRef<Type*> OverloadedPointeeTys = {});
56+
__attribute__ ((visibility ("default"))) Function *getDeclaration(Module *M, ID id, ArrayRef<Type*> OverloadedTys = {});
5757
#else
58-
Function *getDeclaration(Module *M, ID id, ArrayRef<Type*> OverloadedTys = {}, ArrayRef<Type*> OverloadedPointeeTys = {});
58+
Function *getDeclaration(Module *M, ID id, ArrayRef<Type*> OverloadedTys = {});
5959
#endif
6060

6161
//Override of isIntrinsic method defined in Function.h

IGC/GenISAIntrinsics/LlvmTypesMapping.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ SPDX-License-Identifier: MIT
1111

1212
#include "common/LLVMWarningsPush.hpp"
1313
#include "llvm/ADT/ArrayRef.h"
14-
#include "llvm/IR/Attributes.h"
1514
#include "common/LLVMWarningsPop.hpp"
1615

1716
namespace llvm
@@ -410,18 +409,6 @@ struct TypeDescription
410409
const TypeID m_ID;
411410
};
412411

413-
struct ArgumentDescription
414-
{
415-
constexpr ArgumentDescription(const TypeDescription& type, llvm::Attribute::AttrKind attrKind = llvm::Attribute::None) :
416-
m_Type(type),
417-
m_AttrKind(attrKind)
418-
{
419-
}
420-
421-
const TypeDescription& m_Type;
422-
llvm::Attribute::AttrKind m_AttrKind;
423-
};
424-
425412
constexpr bool IsOverloadable(const TypeDescription& type)
426413
{
427414
return type.IsOverloadable();

IGC/GenISAIntrinsics/generator/Intrinsic_definition_objects.py

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -151,36 +151,6 @@ def AttributeID_constructor(loader, node):
151151

152152
yaml.SafeLoader.add_constructor(u'!AttributeID', AttributeID_constructor)
153153

154-
class ParamAttributeID(Enum):
155-
ByRef = 0
156-
ByVal = 1
157-
StructRet = 2
158-
159-
def __str__(self):
160-
return self.name
161-
162-
def __repr__(self):
163-
return '%s("%s")' % (self.__class__.__name__, self)
164-
165-
@classmethod
166-
def from_str(cls, value : str):
167-
for key, val in cls.__members__.items():
168-
if key == value:
169-
return val
170-
else:
171-
raise ValueError("{value} is not present in {cls.__name__}")
172-
173-
def ParamAttributeID_representer(dumper, data):
174-
return dumper.represent_scalar(u'!ParamAttributeID', u'%s' % str(data), style='"')
175-
176-
yaml.add_representer(ParamAttributeID, ParamAttributeID_representer)
177-
178-
def ParamAttributeID_constructor(loader, node):
179-
value = loader.construct_scalar(node)
180-
return ParamAttributeID.from_str(value)
181-
182-
yaml.SafeLoader.add_constructor(u'!ParamAttributeID', ParamAttributeID_constructor)
183-
184154
class MemoryLocation(Enum):
185155
ArgMem = 0
186156
InaccessibleMem = 1
@@ -490,36 +460,27 @@ def from_yaml(cls, loader, node):
490460
arg_dict = loader.construct_mapping(node, deep=True)
491461
return cls(**arg_dict)
492462

493-
def __init__(self, name : str, type_definition : TypeDefinition, comment : str, param_attr : ParamAttributeID = None):
463+
def __init__(self, name : str, type_definition : TypeDefinition, comment : str):
494464
self.name = name
495465
self.type_definition = type_definition
496466
self.comment = QuotedString(comment)
497-
if param_attr:
498-
self.param_attr = param_attr
499467

500468
def __repr__(self):
501-
repr_str = "name=%r" % (self.name)
502-
repr_str += ", type_definition=%r" % (self.type_definition)
503-
repr_str += ", comment=%r" % (self.comment)
504-
if hasattr(self, 'param_attr'):
505-
repr_str += ", param_attr=%r" % str(self.param_attr)
506-
return "%s(%r)" % (
507-
self.__class__.__name__, repr_str)
469+
return "%s(name=%r, type_definition=%r, comment=%r)" % (
470+
self.__class__.__name__, self.name, self.type_definition, self.comment)
508471

509472
def to_dict(self):
510473
res = {
511474
"name": self.name,
512475
"type_definition": self.type_definition.to_dict(),
513476
"comment": self.comment
514477
}
515-
if hasattr(self, 'param_attr'):
516-
res["param_attr"] = str(self.param_attr)
517478
return res
518479

519480
@staticmethod
520481
def from_dict(json_dct : dict):
521482
type_definition = TypeDefinition.from_dict(json_dct['type_definition'])
522-
return ArgumentDefinition(json_dct['name'], type_definition, json_dct['comment'], json_dct['param_attr'])
483+
return ArgumentDefinition(json_dct['name'], type_definition, json_dct['comment'])
523484

524485
class MemoryRestriction(SafeYAMLObject):
525486

IGC/GenISAIntrinsics/generator/Intrinsic_generator.py

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,10 @@ def get_type_definition(type_def):
122122
output = "AnyTypeHolderT<>"
123123
return output
124124

125-
@classmethod
126-
def get_argument_entry(cls, arg, is_last):
127-
output = cls.get_type_definition(arg.type_definition)
125+
@staticmethod
126+
def get_argument_type_entry(type_def, is_last):
127+
output = IntrinsicFormatter.get_type_definition(type_def)
128128
output = "{}::scType".format(output)
129-
if hasattr(arg, 'param_attr'):
130-
# a param attribute is supported only for pointer function arguments to preserve their pointee types
131-
if arg.type_definition.ID != TypeID.Pointer:
132-
sys.exit(1)
133-
output += ", {}".format(cls.get_attribute_entry(arg.param_attr, is_last=True))
134-
output = "ArgumentDescription({})".format(output)
135129
if not is_last:
136130
output = "{},".format(output)
137131
return output
@@ -157,13 +151,6 @@ def get_attribute_entry(attribute, is_last):
157151
output = "{},".format(output)
158152
return output
159153

160-
@staticmethod
161-
def get_param_attribute_entry(param_attribute, is_last):
162-
output = 'std::make_pair(llvm::Attribute::{}, {})'.format(param_attribute.name, param_attribute.index)
163-
if not is_last:
164-
output = "{},".format(output)
165-
return output
166-
167154
@staticmethod
168155
def get_memory_effects_instance(memory_restriction : MemoryRestriction):
169156
modref_arg = "IGCLLVM::ModRefInfo::{}".format(memory_restriction.memory_access)

IGC/GenISAIntrinsics/generator/input/Intrinsic_definitions.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10800,7 +10800,6 @@ intrinsics:
1080010800
name: Arg2
1080110801
type_definition: *p_any_
1080210802
comment: "User defined intersection attributes struct"
10803-
param_attr: !ParamAttributeID "ByRef"
1080410803
attributes:
1080510804
- !AttributeID "NoUnwind"
1080610805
- !<IntrinsicDefinition>

IGC/GenISAIntrinsics/generator/templates/GenIntrinsicDefinition.h.mako

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ SPDX-License-Identifier: MIT
1818

1919
#include <string_view>
2020
#include <array>
21-
#include <utility>
2221

2322
namespace IGC
2423
{
@@ -47,10 +46,9 @@ public:
4746
};
4847
% if hasattr(el, 'arguments') and el.arguments and len(el.arguments) > 0:
4948

50-
## All comments are stored in another member due to preserve `constexpr`
51-
static constexpr std::array<ArgumentDescription, static_cast<uint32_t>(Argument::Count)> scArguments{
49+
static constexpr std::array<TypeDescription, static_cast<uint32_t>(Argument::Count)> scArgumentTypes{
5250
% for arg in el.arguments:
53-
${IntrinsicFormatter.get_argument_entry(arg, loop.last)}
51+
${IntrinsicFormatter.get_argument_type_entry(arg.type_definition, loop.last)}
5452
% endfor
5553
};
5654
% endif
@@ -68,16 +66,8 @@ public:
6866
% endfor
6967
};
7068
% endif
71-
% if hasattr(el, 'param_attributes') and el.param_attributes and len(el.param_attributes) > 0:
7269

73-
static constexpr std::array scParamAttributeKinds = {
74-
% for attr in el.param_attributes:
75-
${IntrinsicFormatter.get_param_attributes_entry(attr, loop.last)}
76-
% endfor
77-
};
78-
% endif
7970
% if hasattr(el, 'memory_effects'):
80-
8171
static constexpr auto scMemoryEffects =
8272
${IntrinsicFormatter.get_memory_effects_from_restrictions(el.memory_effects)};
8373
% endif

0 commit comments

Comments
 (0)