Skip to content

Commit 9432f32

Browse files
committed
remove registration pattern switch to target checking
1 parent 218206d commit 9432f32

File tree

4 files changed

+26
-116
lines changed

4 files changed

+26
-116
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18186,42 +18186,6 @@ Intrinsic::ID getDotProductIntrinsic(QualType QT, int elementCount) {
1818618186
return Intrinsic::dx_udot;
1818718187
}
1818818188

18189-
Value *CodeGenFunction::EmitHLSLMadIntrinsic(const CallExpr *E) {
18190-
Value *M = EmitScalarExpr(E->getArg(0));
18191-
Value *A = EmitScalarExpr(E->getArg(1));
18192-
Value *B = EmitScalarExpr(E->getArg(2));
18193-
if (E->getArg(0)->getType()->hasFloatingRepresentation())
18194-
return Builder.CreateIntrinsic(
18195-
/*ReturnType*/ M->getType(), Intrinsic::fmuladd,
18196-
ArrayRef<Value *>{M, A, B}, nullptr, "hlsl.fmad");
18197-
18198-
auto EmitHLSLIMadDirectX = [E, M, A, B, this]() -> Value * {
18199-
if (E->getArg(0)->getType()->hasSignedIntegerRepresentation())
18200-
return Builder.CreateIntrinsic(
18201-
/*ReturnType*/ M->getType(), Intrinsic::dx_imad,
18202-
ArrayRef<Value *>{M, A, B}, nullptr, "dx.imad");
18203-
assert(E->getArg(0)->getType()->hasUnsignedIntegerRepresentation());
18204-
return Builder.CreateIntrinsic(
18205-
/*ReturnType=*/M->getType(), Intrinsic::dx_umad,
18206-
ArrayRef<Value *>{M, A, B}, nullptr, "dx.umad");
18207-
};
18208-
18209-
auto EmitHLSLIMadGeneric = [E, M, A, B, this]() -> Value * {
18210-
if (E->getArg(0)->getType()->hasSignedIntegerRepresentation()) {
18211-
Value *Mul = Builder.CreateNSWMul(M, A);
18212-
return Builder.CreateNSWAdd(Mul, B);
18213-
}
18214-
assert(E->getArg(0)->getType()->hasUnsignedIntegerRepresentation());
18215-
Value *Mul = Builder.CreateNUWMul(M, A);
18216-
return Builder.CreateNUWAdd(Mul, B);
18217-
};
18218-
CGM.getHLSLRuntime().registerHLSLTargetIntrinsic(
18219-
Builtin::BI__builtin_hlsl_mad, llvm::Triple::dxil, EmitHLSLIMadDirectX);
18220-
CGM.getHLSLRuntime().registerHLSLGenericIntrinsic(
18221-
Builtin::BI__builtin_hlsl_mad, EmitHLSLIMadGeneric);
18222-
return CGM.getHLSLRuntime().emitHLSLIntrinsic(Builtin::BI__builtin_hlsl_mad);
18223-
}
18224-
1822518189
Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
1822618190
const CallExpr *E) {
1822718191
if (!getLangOpts().HLSL)
@@ -18327,7 +18291,31 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
1832718291
ArrayRef<Value *>{Op0}, nullptr, "dx.isinf");
1832818292
}
1832918293
case Builtin::BI__builtin_hlsl_mad: {
18330-
return EmitHLSLMadIntrinsic(E);
18294+
Value *M = EmitScalarExpr(E->getArg(0));
18295+
Value *A = EmitScalarExpr(E->getArg(1));
18296+
Value *B = EmitScalarExpr(E->getArg(2));
18297+
if (E->getArg(0)->getType()->hasFloatingRepresentation())
18298+
return Builder.CreateIntrinsic(
18299+
/*ReturnType*/ M->getType(), Intrinsic::fmuladd,
18300+
ArrayRef<Value *>{M, A, B}, nullptr, "hlsl.fmad");
18301+
18302+
if (E->getArg(0)->getType()->hasSignedIntegerRepresentation()) {
18303+
if (CGM.getTarget().getTriple().getArch() == llvm::Triple::dxil)
18304+
return Builder.CreateIntrinsic(
18305+
/*ReturnType*/ M->getType(), Intrinsic::dx_imad,
18306+
ArrayRef<Value *>{M, A, B}, nullptr, "dx.imad");
18307+
18308+
Value *Mul = Builder.CreateNSWMul(M, A);
18309+
return Builder.CreateNSWAdd(Mul, B);
18310+
}
18311+
assert(E->getArg(0)->getType()->hasUnsignedIntegerRepresentation());
18312+
if (CGM.getTarget().getTriple().getArch() == llvm::Triple::dxil)
18313+
return Builder.CreateIntrinsic(
18314+
/*ReturnType=*/M->getType(), Intrinsic::dx_umad,
18315+
ArrayRef<Value *>{M, A, B}, nullptr, "dx.umad");
18316+
18317+
Value *Mul = Builder.CreateNUWMul(M, A);
18318+
return Builder.CreateNUWAdd(Mul, B);
1833118319
}
1833218320
case Builtin::BI__builtin_hlsl_elementwise_rcp: {
1833318321
Value *Op0 = EmitScalarExpr(E->getArg(0));

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -119,33 +119,6 @@ llvm::Triple::ArchType CGHLSLRuntime::getArch() {
119119
return CGM.getTarget().getTriple().getArch();
120120
}
121121

122-
void CGHLSLRuntime::registerHLSLTargetIntrinsic(
123-
Builtin::ID Id, llvm::Triple::ArchType Arch,
124-
llvm::function_ref<llvm::Value *()> IntrinsicImpl) {
125-
if (!IntrinsicCodeGen.count(Id))
126-
IntrinsicCodeGen[Id] = CGHLSLIntrinsic();
127-
IntrinsicCodeGen[Id].targetImplementations[Arch] = IntrinsicImpl;
128-
}
129-
void CGHLSLRuntime::registerHLSLGenericIntrinsic(
130-
Builtin::ID Id, llvm::function_ref<llvm::Value *()> IntrinsicImpl) {
131-
if (!IntrinsicCodeGen.count(Id))
132-
IntrinsicCodeGen[Id] = CGHLSLIntrinsic();
133-
IntrinsicCodeGen[Id].genericImplementation = IntrinsicImpl;
134-
}
135-
136-
llvm::Value *CGHLSLRuntime::emitHLSLIntrinsic(Builtin::ID id) {
137-
auto it = IntrinsicCodeGen.find(id);
138-
assert(it != IntrinsicCodeGen.end() &&
139-
" HLSL intrinsics need to be reigstered before use.");
140-
llvm::Triple::ArchType Arch = getArch();
141-
auto targets = it->second.targetImplementations;
142-
auto targetIt = targets.find(Arch);
143-
if (targetIt == targets.end()) {
144-
return it->second.genericImplementation();
145-
}
146-
return targetIt->second();
147-
}
148-
149122
void CGHLSLRuntime::addConstant(VarDecl *D, Buffer &CB) {
150123
if (D->getStorageClass() == SC_Static) {
151124
// For static inside cbuffer, take as global static.

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,6 @@ namespace llvm {
5050
class GlobalVariable;
5151
class Function;
5252
class StructType;
53-
class Value;
54-
55-
template <> struct DenseMapInfo<clang::Builtin::ID> {
56-
static clang::Builtin::ID getEmptyKey() { return clang::Builtin::NotBuiltin; }
57-
58-
static clang::Builtin::ID getTombstoneKey() {
59-
return clang::Builtin::FirstTSBuiltin;
60-
}
61-
62-
static unsigned getHashValue(clang::Builtin::ID Val) {
63-
return static_cast<unsigned>(Val);
64-
}
65-
66-
static bool isEqual(clang::Builtin::ID LHS, clang::Builtin::ID RHS) {
67-
return LHS == RHS;
68-
}
69-
};
70-
71-
template <> struct DenseMapInfo<llvm::Triple::ArchType> {
72-
static llvm::Triple::ArchType getEmptyKey() {
73-
return llvm::Triple::ArchType::UnknownArch;
74-
}
75-
76-
static llvm::Triple::ArchType getTombstoneKey() {
77-
return llvm::Triple::ArchType::LastArchType;
78-
}
79-
80-
static unsigned getHashValue(llvm::Triple::ArchType Val) {
81-
return static_cast<unsigned>(Val);
82-
}
83-
84-
static bool isEqual(llvm::Triple::ArchType LHS, llvm::Triple::ArchType RHS) {
85-
return LHS == RHS;
86-
}
87-
};
88-
8953
} // namespace llvm
9054

9155
namespace clang {
@@ -102,15 +66,6 @@ namespace CodeGen {
10266

10367
class CodeGenModule;
10468

105-
struct CGHLSLIntrinsic {
106-
llvm::DenseMap<llvm::Triple::ArchType, llvm::function_ref<llvm::Value *()>>
107-
targetImplementations;
108-
llvm::function_ref<llvm::Value *()> genericImplementation =
109-
[]() -> llvm::Value * {
110-
llvm_unreachable("Intrinsic not supported by target architecture.");
111-
};
112-
};
113-
11469
class CGHLSLRuntime {
11570
public:
11671
//===----------------------------------------------------------------------===//
@@ -124,11 +79,7 @@ class CGHLSLRuntime {
12479
//===----------------------------------------------------------------------===//
12580
// End of reserved area for HLSL intrinsic getters.
12681
//===----------------------------------------------------------------------===//
127-
void registerHLSLTargetIntrinsic(Builtin::ID, llvm::Triple::ArchType,
128-
llvm::function_ref<llvm::Value *()>);
129-
void registerHLSLGenericIntrinsic(Builtin::ID,
130-
llvm::function_ref<llvm::Value *()>);
131-
llvm::Value *emitHLSLIntrinsic(Builtin::ID);
82+
13283
struct BufferResBinding {
13384
// The ID like 2 in register(b2, space1).
13485
std::optional<unsigned> Reg;
@@ -179,7 +130,6 @@ class CGHLSLRuntime {
179130
void addBufferDecls(const DeclContext *DC, Buffer &CB);
180131
llvm::Triple::ArchType getArch();
181132
llvm::SmallVector<Buffer> Buffers;
182-
llvm::DenseMap<clang::Builtin::ID, CGHLSLIntrinsic> IntrinsicCodeGen;
183133
};
184134

185135
} // namespace CodeGen

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4548,7 +4548,6 @@ class CodeGenFunction : public CodeGenTypeCache {
45484548
llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
45494549
llvm::Value *EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
45504550
llvm::Value *EmitHLSLBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
4551-
llvm::Value *EmitHLSLMadIntrinsic(const CallExpr *E);
45524551
llvm::Value *EmitScalarOrConstFoldImmArg(unsigned ICEArguments, unsigned Idx,
45534552
const CallExpr *E);
45544553
llvm::Value *EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E);

0 commit comments

Comments
 (0)