41 #define DEBUG_TYPE "amdgpu-propagate-attributes" 51 class AMDGPUPropagateAttributes {
53 AMDGPU::FeatureWavefrontSize16,
54 AMDGPU::FeatureWavefrontSize32,
55 AMDGPU::FeatureWavefrontSize64
61 FeatureMask(FeatureMask), OrigF(OrigF), NewF(NewF) {}
91 std::string getFeatureString(
const FeatureBitset &Features)
const;
97 AMDGPUPropagateAttributes(
const TargetMachine *TM,
bool AllowClone) :
98 TM(TM), AllowClone(AllowClone) {}
111 class AMDGPUPropagateAttributesEarly :
public FunctionPass {
117 AMDGPUPropagateAttributesEarly(
const TargetMachine *TM =
nullptr) :
128 class AMDGPUPropagateAttributesLate :
public ModulePass {
134 AMDGPUPropagateAttributesLate(
const TargetMachine *TM =
nullptr) :
140 bool runOnModule(
Module &M)
override;
149 "amdgpu-propagate-attributes-early",
150 "Early propagate attributes from kernels to functions",
153 "amdgpu-propagate-attributes-late",
154 "Late propagate attributes from kernels to functions",
161 for (Clone &
C : Clones)
162 if (
C.OrigF == OrigF && FeaturesNeeded ==
C.FeatureMask)
168 bool AMDGPUPropagateAttributes::process(
Module &M) {
176 bool AMDGPUPropagateAttributes::process(
Function &
F) {
181 bool AMDGPUPropagateAttributes::process() {
182 bool Changed =
false;
191 Roots.insert(NewRoots.
begin(), NewRoots.
end());
199 TM->getSubtargetImpl(F)->getFeatureBits();
212 if (!Roots.count(Caller))
216 TM->getSubtargetImpl(*Caller)->getFeatureBits() & TargetFeatures;
218 if (CallerBits == (CalleeBits & TargetFeatures)) {
223 Function *NewF = findFunction(CallerBits, &F);
232 setFeatures(F, NewFeatures);
238 NewF = cloneWithFeatures(F, NewFeatures);
239 Clones.push_back(Clone(CallerBits, &F, NewF));
243 ToReplace.
push_back(std::make_pair(CI, NewF));
249 while (!ToReplace.
empty()) {
251 R.first->setCalledFunction(R.second);
254 }
while (!NewRoots.
empty());
265 AMDGPUPropagateAttributes::cloneWithFeatures(
Function &F,
271 setFeatures(*NewF, NewFeatures);
276 std::string NewName = NewF->
getName();
288 void AMDGPUPropagateAttributes::setFeatures(
Function &F,
290 std::string NewFeatureStr = getFeatureString(NewFeatures);
293 << getFeatureString(NewFeatures & TargetFeatures)
294 <<
" on " << F.
getName() <<
'\n');
297 F.
addFnAttr(
"target-features", NewFeatureStr);
301 AMDGPUPropagateAttributes::getFeatureString(
const FeatureBitset &Features)
const 305 if (Features[KV.Value])
306 Ret += (
StringRef(
"+") + KV.Key +
",").str();
307 else if (TargetFeatures[KV.Value])
308 Ret += (
StringRef(
"-") + KV.Key +
",").str();
318 return AMDGPUPropagateAttributes(
TM,
false).process(F);
321 bool AMDGPUPropagateAttributesLate::runOnModule(
Module &M) {
325 return AMDGPUPropagateAttributes(
TM,
true).process(M);
330 return new AMDGPUPropagateAttributesEarly(TM);
335 return new AMDGPUPropagateAttributesLate(TM);
void setVisibility(VisibilityTypes V)
FunctionPass * createAMDGPUPropagateAttributesEarlyPass(const TargetMachine *)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
AMDGPU specific subclass of TargetSubtarget.
const SubtargetFeatureKV AMDGPUFeatureKV[AMDGPU::NumSubtargetFeatures-1]
This class represents lattice values for constants.
INITIALIZE_PASS(AMDGPUPropagateAttributesEarly, "amdgpu-propagate-attributes-early", "Early propagate attributes from kernels to functions", false, false) INITIALIZE_PASS(AMDGPUPropagateAttributesLate
A Module instance is used to store all the information related to an LLVM module. ...
Function * getCaller()
Helper to get the caller (the parent function).
void push_back(const T &Elt)
Function * CloneFunction(Function *F, ValueToValueMapTy &VMap, ClonedCodeInfo *CodeInfo=nullptr)
Return a copy of the specified function and add it to that function's module.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
LLVM_NODISCARD bool empty() const
const_iterator begin() const
void setName(const Twine &Name)
Change the name of the value.
Used to provide key value pairs for feature and CPU bit flags.
void takeName(Value *V)
Transfer the name from V to this value.
const_iterator end() const
static bool runOnFunction(Function &F, bool PostInlining)
iterator_range< iterator > functions()
Container class for subtarget features.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
bool isEntryFunctionCC(CallingConv::ID CC)
FunctionPass class - This class is used to implement most global optimizations.
std::pair< NoneType, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
LLVM_NODISCARD T pop_back_val()
void setLinkage(LinkageTypes LT)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
iterator_range< user_iterator > users()
Provides AMDGPU specific target descriptions.
void initializeAMDGPUPropagateAttributesLatePass(PassRegistry &)
LLVM_NODISCARD bool empty() const
StringRef getName() const
Return a constant reference to the value's name.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Rename collisions when linking (static functions).
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
ModulePass * createAMDGPUPropagateAttributesLatePass(const TargetMachine *)
void removeFnAttr(Attribute::AttrKind Kind)
Remove function attributes from this function.
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
void initializeAMDGPUPropagateAttributesEarlyPass(PassRegistry &)
static const Function * getParent(const Value *V)
Primary interface to the complete machine description for the target machine.
void addFnAttr(Attribute::AttrKind Kind)
Add function attributes to this function.
StringRef - Represent a constant reference to a string, i.e.