-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DXIL][Analysis] Collect Function properties in Metadata Analysis #105728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
04400db
92ffbbb
c067683
ccb97cc
b3a5362
93b26bc
b54693a
804cf7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
#ifndef LLVM_ANALYSIS_DXILMETADATA_H | ||
#define LLVM_ANALYSIS_DXILMETADATA_H | ||
|
||
#include "llvm/IR/Function.h" | ||
#include "llvm/IR/PassManager.h" | ||
#include "llvm/Pass.h" | ||
#include "llvm/Support/VersionTuple.h" | ||
|
@@ -19,12 +20,16 @@ namespace llvm { | |
|
||
namespace dxil { | ||
|
||
struct FunctionProperties { | ||
unsigned NumThreads[3]; | ||
bharadwajy marked this conversation as resolved.
Show resolved
Hide resolved
bharadwajy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
bharadwajy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
struct ModuleMetadataInfo { | ||
VersionTuple DXILVersion{}; | ||
VersionTuple ShaderModelVersion{}; | ||
Triple::EnvironmentType ShaderStage = Triple::UnknownEnvironment; | ||
VersionTuple ValidatorVersion{}; | ||
|
||
std::unordered_map<Function *, FunctionProperties> FunctionPropertyMap{}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we actually need to look up functions in a map for the function properties, or do we just need to be able to iterate through them? It might be nice to wire up the metadata analysis into DXILTranslateMetadata before adding more properties so that we can see how they'll be used. In any case, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Function lookup is employed in an implementation I have as a follow on PR that consumes this information in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to |
||
void print(raw_ostream &OS) const; | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,16 @@ | |
|
||
#include "llvm/Analysis/DXILMetadataAnalysis.h" | ||
#include "llvm/ADT/APInt.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/IR/Constants.h" | ||
#include "llvm/IR/DerivedTypes.h" | ||
#include "llvm/IR/Instructions.h" | ||
#include "llvm/IR/Metadata.h" | ||
#include "llvm/IR/Module.h" | ||
#include "llvm/InitializePasses.h" | ||
#include "llvm/Support/ErrorHandling.h" | ||
#include <memory> | ||
#include <utility> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think |
||
|
||
#define DEBUG_TYPE "dxil-metadata-analysis" | ||
|
||
|
@@ -33,6 +38,37 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) { | |
MMDAI.ValidatorVersion = | ||
VersionTuple(MajorMD->getZExtValue(), MinorMD->getZExtValue()); | ||
} | ||
|
||
if (MMDAI.ShaderStage == Triple::EnvironmentType::Compute) { | ||
// For all HLSL Shader functions | ||
for (auto &F : M.functions()) { | ||
if (!F.hasFnAttribute("hlsl.shader")) | ||
continue; | ||
|
||
// Get numthreads attribute value | ||
StringRef NumThreadsStr = | ||
F.getFnAttribute("hlsl.numthreads").getValueAsString(); | ||
SmallVector<StringRef> NumThreadsVec; | ||
NumThreadsStr.split(NumThreadsVec, ','); | ||
if (NumThreadsVec.size() != 3) { | ||
report_fatal_error(Twine(F.getName()) + | ||
": Invalid numthreads specified", | ||
/* gen_crash_diag */ false); | ||
} | ||
bharadwajy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FunctionProperties EFP; | ||
auto Zip = | ||
llvm::zip(NumThreadsVec, MutableArrayRef<unsigned>(EFP.NumThreads)); | ||
for (auto It : Zip) { | ||
StringRef Str = std::get<0>(It); | ||
APInt V; | ||
assert(!Str.getAsInteger(10, V) && | ||
"Failed to parse numthreads components as integer values"); | ||
unsigned &Num = std::get<1>(It); | ||
Num = V.getLimitedValue(); | ||
} | ||
bharadwajy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
MMDAI.FunctionPropertyMap.emplace(std::make_pair(std::addressof(F), EFP)); | ||
} | ||
} | ||
return MMDAI; | ||
} | ||
|
||
|
@@ -42,6 +78,20 @@ void ModuleMetadataInfo::print(raw_ostream &OS) const { | |
OS << "Shader Stage : " << Triple::getEnvironmentTypeName(ShaderStage) | ||
<< "\n"; | ||
OS << "Validator Version : " << ValidatorVersion.getAsString() << "\n"; | ||
for (auto MapItem : FunctionPropertyMap) { | ||
MapItem.first->getReturnType()->print(OS, false, true); | ||
OS << " " << MapItem.first->getName() << "("; | ||
FunctionType *FT = MapItem.first->getFunctionType(); | ||
for (unsigned I = 0, Sz = FT->getNumParams(); I < Sz; ++I) { | ||
if (I) | ||
OS << ","; | ||
FT->getParamType(I)->print(OS); | ||
} | ||
OS << ")\n"; | ||
bharadwajy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
OS << " NumThreads: " << MapItem.second.NumThreads[0] << "," | ||
<< MapItem.second.NumThreads[1] << "," << MapItem.second.NumThreads[2] | ||
<< "\n"; | ||
} | ||
} | ||
|
||
//===----------------------------------------------------------------------===// | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A forward declaration should be sufficient for
Function