Skip to content

Commit

Permalink
[DXIL] Simplify MDBuilder in resource unit tests. NFC (#120275)
Browse files Browse the repository at this point in the history
  • Loading branch information
bogner authored Dec 17, 2024
1 parent 7153a21 commit 65d2177
Showing 1 changed file with 15 additions and 49 deletions.
64 changes: 15 additions & 49 deletions llvm/unittests/Analysis/DXILResourceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,57 +26,23 @@ struct MDBuilder {
MDBuilder(LLVMContext &Context, Type *Int32Ty, Type *Int1Ty)
: Context(Context), Int32Ty(Int32Ty), Int1Ty(Int1Ty) {}

template <typename... Ts>
void appendMDs(SmallVectorImpl<Metadata *> &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 <typename... Ts>
void appendMDs(SmallVectorImpl<Metadata *> &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<unsigned int>(V)); }
Metadata *toMD(bool V) {
return ConstantAsMetadata::get(
Constant::getIntegerValue(Int32Ty, APInt(1, V)));
}
template <typename... Ts>
void appendMDs(SmallVectorImpl<Metadata *> &MDs, bool V, Ts... More) {
MDs.push_back(ConstantAsMetadata::get(
Constant::getIntegerValue(Int1Ty, APInt(1, V))));
appendMDs(MDs, More...);
}
template <typename... Ts>
void appendMDs(SmallVectorImpl<Metadata *> &MDs, Value *V, Ts... More) {
MDs.push_back(ValueAsMetadata::get(V));
appendMDs(MDs, More...);
}
template <typename... Ts>
void appendMDs(SmallVectorImpl<Metadata *> &MDs, const char *V, Ts... More) {
MDs.push_back(MDString::get(Context, V));
appendMDs(MDs, More...);
}
template <typename... Ts>
void appendMDs(SmallVectorImpl<Metadata *> &MDs, StringRef V, Ts... More) {
MDs.push_back(MDString::get(Context, V));
appendMDs(MDs, More...);
}
template <typename... Ts>
void appendMDs(SmallVectorImpl<Metadata *> &MDs, std::nullptr_t V,
Ts... More) {
MDs.push_back(nullptr);
appendMDs(MDs, More...);
}
template <typename... Ts>
void appendMDs(SmallVectorImpl<Metadata *> &MDs, MDTuple *V, Ts... More) {
MDs.push_back(V);
appendMDs(MDs, More...);
}
void appendMDs(SmallVectorImpl<Metadata *> &MDs) {
// Base case, nothing to do.
}

template <typename... Ts> MDTuple *get(Ts... Data) {
SmallVector<Metadata *> 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 <typename... Ts> MDTuple *get(Ts... Vs) {
std::array<Metadata *, sizeof...(Vs)> MDs{toMD(std::forward<Ts>(Vs))...};
return MDNode::get(Context, MDs);
}
};
Expand Down

0 comments on commit 65d2177

Please sign in to comment.