20#include "llvm/IR/IntrinsicsDirectX.h"
26#define DEBUG_TYPE "dxil-op-lower"
32 switch (
F.getIntrinsicID()) {
33 case Intrinsic::dx_dot2:
34 case Intrinsic::dx_dot3:
35 case Intrinsic::dx_dot4:
43 auto *VecArg = dyn_cast<FixedVectorType>(Arg->
getType());
44 for (
unsigned I = 0;
I < VecArg->getNumElements(); ++
I) {
47 ExtractedElements.
push_back(ExtractedElement);
49 return ExtractedElements;
58 [[maybe_unused]]
auto *VecArg0 = dyn_cast<FixedVectorType>(Arg0->
getType());
61 for (
unsigned I = 1;
I < NumOperands; ++
I) {
63 [[maybe_unused]]
auto *VecArg = dyn_cast<FixedVectorType>(Arg->
getType());
65 assert(VecArg0->getElementType() == VecArg->getElementType());
66 assert(VecArg0->getNumElements() == VecArg->getNumElements());
68 NewOperands.
append(NextOperandList.begin(), NextOperandList.end());
79 OpLowerer(
Module &M) :
M(
M), OpBuilder(
M) {}
84 CallInst *CI = dyn_cast<CallInst>(U);
88 if (
Error E = ReplaceCall(CI)) {
89 std::string Message(
toString(std::move(E)));
92 M.getContext().diagnose(Diag);
104 OpBuilder.
getIRB().SetInsertPoint(CI);
105 if (IsVectorArgExpansion) {
122 bool lowerIntrinsics() {
123 bool Updated =
false;
126 if (!
F.isDeclaration())
132#define DXIL_OP_INTRINSIC(OpCode, Intrin) \
134 replaceFunctionWithOp(F, OpCode); \
136#include "DXILOperation.inc"
146 if (OpLowerer(M).lowerIntrinsics())
152class DXILOpLoweringLegacy :
public ModulePass {
154 bool runOnModule(
Module &M)
override {
155 return OpLowerer(M).lowerIntrinsics();
157 StringRef getPassName()
const override {
return "DXIL Op Lowering"; }
166char DXILOpLoweringLegacy::ID = 0;
175 return new DXILOpLoweringLegacy();
static bool isVectorArgExpansion(Function &F)
static SmallVector< Value * > argVectorFlatten(CallInst *Orig, IRBuilder<> &Builder)
static SmallVector< Value * > populateOperands(Value *Arg, IRBuilder<> &Builder)
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
A container for analyses that lazily runs them and caches their results.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
This class represents a function call, abstracting a target machine's calling convention.
This class represents an Operation in the Expression.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)
Diagnostic information for unsupported feature in backend.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
const Function * getFunction() const
Return the function this instruction belongs to.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
static IntegerType * getInt32Ty(LLVMContext &C)
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVMContext & getContext() const
All values hold a context through their type.
Expected< CallInst * > tryCreateOp(dxil::OpCode Op, ArrayRef< Value * > Args, Type *RetTy=nullptr)
Try to create a call instruction for the given DXIL op.
An efficient, type-erasing, non-owning reference to a callable.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
std::optional< const char * > toString(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract a string value from it.
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
ModulePass * createDXILOpLoweringLegacyPass()
Pass to lowering LLVM intrinsic call to DXIL op function call.