The following changes are necessasy to get the generated tree
matcher to compile:
- In CodeExpansions::declare(), the assert() prevents connecting
two instructions. E.g. the match code
(match (MUL $t, $s1, $s2),
(SUB $d, $t, $s3)),
results in two declarations of $t, one for the def and one for
the use. Removing the assertion allows this construct.
If $t is later used, it is one of the operands, which should be
perfectly fine.
- The code emitted in GIMatchTreeVRegDefPartitioner::generatePartitionSelectorCode()
is not compilable:
- The value of NewInstrID should be emitted, not the name
- Both calls involving getOperand() end with one parenthesis too many
- Swaps generated condition for the partition code in the latter function
It also changes the rules i2p_to_p2i, fabs_fabs_fold, and fneg_fneg_fold
to use the tree matcher for a linear match. These rules are tested by:
CodeGen/AArch64/GlobalISel/combine-fabs.mir
CodeGen/AArch64/GlobalISel/combine-fneg.mir
CodeGen/AArch64/GlobalISel/combine-ptrtoint.mir
CodeGen/AMDGPU/GlobalISel/combine-add-nullptr.mir
Reviewed By: arsenm
Differential Revision: https://reviews.llvm.org/D133257
44 lines
1.4 KiB
C++
44 lines
1.4 KiB
C++
//===- CodeExpansions.h - Record expansions for CodeExpander --------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
/// \file Record the expansions to use in a CodeExpander.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#ifndef LLVM_UTILS_TABLEGEN_CODEEXPANSIONS_H
|
|
#define LLVM_UTILS_TABLEGEN_CODEEXPANSIONS_H
|
|
namespace llvm {
|
|
class CodeExpansions {
|
|
public:
|
|
using const_iterator = StringMap<std::string>::const_iterator;
|
|
|
|
protected:
|
|
StringMap<std::string> Expansions;
|
|
|
|
public:
|
|
void declare(StringRef Name, StringRef Expansion) {
|
|
// Duplicates are not inserted. The expansion refers to different
|
|
// MachineOperands using the same virtual register.
|
|
Expansions.try_emplace(Name, Expansion);
|
|
}
|
|
|
|
std::string lookup(StringRef Variable) const {
|
|
return Expansions.lookup(Variable);
|
|
}
|
|
|
|
const_iterator begin() const { return Expansions.begin(); }
|
|
const_iterator end() const { return Expansions.end(); }
|
|
const_iterator find(StringRef Variable) const {
|
|
return Expansions.find(Variable);
|
|
}
|
|
};
|
|
} // end namespace llvm
|
|
#endif // ifndef LLVM_UTILS_TABLEGEN_CODEEXPANSIONS_H
|