Skip to content

Commit c38a144

Browse files
author
Simon Moll
committed
[feature] Generalized pattern rewriting
Changes to perform generalized pattern rewriting for VP intrinsics. This lifts InstSimplify/InstCombine and DAGCombiner patterns that were intended for normal instructions to also work on VP intrinsics and SDNodes. A newer version of this is part of an RFC for LLVM: https://reviews.llvm.org/D92086
1 parent 74c3e23 commit c38a144

File tree

16 files changed

+1686
-220
lines changed

16 files changed

+1686
-220
lines changed

llvm/include/llvm/IR/MatcherCast.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#ifndef LLVM_IR_MATCHERCAST_H
2+
#define LLVM_IR_MATCHERCAST_H
3+
4+
//===- MatcherCast.h - Match on the LLVM IR --------------------*- C++ -*-===//
5+
//
6+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
7+
// See https://llvm.org/LICENSE.txt for license information.
8+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
9+
//
10+
//===----------------------------------------------------------------------===//
11+
//
12+
// Parameterized class hierachy for templatized pattern matching.
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
17+
namespace llvm {
18+
namespace PatternMatch {
19+
20+
21+
// type modification
22+
template<typename Matcher, typename DestClass>
23+
struct MatcherCast {
24+
using ActualCastType = DestClass;
25+
};
26+
27+
// whether the Value \p Obj behaves like a \p Class.
28+
template<typename MatcherClass, typename Class>
29+
bool match_isa(const Value* Obj) {
30+
using UnconstClass = typename std::remove_cv<Class>::type;
31+
using DestClass = typename MatcherCast<MatcherClass, UnconstClass>::ActualCastType;
32+
return isa<const DestClass>(Obj);
33+
}
34+
35+
template<typename MatcherClass, typename Class>
36+
auto match_cast(const Value* Obj) {
37+
using UnconstClass = typename std::remove_cv<Class>::type;
38+
using DestClass = typename MatcherCast<MatcherClass, UnconstClass>::ActualCastType;
39+
return cast<const DestClass>(Obj);
40+
}
41+
template<typename MatcherClass, typename Class>
42+
auto match_dyn_cast(const Value* Obj) {
43+
using UnconstClass = typename std::remove_cv<Class>::type;
44+
using DestClass = typename MatcherCast<MatcherClass, UnconstClass>::ActualCastType;
45+
return dyn_cast<const DestClass>(Obj);
46+
}
47+
48+
template<typename MatcherClass, typename Class>
49+
auto match_cast(Value* Obj) {
50+
using UnconstClass = typename std::remove_cv<Class>::type;
51+
using DestClass = typename MatcherCast<MatcherClass, UnconstClass>::ActualCastType;
52+
return cast<DestClass>(Obj);
53+
}
54+
template<typename MatcherClass, typename Class>
55+
auto match_dyn_cast(Value* Obj) {
56+
using UnconstClass = typename std::remove_cv<Class>::type;
57+
using DestClass = typename MatcherCast<MatcherClass, UnconstClass>::ActualCastType;
58+
return dyn_cast<DestClass>(Obj);
59+
}
60+
61+
62+
} // namespace PatternMatch
63+
64+
} // namespace llvm
65+
66+
#endif // LLVM_IR_MATCHERCAST_H
67+

0 commit comments

Comments
 (0)