//===-- llvm/CodeGen/GlobalISel/CSEMIRBuilder.h --*- C++ -*-==// // // 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 /// This file implements a version of MachineIRBuilder which CSEs insts within /// a MachineBasicBlock. //===----------------------------------------------------------------------===// #ifndef LLVM_CODEGEN_GLOBALISEL_CSEMIRBUILDER_H #define LLVM_CODEGEN_GLOBALISEL_CSEMIRBUILDER_H #include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h" namespace llvm { class GISelInstProfileBuilder; /// Defines a builder that does CSE of MachineInstructions using GISelCSEInfo. /// Eg usage. /// /// /// GISelCSEInfo *Info = /// &getAnalysis<GISelCSEAnalysisWrapperPass>().getCSEInfo(); CSEMIRBuilder /// CB(Builder.getState()); CB.setCSEInfo(Info); auto A = CB.buildConstant(s32, /// 42); auto B = CB.buildConstant(s32, 42); assert(A == B); unsigned CReg = /// MRI.createGenericVirtualRegister(s32); auto C = CB.buildConstant(CReg, 42); /// assert(C->getOpcode() == TargetOpcode::COPY); /// Explicitly passing in a register would materialize a copy if possible. /// CSEMIRBuilder also does trivial constant folding for binary ops. class CSEMIRBuilder : public MachineIRBuilder { … }; } // namespace llvm #endif