From 7061dc50b2513731d7b346ab16183cda4a44619f Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 3 Dec 2001 18:02:31 +0000 Subject: [PATCH] Split the PHINode class out from the iOther.h file into the iPHINode.h file git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1405 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/iOther.h | 68 ---------------- include/llvm/iPHINode.h | 80 +++++++++++++++++++ lib/Analysis/InductionVariable.cpp | 3 +- lib/AsmParser/llvmAsmParser.y | 7 +- lib/Bytecode/Reader/ConstantReader.cpp | 3 +- lib/Bytecode/Reader/InstructionReader.cpp | 6 +- lib/Bytecode/Reader/Reader.cpp | 4 +- lib/Bytecode/Reader/ReaderInternals.h | 1 + lib/CodeGen/InstrSelection/InstrForest.cpp | 2 +- lib/CodeGen/InstrSelection/InstrSelection.cpp | 2 +- lib/ExecutionEngine/Interpreter/Execution.cpp | 1 + .../SparcV9/InstrSelection/InstrForest.cpp | 2 +- .../SparcV9/InstrSelection/InstrSelection.cpp | 2 +- lib/Transforms/ExprTypeConvert.cpp | 1 + lib/Transforms/HoistPHIConstants.cpp | 4 +- lib/Transforms/IPO/DeadTypeElimination.cpp | 3 +- lib/Transforms/IPO/InlineSimple.cpp | 1 + lib/Transforms/IPO/MutateStructTypes.cpp | 3 +- lib/Transforms/Scalar/ADCE.cpp | 2 +- lib/Transforms/Scalar/ConstantProp.cpp | 1 + lib/Transforms/Scalar/DCE.cpp | 2 +- lib/Transforms/Scalar/InductionVars.cpp | 2 +- lib/Transforms/Scalar/SCCP.cpp | 3 +- .../Utils/UnifyFunctionExitNodes.cpp | 2 +- lib/VMCore/AsmWriter.cpp | 3 +- lib/VMCore/BasicBlock.cpp | 2 +- lib/VMCore/InstrTypes.cpp | 1 + 27 files changed, 113 insertions(+), 98 deletions(-) create mode 100644 include/llvm/iPHINode.h diff --git a/include/llvm/iOther.h b/include/llvm/iOther.h index cba41964d7a..de1532d5903 100644 --- a/include/llvm/iOther.h +++ b/include/llvm/iOther.h @@ -11,74 +11,6 @@ #include "llvm/InstrTypes.h" #include "llvm/Method.h" -//===----------------------------------------------------------------------===// -// PHINode Class -//===----------------------------------------------------------------------===// - -// PHINode - The PHINode class is used to represent the magical mystical PHI -// node, that can not exist in nature, but can be synthesized in a computer -// scientist's overactive imagination. -// -class PHINode : public Instruction { - PHINode(const PHINode &PN); -public: - PHINode(const Type *Ty, const string &Name = ""); - - virtual Instruction *clone() const { return new PHINode(*this); } - virtual const char *getOpcodeName() const { return "phi"; } - - // getNumIncomingValues - Return the number of incoming edges the PHI node has - inline unsigned getNumIncomingValues() const { return Operands.size()/2; } - - // getIncomingValue - Return incoming value #x - inline const Value *getIncomingValue(unsigned i) const { - return Operands[i*2]; - } - inline Value *getIncomingValue(unsigned i) { - return Operands[i*2]; - } - inline void setIncomingValue(unsigned i, Value *V) { - Operands[i*2] = V; - } - - // getIncomingBlock - Return incoming basic block #x - inline const BasicBlock *getIncomingBlock(unsigned i) const { - return cast(Operands[i*2+1]); - } - inline BasicBlock *getIncomingBlock(unsigned i) { - return cast(Operands[i*2+1]); - } - inline void setIncomingBlock(unsigned i, BasicBlock *BB) { - Operands[i*2+1] = BB; - } - - // addIncoming - Add an incoming value to the end of the PHI list - void addIncoming(Value *D, BasicBlock *BB); - - // removeIncomingValue - Remove an incoming value. This is useful if a - // predecessor basic block is deleted. The value removed is returned. - Value *removeIncomingValue(const BasicBlock *BB); - - // getBasicBlockIndex - Return the first index of the specified basic - // block in the value list for this PHI. Returns -1 if no instance. - // - int getBasicBlockIndex(const BasicBlock *BB) const { - for (unsigned i = 0; i < Operands.size()/2; ++i) - if (getIncomingBlock(i) == BB) return i; - return -1; - } - - // Methods for support type inquiry through isa, cast, and dyn_cast: - static inline bool classof(const PHINode *) { return true; } - static inline bool classof(const Instruction *I) { - return I->getOpcode() == Instruction::PHINode; - } - static inline bool classof(const Value *V) { - return isa(V) && classof(cast(V)); - } -}; - - //===----------------------------------------------------------------------===// // CastInst Class //===----------------------------------------------------------------------===// diff --git a/include/llvm/iPHINode.h b/include/llvm/iPHINode.h new file mode 100644 index 00000000000..66afac62c08 --- /dev/null +++ b/include/llvm/iPHINode.h @@ -0,0 +1,80 @@ +//===-- llvm/iPHINode.h - PHI instruction definition -------------*- C++ -*--=// +// +// This file defines the PHINode class. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_IPHINODE_H +#define LLVM_IPHINODE_H + +#include "llvm/Instruction.h" +class BasicBlock; + +//===----------------------------------------------------------------------===// +// PHINode Class +//===----------------------------------------------------------------------===// + +// PHINode - The PHINode class is used to represent the magical mystical PHI +// node, that can not exist in nature, but can be synthesized in a computer +// scientist's overactive imagination. +// +class PHINode : public Instruction { + PHINode(const PHINode &PN); +public: + PHINode(const Type *Ty, const string &Name = ""); + + virtual Instruction *clone() const { return new PHINode(*this); } + virtual const char *getOpcodeName() const { return "phi"; } + + // getNumIncomingValues - Return the number of incoming edges the PHI node has + inline unsigned getNumIncomingValues() const { return Operands.size()/2; } + + // getIncomingValue - Return incoming value #x + inline const Value *getIncomingValue(unsigned i) const { + return Operands[i*2]; + } + inline Value *getIncomingValue(unsigned i) { + return Operands[i*2]; + } + inline void setIncomingValue(unsigned i, Value *V) { + Operands[i*2] = V; + } + + // getIncomingBlock - Return incoming basic block #x + inline const BasicBlock *getIncomingBlock(unsigned i) const { + return (const BasicBlock*)Operands[i*2+1].get(); + } + inline BasicBlock *getIncomingBlock(unsigned i) { + return (BasicBlock*)Operands[i*2+1].get(); + } + inline void setIncomingBlock(unsigned i, BasicBlock *BB) { + Operands[i*2+1] = (Value*)BB; + } + + // addIncoming - Add an incoming value to the end of the PHI list + void addIncoming(Value *D, BasicBlock *BB); + + // removeIncomingValue - Remove an incoming value. This is useful if a + // predecessor basic block is deleted. The value removed is returned. + Value *removeIncomingValue(const BasicBlock *BB); + + // getBasicBlockIndex - Return the first index of the specified basic + // block in the value list for this PHI. Returns -1 if no instance. + // + int getBasicBlockIndex(const BasicBlock *BB) const { + for (unsigned i = 0; i < Operands.size()/2; ++i) + if (getIncomingBlock(i) == BB) return i; + return -1; + } + + // Methods for support type inquiry through isa, cast, and dyn_cast: + static inline bool classof(const PHINode *) { return true; } + static inline bool classof(const Instruction *I) { + return I->getOpcode() == Instruction::PHINode; + } + static inline bool classof(const Value *V) { + return isa(V) && classof(cast(V)); + } +}; + +#endif diff --git a/lib/Analysis/InductionVariable.cpp b/lib/Analysis/InductionVariable.cpp index b64daa25b30..73f4e7fe571 100644 --- a/lib/Analysis/InductionVariable.cpp +++ b/lib/Analysis/InductionVariable.cpp @@ -19,7 +19,8 @@ #include "llvm/Analysis/InductionVariable.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/Expressions.h" -#include "llvm/iOther.h" +#include "llvm/iPHINode.h" +#include "llvm/InstrTypes.h" #include "llvm/Type.h" #include "llvm/ConstPoolVals.h" diff --git a/lib/AsmParser/llvmAsmParser.y b/lib/AsmParser/llvmAsmParser.y index 0f5c11e1eae..b5816f20ac1 100644 --- a/lib/AsmParser/llvmAsmParser.y +++ b/lib/AsmParser/llvmAsmParser.y @@ -4,12 +4,6 @@ // //===------------------------------------------------------------------------=// -// -// TODO: Parse comments and add them to an internal node... so that they may -// be saved in the bytecode format as well as everything else. Very important -// for a general IR format. -// - %{ #include "ParserInternals.h" #include "llvm/Assembly/Parser.h" @@ -21,6 +15,7 @@ #include "llvm/DerivedTypes.h" #include "llvm/iTerminators.h" #include "llvm/iMemory.h" +#include "llvm/iPHINode.h" #include "Support/STLExtras.h" #include "Support/DepthFirstIterator.h" #include diff --git a/lib/Bytecode/Reader/ConstantReader.cpp b/lib/Bytecode/Reader/ConstantReader.cpp index 405745d14ad..21462b16d74 100644 --- a/lib/Bytecode/Reader/ConstantReader.cpp +++ b/lib/Bytecode/Reader/ConstantReader.cpp @@ -8,12 +8,11 @@ // //===------------------------------------------------------------------------=== +#include "ReaderInternals.h" #include "llvm/Module.h" #include "llvm/BasicBlock.h" #include "llvm/ConstPoolVals.h" -#include "llvm/DerivedTypes.h" #include "llvm/GlobalVariable.h" -#include "ReaderInternals.h" #include diff --git a/lib/Bytecode/Reader/InstructionReader.cpp b/lib/Bytecode/Reader/InstructionReader.cpp index c59d147c240..a80f656d0dd 100644 --- a/lib/Bytecode/Reader/InstructionReader.cpp +++ b/lib/Bytecode/Reader/InstructionReader.cpp @@ -11,11 +11,11 @@ // //===----------------------------------------------------------------------===// -#include "llvm/iOther.h" +#include "ReaderInternals.h" #include "llvm/iTerminators.h" #include "llvm/iMemory.h" -#include "llvm/DerivedTypes.h" -#include "ReaderInternals.h" +#include "llvm/iPHINode.h" +#include "llvm/iOther.h" bool BytecodeParser::ParseRawInst(const uchar *&Buf, const uchar *EndBuf, RawInst &Result) { diff --git a/lib/Bytecode/Reader/Reader.cpp b/lib/Bytecode/Reader/Reader.cpp index 7f02b9339f8..2766b3485ed 100644 --- a/lib/Bytecode/Reader/Reader.cpp +++ b/lib/Bytecode/Reader/Reader.cpp @@ -10,15 +10,15 @@ // //===----------------------------------------------------------------------===// +#include "ReaderInternals.h" #include "llvm/Bytecode/Reader.h" #include "llvm/Bytecode/Format.h" #include "llvm/GlobalVariable.h" #include "llvm/Module.h" #include "llvm/BasicBlock.h" -#include "llvm/DerivedTypes.h" #include "llvm/ConstPoolVals.h" +#include "llvm/iPHINode.h" #include "llvm/iOther.h" -#include "ReaderInternals.h" #include #include #include diff --git a/lib/Bytecode/Reader/ReaderInternals.h b/lib/Bytecode/Reader/ReaderInternals.h index fb34169d795..b3977f6c123 100644 --- a/lib/Bytecode/Reader/ReaderInternals.h +++ b/lib/Bytecode/Reader/ReaderInternals.h @@ -11,6 +11,7 @@ #include "llvm/SymTabValue.h" #include "llvm/Method.h" #include "llvm/Instruction.h" +#include "llvm/DerivedTypes.h" #include #include #include diff --git a/lib/CodeGen/InstrSelection/InstrForest.cpp b/lib/CodeGen/InstrSelection/InstrForest.cpp index c6d53674ac7..e0f0219a73f 100644 --- a/lib/CodeGen/InstrSelection/InstrForest.cpp +++ b/lib/CodeGen/InstrSelection/InstrForest.cpp @@ -26,7 +26,7 @@ #include "llvm/Method.h" #include "llvm/iTerminators.h" #include "llvm/iMemory.h" -#include "llvm/iOther.h" +#include "llvm/iPHINode.h" #include "llvm/ConstPoolVals.h" #include "llvm/BasicBlock.h" #include "llvm/CodeGen/MachineInstr.h" diff --git a/lib/CodeGen/InstrSelection/InstrSelection.cpp b/lib/CodeGen/InstrSelection/InstrSelection.cpp index ce26a1d073e..d0a301ce5ee 100644 --- a/lib/CodeGen/InstrSelection/InstrSelection.cpp +++ b/lib/CodeGen/InstrSelection/InstrSelection.cpp @@ -20,7 +20,7 @@ #include "llvm/Instruction.h" #include "llvm/BasicBlock.h" #include "llvm/Method.h" -#include "llvm/iOther.h" +#include "llvm/iPHINode.h" #include "llvm/Target/MachineRegInfo.h" #include "Support/CommandLine.h" #include diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index 2f0ee41c52f..a1547c16532 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -6,6 +6,7 @@ #include "Interpreter.h" #include "ExecutionAnnotations.h" +#include "llvm/iPHINode.h" #include "llvm/iOther.h" #include "llvm/iTerminators.h" #include "llvm/iMemory.h" diff --git a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp index c6d53674ac7..e0f0219a73f 100644 --- a/lib/Target/SparcV9/InstrSelection/InstrForest.cpp +++ b/lib/Target/SparcV9/InstrSelection/InstrForest.cpp @@ -26,7 +26,7 @@ #include "llvm/Method.h" #include "llvm/iTerminators.h" #include "llvm/iMemory.h" -#include "llvm/iOther.h" +#include "llvm/iPHINode.h" #include "llvm/ConstPoolVals.h" #include "llvm/BasicBlock.h" #include "llvm/CodeGen/MachineInstr.h" diff --git a/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp b/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp index ce26a1d073e..d0a301ce5ee 100644 --- a/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp +++ b/lib/Target/SparcV9/InstrSelection/InstrSelection.cpp @@ -20,7 +20,7 @@ #include "llvm/Instruction.h" #include "llvm/BasicBlock.h" #include "llvm/Method.h" -#include "llvm/iOther.h" +#include "llvm/iPHINode.h" #include "llvm/Target/MachineRegInfo.h" #include "Support/CommandLine.h" #include diff --git a/lib/Transforms/ExprTypeConvert.cpp b/lib/Transforms/ExprTypeConvert.cpp index a1d92f1b269..7efe6238bec 100644 --- a/lib/Transforms/ExprTypeConvert.cpp +++ b/lib/Transforms/ExprTypeConvert.cpp @@ -9,6 +9,7 @@ #include "TransformInternals.h" #include "llvm/Method.h" #include "llvm/iOther.h" +#include "llvm/iPHINode.h" #include "llvm/iMemory.h" #include "llvm/ConstPoolVals.h" #include "llvm/Optimizations/ConstantHandling.h" diff --git a/lib/Transforms/HoistPHIConstants.cpp b/lib/Transforms/HoistPHIConstants.cpp index d08deba7781..fe7cabf1614 100644 --- a/lib/Transforms/HoistPHIConstants.cpp +++ b/lib/Transforms/HoistPHIConstants.cpp @@ -6,10 +6,8 @@ // //===----------------------------------------------------------------------===// - - - #include "llvm/Transforms/HoistPHIConstants.h" +#include "llvm/iPHINode.h" #include "llvm/iOther.h" #include "llvm/BasicBlock.h" #include "llvm/Method.h" diff --git a/lib/Transforms/IPO/DeadTypeElimination.cpp b/lib/Transforms/IPO/DeadTypeElimination.cpp index e02c022dbb2..f29ae29e0b3 100644 --- a/lib/Transforms/IPO/DeadTypeElimination.cpp +++ b/lib/Transforms/IPO/DeadTypeElimination.cpp @@ -18,9 +18,10 @@ #include "TransformInternals.h" #include "llvm/SymbolTable.h" #include "llvm/DerivedTypes.h" -#include "llvm/iOther.h" +#include "llvm/iPHINode.h" #include "llvm/iMemory.h" #include "llvm/iTerminators.h" +#include "llvm/iOther.h" #include static const Type *PtrArrSByte = 0; // '[sbyte]*' type diff --git a/lib/Transforms/IPO/InlineSimple.cpp b/lib/Transforms/IPO/InlineSimple.cpp index bc320ee330f..e54e0d9b7f4 100644 --- a/lib/Transforms/IPO/InlineSimple.cpp +++ b/lib/Transforms/IPO/InlineSimple.cpp @@ -23,6 +23,7 @@ #include "llvm/Module.h" #include "llvm/Method.h" #include "llvm/iTerminators.h" +#include "llvm/iPHINode.h" #include "llvm/iOther.h" #include #include diff --git a/lib/Transforms/IPO/MutateStructTypes.cpp b/lib/Transforms/IPO/MutateStructTypes.cpp index fd1f46d0fa2..a433e26ec54 100644 --- a/lib/Transforms/IPO/MutateStructTypes.cpp +++ b/lib/Transforms/IPO/MutateStructTypes.cpp @@ -16,9 +16,10 @@ #include "llvm/Method.h" #include "llvm/GlobalVariable.h" #include "llvm/SymbolTable.h" -#include "llvm/iOther.h" +#include "llvm/iPHINode.h" #include "llvm/iMemory.h" #include "llvm/iTerminators.h" +#include "llvm/iOther.h" #include // To enable debugging, uncomment this... diff --git a/lib/Transforms/Scalar/ADCE.cpp b/lib/Transforms/Scalar/ADCE.cpp index a5d1d12bcf8..a38dbc56176 100644 --- a/lib/Transforms/Scalar/ADCE.cpp +++ b/lib/Transforms/Scalar/ADCE.cpp @@ -12,7 +12,7 @@ #include "llvm/Analysis/Dominators.h" #include "llvm/Analysis/Writer.h" #include "llvm/iTerminators.h" -#include "llvm/iOther.h" +#include "llvm/iPHINode.h" #include "Support/STLExtras.h" #include "Support/DepthFirstIterator.h" #include diff --git a/lib/Transforms/Scalar/ConstantProp.cpp b/lib/Transforms/Scalar/ConstantProp.cpp index 15be76343e1..bf2886871f8 100644 --- a/lib/Transforms/Scalar/ConstantProp.cpp +++ b/lib/Transforms/Scalar/ConstantProp.cpp @@ -27,6 +27,7 @@ #include "llvm/Method.h" #include "llvm/BasicBlock.h" #include "llvm/iTerminators.h" +#include "llvm/iPHINode.h" #include "llvm/iOther.h" #include "llvm/ConstPoolVals.h" diff --git a/lib/Transforms/Scalar/DCE.cpp b/lib/Transforms/Scalar/DCE.cpp index caacf32d389..e1bda22b8b9 100644 --- a/lib/Transforms/Scalar/DCE.cpp +++ b/lib/Transforms/Scalar/DCE.cpp @@ -29,7 +29,7 @@ #include "llvm/Method.h" #include "llvm/BasicBlock.h" #include "llvm/iTerminators.h" -#include "llvm/iOther.h" +#include "llvm/iPHINode.h" #include "llvm/Assembly/Writer.h" #include "Support/STLExtras.h" #include diff --git a/lib/Transforms/Scalar/InductionVars.cpp b/lib/Transforms/Scalar/InductionVars.cpp index 9f0513f36e8..7dfae486d2b 100644 --- a/lib/Transforms/Scalar/InductionVars.cpp +++ b/lib/Transforms/Scalar/InductionVars.cpp @@ -24,7 +24,7 @@ #include "llvm/Analysis/IntervalPartition.h" #include "llvm/Assembly/Writer.h" #include "llvm/SymbolTable.h" -#include "llvm/iOther.h" +#include "llvm/iPHINode.h" #include "Support/STLExtras.h" #include diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 256fadf6371..3c699c16e0e 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -21,9 +21,10 @@ #include "llvm/BasicBlock.h" #include "llvm/ConstPoolVals.h" #include "llvm/InstrTypes.h" -#include "llvm/iOther.h" +#include "llvm/iPHINode.h" #include "llvm/iMemory.h" #include "llvm/iTerminators.h" +#include "llvm/iOther.h" #include "llvm/Assembly/Writer.h" #include "Support/STLExtras.h" #include diff --git a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp index ab600bd151a..efc7676bb71 100644 --- a/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp +++ b/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp @@ -9,7 +9,7 @@ #include "llvm/BasicBlock.h" #include "llvm/Method.h" #include "llvm/iTerminators.h" -#include "llvm/iOther.h" +#include "llvm/iPHINode.h" #include "llvm/Type.h" // UnifyAllExitNodes - Unify all exit nodes of the CFG by creating a new diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 2be172324c4..9523c9428a1 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -17,9 +17,10 @@ #include "llvm/GlobalVariable.h" #include "llvm/BasicBlock.h" #include "llvm/ConstPoolVals.h" -#include "llvm/iOther.h" #include "llvm/iMemory.h" #include "llvm/iTerminators.h" +#include "llvm/iPHINode.h" +#include "llvm/iOther.h" #include "llvm/SymbolTable.h" #include "Support/StringExtras.h" #include "Support/STLExtras.h" diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index 462b98fb87d..40962ef0f3d 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -10,7 +10,7 @@ #include "llvm/Method.h" #include "llvm/SymbolTable.h" #include "llvm/Type.h" -#include "llvm/iOther.h" +#include "llvm/iPHINode.h" #include "llvm/CodeGen/MachineInstr.h" // Instantiate Templates - This ugliness is the price we have to pay diff --git a/lib/VMCore/InstrTypes.cpp b/lib/VMCore/InstrTypes.cpp index 9e49805d315..69a703c0c74 100644 --- a/lib/VMCore/InstrTypes.cpp +++ b/lib/VMCore/InstrTypes.cpp @@ -5,6 +5,7 @@ //===----------------------------------------------------------------------===// #include "llvm/iOther.h" +#include "llvm/iPHINode.h" #include "llvm/BasicBlock.h" #include "llvm/Method.h" #include "llvm/SymbolTable.h"