@@ -26,57 +26,23 @@ struct MDBuilder {
26
26
MDBuilder (LLVMContext &Context, Type *Int32Ty, Type *Int1Ty)
27
27
: Context(Context), Int32Ty(Int32Ty), Int1Ty(Int1Ty) {}
28
28
29
- template <typename ... Ts>
30
- void appendMDs (SmallVectorImpl<Metadata *> &MDs, int V, Ts... More) {
31
- MDs.push_back (ConstantAsMetadata::get (
32
- Constant::getIntegerValue (Int32Ty, APInt (32 , V))));
33
- appendMDs (MDs, More...);
29
+ Metadata *toMD (unsigned int V) {
30
+ return ConstantAsMetadata::get (
31
+ Constant::getIntegerValue (Int32Ty, APInt (32 , V)));
34
32
}
35
- template <typename ... Ts>
36
- void appendMDs (SmallVectorImpl<Metadata *> &MDs, unsigned int V, Ts... More) {
37
- MDs.push_back (ConstantAsMetadata::get (
38
- Constant::getIntegerValue (Int32Ty, APInt (32 , V))));
39
- appendMDs (MDs, More...);
33
+ Metadata *toMD (int V) { return toMD (static_cast <unsigned int >(V)); }
34
+ Metadata *toMD (bool V) {
35
+ return ConstantAsMetadata::get (
36
+ Constant::getIntegerValue (Int32Ty, APInt (1 , V)));
40
37
}
41
- template <typename ... Ts>
42
- void appendMDs (SmallVectorImpl<Metadata *> &MDs, bool V, Ts... More) {
43
- MDs.push_back (ConstantAsMetadata::get (
44
- Constant::getIntegerValue (Int1Ty, APInt (1 , V))));
45
- appendMDs (MDs, More...);
46
- }
47
- template <typename ... Ts>
48
- void appendMDs (SmallVectorImpl<Metadata *> &MDs, Value *V, Ts... More) {
49
- MDs.push_back (ValueAsMetadata::get (V));
50
- appendMDs (MDs, More...);
51
- }
52
- template <typename ... Ts>
53
- void appendMDs (SmallVectorImpl<Metadata *> &MDs, const char *V, Ts... More) {
54
- MDs.push_back (MDString::get (Context, V));
55
- appendMDs (MDs, More...);
56
- }
57
- template <typename ... Ts>
58
- void appendMDs (SmallVectorImpl<Metadata *> &MDs, StringRef V, Ts... More) {
59
- MDs.push_back (MDString::get (Context, V));
60
- appendMDs (MDs, More...);
61
- }
62
- template <typename ... Ts>
63
- void appendMDs (SmallVectorImpl<Metadata *> &MDs, std::nullptr_t V,
64
- Ts... More) {
65
- MDs.push_back (nullptr );
66
- appendMDs (MDs, More...);
67
- }
68
- template <typename ... Ts>
69
- void appendMDs (SmallVectorImpl<Metadata *> &MDs, MDTuple *V, Ts... More) {
70
- MDs.push_back (V);
71
- appendMDs (MDs, More...);
72
- }
73
- void appendMDs (SmallVectorImpl<Metadata *> &MDs) {
74
- // Base case, nothing to do.
75
- }
76
-
77
- template <typename ... Ts> MDTuple *get (Ts... Data) {
78
- SmallVector<Metadata *> MDs;
79
- appendMDs (MDs, Data...);
38
+ Metadata *toMD (Value *V) { return ValueAsMetadata::get (V); }
39
+ Metadata *toMD (const char *V) { return MDString::get (Context, V); }
40
+ Metadata *toMD (StringRef V) { return MDString::get (Context, V); }
41
+ Metadata *toMD (std::nullptr_t V) { return nullptr ; }
42
+ Metadata *toMD (MDTuple *V) { return V; }
43
+
44
+ template <typename ... Ts> MDTuple *get (Ts... Vs) {
45
+ std::array<Metadata *, sizeof ...(Vs)> MDs{toMD (std::forward<Ts>(Vs))...};
80
46
return MDNode::get (Context, MDs);
81
47
}
82
48
};
0 commit comments