diff --git a/llvm/unittests/Analysis/DXILResourceTest.cpp b/llvm/unittests/Analysis/DXILResourceTest.cpp index 776c914b89a045..8301458f1d1802 100644 --- a/llvm/unittests/Analysis/DXILResourceTest.cpp +++ b/llvm/unittests/Analysis/DXILResourceTest.cpp @@ -26,57 +26,23 @@ struct MDBuilder { MDBuilder(LLVMContext &Context, Type *Int32Ty, Type *Int1Ty) : Context(Context), Int32Ty(Int32Ty), Int1Ty(Int1Ty) {} - template - void appendMDs(SmallVectorImpl &MDs, int V, Ts... More) { - MDs.push_back(ConstantAsMetadata::get( - Constant::getIntegerValue(Int32Ty, APInt(32, V)))); - appendMDs(MDs, More...); + Metadata *toMD(unsigned int V) { + return ConstantAsMetadata::get( + Constant::getIntegerValue(Int32Ty, APInt(32, V))); } - template - void appendMDs(SmallVectorImpl &MDs, unsigned int V, Ts... More) { - MDs.push_back(ConstantAsMetadata::get( - Constant::getIntegerValue(Int32Ty, APInt(32, V)))); - appendMDs(MDs, More...); + Metadata *toMD(int V) { return toMD(static_cast(V)); } + Metadata *toMD(bool V) { + return ConstantAsMetadata::get( + Constant::getIntegerValue(Int32Ty, APInt(1, V))); } - template - void appendMDs(SmallVectorImpl &MDs, bool V, Ts... More) { - MDs.push_back(ConstantAsMetadata::get( - Constant::getIntegerValue(Int1Ty, APInt(1, V)))); - appendMDs(MDs, More...); - } - template - void appendMDs(SmallVectorImpl &MDs, Value *V, Ts... More) { - MDs.push_back(ValueAsMetadata::get(V)); - appendMDs(MDs, More...); - } - template - void appendMDs(SmallVectorImpl &MDs, const char *V, Ts... More) { - MDs.push_back(MDString::get(Context, V)); - appendMDs(MDs, More...); - } - template - void appendMDs(SmallVectorImpl &MDs, StringRef V, Ts... More) { - MDs.push_back(MDString::get(Context, V)); - appendMDs(MDs, More...); - } - template - void appendMDs(SmallVectorImpl &MDs, std::nullptr_t V, - Ts... More) { - MDs.push_back(nullptr); - appendMDs(MDs, More...); - } - template - void appendMDs(SmallVectorImpl &MDs, MDTuple *V, Ts... More) { - MDs.push_back(V); - appendMDs(MDs, More...); - } - void appendMDs(SmallVectorImpl &MDs) { - // Base case, nothing to do. - } - - template MDTuple *get(Ts... Data) { - SmallVector MDs; - appendMDs(MDs, Data...); + Metadata *toMD(Value *V) { return ValueAsMetadata::get(V); } + Metadata *toMD(const char *V) { return MDString::get(Context, V); } + Metadata *toMD(StringRef V) { return MDString::get(Context, V); } + Metadata *toMD(std::nullptr_t V) { return nullptr; } + Metadata *toMD(MDTuple *V) { return V; } + + template MDTuple *get(Ts... Vs) { + std::array MDs{toMD(std::forward(Vs))...}; return MDNode::get(Context, MDs); } };