mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-01 15:11:24 +00:00
60df53e30a
reflect what it does. Switch the sense of the Next and the Check arms to be more logical. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97093 91177308-0d34-0410-b5e6-96231b3b80d8
61 lines
2.0 KiB
C++
61 lines
2.0 KiB
C++
//===- DAGISelMatcherOpt.cpp - Optimize a DAG Matcher ---------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file implements the DAG Matcher optimizer.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "DAGISelMatcher.h"
|
|
using namespace llvm;
|
|
|
|
static void ContractNodes(OwningPtr<MatcherNode> &MatcherPtr) {
|
|
// If we reached the end of the chain, we're done.
|
|
MatcherNode *N = MatcherPtr.get();
|
|
if (N == 0) return;
|
|
|
|
// If we have a scope node, walk down both edges.
|
|
if (ScopeMatcherNode *Push = dyn_cast<ScopeMatcherNode>(N))
|
|
ContractNodes(Push->getCheckPtr());
|
|
|
|
// If we found a movechild node with a node that comes in a 'foochild' form,
|
|
// transform it.
|
|
if (MoveChildMatcherNode *MC = dyn_cast<MoveChildMatcherNode>(N)) {
|
|
MatcherNode *New = 0;
|
|
if (RecordMatcherNode *RM = dyn_cast<RecordMatcherNode>(MC->getNext()))
|
|
New = new RecordChildMatcherNode(MC->getChildNo(), RM->getWhatFor());
|
|
|
|
if (CheckTypeMatcherNode *CT= dyn_cast<CheckTypeMatcherNode>(MC->getNext()))
|
|
New = new CheckChildTypeMatcherNode(MC->getChildNo(), CT->getType());
|
|
|
|
if (New) {
|
|
// Insert the new node.
|
|
New->setNext(MatcherPtr.take());
|
|
MatcherPtr.reset(New);
|
|
// Remove the old one.
|
|
MC->setNext(MC->getNext()->takeNext());
|
|
return ContractNodes(MatcherPtr);
|
|
}
|
|
}
|
|
|
|
if (MoveChildMatcherNode *MC = dyn_cast<MoveChildMatcherNode>(N))
|
|
if (MoveParentMatcherNode *MP =
|
|
dyn_cast<MoveParentMatcherNode>(MC->getNext())) {
|
|
MatcherPtr.reset(MP->takeNext());
|
|
return ContractNodes(MatcherPtr);
|
|
}
|
|
|
|
ContractNodes(N->getNextPtr());
|
|
}
|
|
|
|
MatcherNode *llvm::OptimizeMatcher(MatcherNode *Matcher) {
|
|
OwningPtr<MatcherNode> MatcherPtr(Matcher);
|
|
ContractNodes(MatcherPtr);
|
|
return MatcherPtr.take();
|
|
}
|