From d3b34b7f3a7cbfc96aea897419f167b5ee19e61a Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Fri, 2 Jun 2023 10:47:36 -0700 Subject: [PATCH] [RDF] Use trailing return type syntax, NFC The name rdf::Use conflicts with llvm::Use when both namespaces are used via `using namespace`. Specifically this happened in the declaration of DataFlowGraph::newUse (in RDFGraph.cpp): ``` using namespace rdf; Use newUse(...); <-- Lookup conflict for "Use" ``` Since the TRT lookup starts in a different namespace than that of the leading type, this serves as a workaround. In general the rdf namespace will not likely be introduced via `using namespace`, so this shouldn't be a problem elsewhere. --- llvm/include/llvm/CodeGen/RDFGraph.h | 360 ++++++++++++++------------- llvm/lib/CodeGen/RDFGraph.cpp | 194 ++++++++------- 2 files changed, 293 insertions(+), 261 deletions(-) diff --git a/llvm/include/llvm/CodeGen/RDFGraph.h b/llvm/include/llvm/CodeGen/RDFGraph.h index f76f6cdaa5bc..f3fe6ad81dd5 100644 --- a/llvm/include/llvm/CodeGen/RDFGraph.h +++ b/llvm/include/llvm/CodeGen/RDFGraph.h @@ -293,29 +293,29 @@ struct NodeAttrs { }; // clang-format on - static uint16_t type(uint16_t T) { // + static auto type(uint16_t T) -> uint16_t { // return T & TypeMask; } - static uint16_t kind(uint16_t T) { // + static auto kind(uint16_t T) -> uint16_t { // return T & KindMask; } - static uint16_t flags(uint16_t T) { // + static auto flags(uint16_t T) -> uint16_t { // return T & FlagMask; } - static uint16_t set_type(uint16_t A, uint16_t T) { + static auto set_type(uint16_t A, uint16_t T) -> uint16_t { return (A & ~TypeMask) | T; } - static uint16_t set_kind(uint16_t A, uint16_t K) { + static auto set_kind(uint16_t A, uint16_t K) -> uint16_t { return (A & ~KindMask) | K; } - static uint16_t set_flags(uint16_t A, uint16_t F) { + static auto set_flags(uint16_t A, uint16_t F) -> uint16_t { return (A & ~FlagMask) | F; } // Test if A contains B. - static bool contains(uint16_t A, uint16_t B) { + static auto contains(uint16_t A, uint16_t B) -> bool { if (type(A) != Code) return false; uint16_t KB = kind(B); @@ -348,11 +348,11 @@ template struct NodeAddr { template NodeAddr(const NodeAddr &NA) : Addr(static_cast(NA.Addr)), Id(NA.Id) {} - bool operator==(const NodeAddr &NA) const { + auto operator==(const NodeAddr &NA) const -> bool { assert((Addr == NA.Addr) == (Id == NA.Id)); return Addr == NA.Addr; } - bool operator!=(const NodeAddr &NA) const { // + auto operator!=(const NodeAddr &NA) const -> bool { return !operator==(NA); } @@ -414,22 +414,22 @@ struct NodeAllocator { assert(isPowerOf2_32(NPB)); } - NodeBase *ptr(NodeId N) const { + auto ptr(NodeId N) const -> NodeBase * { uint32_t N1 = N - 1; uint32_t BlockN = N1 >> BitsPerIndex; uint32_t Offset = (N1 & IndexMask) * NodeMemSize; return reinterpret_cast(Blocks[BlockN] + Offset); } - NodeId id(const NodeBase *P) const; - Node New(); - void clear(); + auto id(const NodeBase *P) const -> NodeId; + auto New() -> Node; + auto clear() -> void; private: - void startNewBlock(); - bool needNewBlock(); + auto startNewBlock() -> void; + auto needNewBlock() -> bool; - uint32_t makeId(uint32_t Block, uint32_t Index) const { + auto makeId(uint32_t Block, uint32_t Index) const -> uint32_t { // Add 1 to the id, to avoid the id of 0, which is treated as "null". return ((Block << BitsPerIndex) | Index) + 1; } @@ -449,9 +449,11 @@ struct TargetOperandInfo { TargetOperandInfo(const TargetInstrInfo &tii) : TII(tii) {} virtual ~TargetOperandInfo() = default; - virtual bool isPreserving(const MachineInstr &In, unsigned OpNum) const; - virtual bool isClobbering(const MachineInstr &In, unsigned OpNum) const; - virtual bool isFixedReg(const MachineInstr &In, unsigned OpNum) const; + virtual auto isPreserving(const MachineInstr &In, unsigned OpNum) const + -> bool; + virtual auto isClobbering(const MachineInstr &In, unsigned OpNum) const + -> bool; + virtual auto isFixedReg(const MachineInstr &In, unsigned OpNum) const -> bool; const TargetInstrInfo &TII; }; @@ -465,16 +467,16 @@ struct PackedRegisterRef { struct LaneMaskIndex : private IndexedSet { LaneMaskIndex() = default; - LaneBitmask getLaneMaskForIndex(uint32_t K) const { + auto getLaneMaskForIndex(uint32_t K) const -> LaneBitmask { return K == 0 ? LaneBitmask::getAll() : get(K); } - uint32_t getIndexForLaneMask(LaneBitmask LM) { + auto getIndexForLaneMask(LaneBitmask LM) -> uint32_t { assert(LM.any()); return LM.all() ? 0 : insert(LM); } - uint32_t getIndexForLaneMask(LaneBitmask LM) const { + auto getIndexForLaneMask(LaneBitmask LM) const -> uint32_t { assert(LM.any()); return LM.all() ? 0 : find(LM); } @@ -485,22 +487,24 @@ public: // Make sure this is a POD. NodeBase() = default; - uint16_t getType() const { return NodeAttrs::type(Attrs); } - uint16_t getKind() const { return NodeAttrs::kind(Attrs); } - uint16_t getFlags() const { return NodeAttrs::flags(Attrs); } - NodeId getNext() const { return Next; } + auto getType() const -> uint16_t { return NodeAttrs::type(Attrs); } + auto getKind() const -> uint16_t { return NodeAttrs::kind(Attrs); } + auto getFlags() const -> uint16_t { return NodeAttrs::flags(Attrs); } + auto getNext() const -> NodeId { return Next; } - uint16_t getAttrs() const { return Attrs; } - void setAttrs(uint16_t A) { Attrs = A; } - void setFlags(uint16_t F) { setAttrs(NodeAttrs::set_flags(getAttrs(), F)); } + auto getAttrs() const -> uint16_t { return Attrs; } + auto setAttrs(uint16_t A) -> void { Attrs = A; } + auto setFlags(uint16_t F) -> void { + setAttrs(NodeAttrs::set_flags(getAttrs(), F)); + } // Insert node NA after "this" in the circular chain. - void append(Node NA); + auto append(Node NA) -> void; // Initialize all members to 0. - void init() { memset(this, 0, sizeof *this); } + auto init() -> void { memset(this, 0, sizeof *this); } - void setNext(NodeId N) { Next = N; } + auto setNext(NodeId N) -> void { Next = N; } protected: uint16_t Attrs; @@ -549,108 +553,117 @@ using NodeSet = std::set; struct RefNode : public NodeBase { RefNode() = default; - RegisterRef getRegRef(const DataFlowGraph &G) const; + auto getRegRef(const DataFlowGraph &G) const -> RegisterRef; - MachineOperand &getOp() { + auto getOp() -> MachineOperand & { assert(!(getFlags() & NodeAttrs::PhiRef)); return *RefData.Op; } - void setRegRef(RegisterRef RR, DataFlowGraph &G); - void setRegRef(MachineOperand *Op, DataFlowGraph &G); + auto setRegRef(RegisterRef RR, DataFlowGraph &G) -> void; + auto setRegRef(MachineOperand *Op, DataFlowGraph &G) -> void; - NodeId getReachingDef() const { return RefData.RD; } - void setReachingDef(NodeId RD) { RefData.RD = RD; } + auto getReachingDef() const -> NodeId { return RefData.RD; } + auto setReachingDef(NodeId RD) -> void { RefData.RD = RD; } - NodeId getSibling() const { return RefData.Sib; } - void setSibling(NodeId Sib) { RefData.Sib = Sib; } + auto getSibling() const -> NodeId { return RefData.Sib; } + auto setSibling(NodeId Sib) -> void { RefData.Sib = Sib; } - bool isUse() const { + auto isUse() const -> bool { assert(getType() == NodeAttrs::Ref); return getKind() == NodeAttrs::Use; } - bool isDef() const { + auto isDef() const -> bool { assert(getType() == NodeAttrs::Ref); return getKind() == NodeAttrs::Def; } template - Ref getNextRef(RegisterRef RR, Predicate P, bool NextOnly, - const DataFlowGraph &G); - Node getOwner(const DataFlowGraph &G); + auto getNextRef(RegisterRef RR, Predicate P, bool NextOnly, + const DataFlowGraph &G) -> Ref; + auto getOwner(const DataFlowGraph &G) -> Node; }; struct DefNode : public RefNode { - NodeId getReachedDef() const { return RefData.Def.DD; } - void setReachedDef(NodeId D) { RefData.Def.DD = D; } - NodeId getReachedUse() const { return RefData.Def.DU; } - void setReachedUse(NodeId U) { RefData.Def.DU = U; } + auto getReachedDef() const -> NodeId { // + return RefData.Def.DD; + } + auto setReachedDef(NodeId D) -> void { // + RefData.Def.DD = D; + } + auto getReachedUse() const -> NodeId { // + return RefData.Def.DU; + } + auto setReachedUse(NodeId U) -> void { // + RefData.Def.DU = U; + } - void linkToDef(NodeId Self, Def DA); + auto linkToDef(NodeId Self, Def DA) -> void; }; struct UseNode : public RefNode { - void linkToDef(NodeId Self, Def DA); + auto linkToDef(NodeId Self, Def DA) -> void; }; struct PhiUseNode : public UseNode { - NodeId getPredecessor() const { + auto getPredecessor() const -> NodeId { assert(getFlags() & NodeAttrs::PhiRef); return RefData.PhiU.PredB; } - void setPredecessor(NodeId B) { + auto setPredecessor(NodeId B) -> void { assert(getFlags() & NodeAttrs::PhiRef); RefData.PhiU.PredB = B; } }; struct CodeNode : public NodeBase { - template T getCode() const { // + template auto getCode() const -> T { return static_cast(CodeData.CP); } - void setCode(void *C) { CodeData.CP = C; } + auto setCode(void *C) -> void { CodeData.CP = C; } - Node getFirstMember(const DataFlowGraph &G) const; - Node getLastMember(const DataFlowGraph &G) const; - void addMember(Node NA, const DataFlowGraph &G); - void addMemberAfter(Node MA, Node NA, const DataFlowGraph &G); - void removeMember(Node NA, const DataFlowGraph &G); + auto getFirstMember(const DataFlowGraph &G) const -> Node; + auto getLastMember(const DataFlowGraph &G) const -> Node; + auto addMember(Node NA, const DataFlowGraph &G) -> void; + auto addMemberAfter(Node MA, Node NA, const DataFlowGraph &G) -> void; + auto removeMember(Node NA, const DataFlowGraph &G) -> void; - NodeList members(const DataFlowGraph &G) const; + auto members(const DataFlowGraph &G) const -> NodeList; template - NodeList members_if(Predicate P, const DataFlowGraph &G) const; + auto members_if(Predicate P, const DataFlowGraph &G) const -> NodeList; }; struct InstrNode : public CodeNode { - Node getOwner(const DataFlowGraph &G); + auto getOwner(const DataFlowGraph &G) -> Node; }; struct PhiNode : public InstrNode { - MachineInstr *getCode() const { return nullptr; } + auto getCode() const -> MachineInstr * { return nullptr; } }; struct StmtNode : public InstrNode { - MachineInstr *getCode() const { // + auto getCode() const -> MachineInstr * { return CodeNode::getCode(); } }; struct BlockNode : public CodeNode { - MachineBasicBlock *getCode() const { + auto getCode() const -> MachineBasicBlock * { return CodeNode::getCode(); } - void addPhi(Phi PA, const DataFlowGraph &G); + auto addPhi(Phi PA, const DataFlowGraph &G) -> void; }; struct FuncNode : public CodeNode { - MachineFunction *getCode() const { + auto getCode() const -> MachineFunction * { return CodeNode::getCode(); } - Block findBlock(const MachineBasicBlock *BB, const DataFlowGraph &G) const; - Block getEntryBlock(const DataFlowGraph &G); + auto findBlock(const MachineBasicBlock *BB, const DataFlowGraph &G) const + -> Block; + auto getEntryBlock(const DataFlowGraph &G) -> Block; }; struct DataFlowGraph { @@ -662,55 +675,59 @@ struct DataFlowGraph { const MachineDominanceFrontier &mdf, const TargetOperandInfo &toi); - NodeBase *ptr(NodeId N) const; - template T ptr(NodeId N) const { // + auto ptr(NodeId N) const -> NodeBase *; + template auto ptr(NodeId N) const -> T { return static_cast(ptr(N)); } - NodeId id(const NodeBase *P) const; + auto id(const NodeBase *P) const -> NodeId; - template NodeAddr addr(NodeId N) const { + template auto addr(NodeId N) const -> NodeAddr { return {ptr(N), N}; } - Func getFunc() const { return TheFunc; } - MachineFunction &getMF() const { return MF; } - const TargetInstrInfo &getTII() const { return TII; } - const TargetRegisterInfo &getTRI() const { return TRI; } - const PhysicalRegisterInfo &getPRI() const { return PRI; } - const MachineDominatorTree &getDT() const { return MDT; } - const MachineDominanceFrontier &getDF() const { return MDF; } - const RegisterAggr &getLiveIns() const { return LiveIns; } + auto getFunc() const -> Func { return TheFunc; } + auto getMF() const -> MachineFunction & { return MF; } + auto getTII() const -> const TargetInstrInfo & { return TII; } + auto getTRI() const -> const TargetRegisterInfo & { return TRI; } + auto getPRI() const -> const PhysicalRegisterInfo & { return PRI; } + auto getDT() const -> const MachineDominatorTree & { return MDT; } + auto getDF() const -> const MachineDominanceFrontier & { return MDF; } + auto getLiveIns() const -> const RegisterAggr & { return LiveIns; } struct DefStack { DefStack() = default; - bool empty() const { return Stack.empty() || top() == bottom(); } + auto empty() const -> bool { return Stack.empty() || top() == bottom(); } private: using value_type = Def; struct Iterator { using value_type = DefStack::value_type; - Iterator &up() { + auto up() -> Iterator & { Pos = DS.nextUp(Pos); return *this; } - Iterator &down() { + auto down() -> Iterator & { Pos = DS.nextDown(Pos); return *this; } - value_type operator*() const { + auto operator*() const -> value_type { assert(Pos >= 1); return DS.Stack[Pos - 1]; } - const value_type *operator->() const { + auto operator->() const -> const value_type * { assert(Pos >= 1); return &DS.Stack[Pos - 1]; } - bool operator==(const Iterator &It) const { return Pos == It.Pos; } - bool operator!=(const Iterator &It) const { return Pos != It.Pos; } + auto operator==(const Iterator &It) const -> bool { + return Pos == It.Pos; + } + auto operator!=(const Iterator &It) const -> bool { + return Pos != It.Pos; + } private: friend struct DefStack; @@ -726,26 +743,27 @@ struct DataFlowGraph { public: using iterator = Iterator; - iterator top() const { return Iterator(*this, true); } - iterator bottom() const { return Iterator(*this, false); } - unsigned size() const; + auto top() const -> iterator { return Iterator(*this, true); } + auto bottom() const -> iterator { return Iterator(*this, false); } + auto size() const -> unsigned; - void push(Def DA) { Stack.push_back(DA); } - void pop(); - void start_block(NodeId N); - void clear_block(NodeId N); + auto push(Def DA) -> void { Stack.push_back(DA); } + auto pop() -> void; + auto start_block(NodeId N) -> void; + auto clear_block(NodeId N) -> void; private: friend struct Iterator; using StorageType = std::vector; - bool isDelimiter(const StorageType::value_type &P, NodeId N = 0) const { + auto isDelimiter(const StorageType::value_type &P, NodeId N = 0) const + -> bool { return (P.Addr == nullptr) && (N == 0 || P.Id == N); } - unsigned nextUp(unsigned P) const; - unsigned nextDown(unsigned P) const; + auto nextUp(unsigned P) const -> unsigned; + auto nextDown(unsigned P) const -> unsigned; StorageType Stack; }; @@ -754,111 +772,118 @@ struct DataFlowGraph { // Map: Register (physical or virtual) -> DefStack using DefStackMap = std::unordered_map; - void build(unsigned Options = BuildOptions::None); - void pushAllDefs(Instr IA, DefStackMap &DM); - void markBlock(NodeId B, DefStackMap &DefM); - void releaseBlock(NodeId B, DefStackMap &DefM); + auto build(unsigned Options = BuildOptions::None) -> void; + auto pushAllDefs(Instr IA, DefStackMap &DM) -> void; + auto markBlock(NodeId B, DefStackMap &DefM) -> void; + auto releaseBlock(NodeId B, DefStackMap &DefM) -> void; - PackedRegisterRef pack(RegisterRef RR) { + auto pack(RegisterRef RR) -> PackedRegisterRef { return {RR.Reg, LMI.getIndexForLaneMask(RR.Mask)}; } - PackedRegisterRef pack(RegisterRef RR) const { + auto pack(RegisterRef RR) const -> PackedRegisterRef { return {RR.Reg, LMI.getIndexForLaneMask(RR.Mask)}; } - RegisterRef unpack(PackedRegisterRef PR) const { + auto unpack(PackedRegisterRef PR) const -> RegisterRef { return RegisterRef(PR.Reg, LMI.getLaneMaskForIndex(PR.MaskId)); } - RegisterRef makeRegRef(unsigned Reg, unsigned Sub) const; - RegisterRef makeRegRef(const MachineOperand &Op) const; + auto makeRegRef(unsigned Reg, unsigned Sub) const -> RegisterRef; + auto makeRegRef(const MachineOperand &Op) const -> RegisterRef; - Ref getNextRelated(Instr IA, Ref RA) const; - Ref getNextShadow(Instr IA, Ref RA, bool Create); - Ref getNextShadow(Instr IA, Ref RA) const; + auto getNextRelated(Instr IA, Ref RA) const -> Ref; + auto getNextShadow(Instr IA, Ref RA, bool Create) -> Ref; + auto getNextShadow(Instr IA, Ref RA) const -> Ref; - NodeList getRelatedRefs(Instr IA, Ref RA) const; + auto getRelatedRefs(Instr IA, Ref RA) const -> NodeList; - Block findBlock(MachineBasicBlock *BB) const { return BlockNodes.at(BB); } + auto findBlock(MachineBasicBlock *BB) const -> Block { + return BlockNodes.at(BB); + } - void unlinkUse(Use UA, bool RemoveFromOwner) { + auto unlinkUse(Use UA, bool RemoveFromOwner) -> void { unlinkUseDF(UA); if (RemoveFromOwner) removeFromOwner(UA); } - void unlinkDef(Def DA, bool RemoveFromOwner) { + auto unlinkDef(Def DA, bool RemoveFromOwner) -> void { unlinkDefDF(DA); if (RemoveFromOwner) removeFromOwner(DA); } // Some useful filters. - template static bool IsRef(const Node BA) { + template static auto IsRef(const Node BA) -> bool { return BA.Addr->getType() == NodeAttrs::Ref && BA.Addr->getKind() == Kind; } - template static bool IsCode(const Node BA) { + template static auto IsCode(const Node BA) -> bool { return BA.Addr->getType() == NodeAttrs::Code && BA.Addr->getKind() == Kind; } - static bool IsDef(const Node BA) { + static auto IsDef(const Node BA) -> bool { return BA.Addr->getType() == NodeAttrs::Ref && BA.Addr->getKind() == NodeAttrs::Def; } - static bool IsUse(const Node BA) { + static auto IsUse(const Node BA) -> bool { return BA.Addr->getType() == NodeAttrs::Ref && BA.Addr->getKind() == NodeAttrs::Use; } - static bool IsPhi(const Node BA) { + static auto IsPhi(const Node BA) -> bool { return BA.Addr->getType() == NodeAttrs::Code && BA.Addr->getKind() == NodeAttrs::Phi; } - static bool IsPreservingDef(const Def DA) { + static auto IsPreservingDef(const Def DA) -> bool { uint16_t Flags = DA.Addr->getFlags(); return (Flags & NodeAttrs::Preserving) && !(Flags & NodeAttrs::Undef); } private: - void reset(); + auto reset() -> void; - RegisterAggr getLandingPadLiveIns() const; + auto getLandingPadLiveIns() const -> RegisterAggr; - Node newNode(uint16_t Attrs); - Node cloneNode(const Node B); - Use newUse(Instr Owner, MachineOperand &Op, uint16_t Flags = NodeAttrs::None); - PhiUse newPhiUse(Phi Owner, RegisterRef RR, Block PredB, - uint16_t Flags = NodeAttrs::PhiRef); - Def newDef(Instr Owner, MachineOperand &Op, uint16_t Flags = NodeAttrs::None); - Def newDef(Instr Owner, RegisterRef RR, uint16_t Flags = NodeAttrs::PhiRef); - Phi newPhi(Block Owner); - Stmt newStmt(Block Owner, MachineInstr *MI); - Block newBlock(Func Owner, MachineBasicBlock *BB); - Func newFunc(MachineFunction *MF); + auto newNode(uint16_t Attrs) -> Node; + auto cloneNode(const Node B) -> Node; + auto newUse(Instr Owner, MachineOperand &Op, uint16_t Flags = NodeAttrs::None) + -> Use; + auto newPhiUse(Phi Owner, RegisterRef RR, Block PredB, + uint16_t Flags = NodeAttrs::PhiRef) -> PhiUse; + auto newDef(Instr Owner, MachineOperand &Op, uint16_t Flags = NodeAttrs::None) + -> Def; + auto newDef(Instr Owner, RegisterRef RR, uint16_t Flags = NodeAttrs::PhiRef) + -> Def; + auto newPhi(Block Owner) -> Phi; + auto newStmt(Block Owner, MachineInstr *MI) -> Stmt; + auto newBlock(Func Owner, MachineBasicBlock *BB) -> Block; + auto newFunc(MachineFunction *MF) -> Func; template - std::pair locateNextRef(Instr IA, Ref RA, Predicate P) const; + auto locateNextRef(Instr IA, Ref RA, Predicate P) const + -> std::pair; using BlockRefsMap = RegisterAggrMap; - void buildStmt(Block BA, MachineInstr &In); - void recordDefsForDF(BlockRefsMap &PhiM, Block BA); - void buildPhis(BlockRefsMap &PhiM, RegisterSet &AllRefs, Block BA); - void removeUnusedPhis(); + auto buildStmt(Block BA, MachineInstr &In) -> void; + auto recordDefsForDF(BlockRefsMap &PhiM, Block BA) -> void; + auto buildPhis(BlockRefsMap &PhiM, RegisterSet &AllRefs, Block BA) -> void; + auto removeUnusedPhis() -> void; - void pushClobbers(Instr IA, DefStackMap &DM); - void pushDefs(Instr IA, DefStackMap &DM); - template void linkRefUp(Instr IA, NodeAddr TA, DefStack &DS); + auto pushClobbers(Instr IA, DefStackMap &DM) -> void; + auto pushDefs(Instr IA, DefStackMap &DM) -> void; + template + auto linkRefUp(Instr IA, NodeAddr TA, DefStack &DS) -> void; template - void linkStmtRefs(DefStackMap &DefM, Stmt SA, Predicate P); - void linkBlockRefs(DefStackMap &DefM, Block BA); + auto linkStmtRefs(DefStackMap &DefM, Stmt SA, Predicate P) -> void; + auto linkBlockRefs(DefStackMap &DefM, Block BA) -> void; - void unlinkUseDF(Use UA); - void unlinkDefDF(Def DA); + auto unlinkUseDF(Use UA) -> void; + auto unlinkDefDF(Def DA) -> void; - void removeFromOwner(Ref RA) { + auto removeFromOwner(Ref RA) -> void { Instr IA = RA.Addr->getOwner(*this); IA.Addr->removeMember(RA, *this); } @@ -884,8 +909,8 @@ private: }; // struct DataFlowGraph template -Ref RefNode::getNextRef(RegisterRef RR, Predicate P, bool NextOnly, - const DataFlowGraph &G) { +auto RefNode::getNextRef(RegisterRef RR, Predicate P, bool NextOnly, + const DataFlowGraph &G) -> Ref { // Get the "Next" reference in the circular list that references RR and // satisfies predicate "Pred". auto NA = G.addr(getNext()); @@ -910,7 +935,8 @@ Ref RefNode::getNextRef(RegisterRef RR, Predicate P, bool NextOnly, } template -NodeList CodeNode::members_if(Predicate P, const DataFlowGraph &G) const { +auto CodeNode::members_if(Predicate P, const DataFlowGraph &G) const + -> NodeList { NodeList MM; auto M = getFirstMember(G); if (M.Id == 0) @@ -938,23 +964,23 @@ template struct PrintNode : Print> { : Print>(x, g) {} }; -raw_ostream &operator<<(raw_ostream &OS, const Print &P); -raw_ostream &operator<<(raw_ostream &OS, const Print &P); -raw_ostream &operator<<(raw_ostream &OS, const Print &P); -raw_ostream &operator<<(raw_ostream &OS, const Print &P); -raw_ostream &operator<<(raw_ostream &OS, const Print &P); -raw_ostream &operator<<(raw_ostream &OS, const Print &P); -raw_ostream &operator<<(raw_ostream &OS, const Print &P); -raw_ostream &operator<<(raw_ostream &OS, const Print &P); -raw_ostream &operator<<(raw_ostream &OS, const Print &P); -raw_ostream &operator<<(raw_ostream &OS, const Print &P); -raw_ostream &operator<<(raw_ostream &OS, const Print &P); -raw_ostream &operator<<(raw_ostream &OS, const Print &P); -raw_ostream &operator<<(raw_ostream &OS, const Print &P); -raw_ostream &operator<<(raw_ostream &OS, const Print &P); -raw_ostream &operator<<(raw_ostream &OS, const Print &P); -raw_ostream &operator<<(raw_ostream &OS, - const Print &P); +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream &; +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream &; +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream &; +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream &; +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream &; +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream &; +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream &; +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream &; +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream &; +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream &; +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream &; +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream &; +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream &; +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream &; +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream &; +auto operator<<(raw_ostream &OS, const Print &P) + -> raw_ostream &; } // end namespace rdf diff --git a/llvm/lib/CodeGen/RDFGraph.cpp b/llvm/lib/CodeGen/RDFGraph.cpp index 1b1c34f475c1..b4254e45f871 100644 --- a/llvm/lib/CodeGen/RDFGraph.cpp +++ b/llvm/lib/CodeGen/RDFGraph.cpp @@ -46,12 +46,12 @@ using namespace rdf; namespace llvm { namespace rdf { -raw_ostream &operator<<(raw_ostream &OS, const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream & { P.G.getPRI().print(OS, P.Obj); return OS; } -raw_ostream &operator<<(raw_ostream &OS, const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream & { auto NA = P.G.addr(P.Obj); uint16_t Attrs = NA.Addr->getAttrs(); uint16_t Kind = NodeAttrs::kind(Attrs); @@ -110,14 +110,14 @@ raw_ostream &operator<<(raw_ostream &OS, const Print &P) { return OS; } -static void printRefHeader(raw_ostream &OS, const Ref RA, - const DataFlowGraph &G) { +static auto printRefHeader(raw_ostream &OS, const Ref RA, + const DataFlowGraph &G) -> void { OS << Print(RA.Id, G) << '<' << Print(RA.Addr->getRegRef(G), G) << '>'; if (RA.Addr->getFlags() & NodeAttrs::Fixed) OS << '!'; } -raw_ostream &operator<<(raw_ostream &OS, const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream & { printRefHeader(OS, P.Obj, P.G); OS << '('; if (NodeId N = P.Obj.Addr->getReachingDef()) @@ -134,7 +134,7 @@ raw_ostream &operator<<(raw_ostream &OS, const Print &P) { return OS; } -raw_ostream &operator<<(raw_ostream &OS, const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream & { printRefHeader(OS, P.Obj, P.G); OS << '('; if (NodeId N = P.Obj.Addr->getReachingDef()) @@ -145,7 +145,7 @@ raw_ostream &operator<<(raw_ostream &OS, const Print &P) { return OS; } -raw_ostream &operator<<(raw_ostream &OS, const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream & { printRefHeader(OS, P.Obj, P.G); OS << '('; if (NodeId N = P.Obj.Addr->getReachingDef()) @@ -159,7 +159,7 @@ raw_ostream &operator<<(raw_ostream &OS, const Print &P) { return OS; } -raw_ostream &operator<<(raw_ostream &OS, const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream & { switch (P.Obj.Addr->getKind()) { case NodeAttrs::Def: OS << PrintNode(P.Obj, P.G); @@ -174,7 +174,7 @@ raw_ostream &operator<<(raw_ostream &OS, const Print &P) { return OS; } -raw_ostream &operator<<(raw_ostream &OS, const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream & { unsigned N = P.Obj.size(); for (auto I : P.Obj) { OS << Print(I.Id, P.G); @@ -184,7 +184,7 @@ raw_ostream &operator<<(raw_ostream &OS, const Print &P) { return OS; } -raw_ostream &operator<<(raw_ostream &OS, const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream & { unsigned N = P.Obj.size(); for (auto I : P.Obj) { OS << Print(I, P.G); @@ -205,7 +205,7 @@ template struct PrintListV { }; template -raw_ostream &operator<<(raw_ostream &OS, const PrintListV &P) { +auto operator<<(raw_ostream &OS, const PrintListV &P) -> raw_ostream & { unsigned N = P.List.size(); for (NodeAddr A : P.List) { OS << PrintNode(A, P.G); @@ -217,13 +217,13 @@ raw_ostream &operator<<(raw_ostream &OS, const PrintListV &P) { } // end anonymous namespace -raw_ostream &operator<<(raw_ostream &OS, const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream & { OS << Print(P.Obj.Id, P.G) << ": phi [" << PrintListV(P.Obj.Addr->members(P.G), P.G) << ']'; return OS; } -raw_ostream &operator<<(raw_ostream &OS, const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream & { const MachineInstr &MI = *P.Obj.Addr->getCode(); unsigned Opc = MI.getOpcode(); OS << Print(P.Obj.Id, P.G) << ": " << P.G.getTII().getName(Opc); @@ -247,7 +247,7 @@ raw_ostream &operator<<(raw_ostream &OS, const Print &P) { return OS; } -raw_ostream &operator<<(raw_ostream &OS, const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream & { switch (P.Obj.Addr->getKind()) { case NodeAttrs::Phi: OS << PrintNode(P.Obj, P.G); @@ -262,7 +262,7 @@ raw_ostream &operator<<(raw_ostream &OS, const Print &P) { return OS; } -raw_ostream &operator<<(raw_ostream &OS, const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream & { MachineBasicBlock *BB = P.Obj.Addr->getCode(); unsigned NP = BB->pred_size(); std::vector Ns; @@ -294,7 +294,7 @@ raw_ostream &operator<<(raw_ostream &OS, const Print &P) { return OS; } -raw_ostream &operator<<(raw_ostream &OS, const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream & { OS << "DFG dump:[\n" << Print(P.Obj.Id, P.G) << ": Function: " << P.Obj.Addr->getCode()->getName() << '\n'; @@ -304,7 +304,7 @@ raw_ostream &operator<<(raw_ostream &OS, const Print &P) { return OS; } -raw_ostream &operator<<(raw_ostream &OS, const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) -> raw_ostream & { OS << '{'; for (auto I : P.Obj) OS << ' ' << Print(I, P.G); @@ -312,13 +312,14 @@ raw_ostream &operator<<(raw_ostream &OS, const Print &P) { return OS; } -raw_ostream &operator<<(raw_ostream &OS, const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) + -> raw_ostream & { OS << P.Obj; return OS; } -raw_ostream &operator<<(raw_ostream &OS, - const Print &P) { +auto operator<<(raw_ostream &OS, const Print &P) + -> raw_ostream & { for (auto I = P.Obj.top(), E = P.Obj.bottom(); I != E;) { OS << Print(I->Id, P.G) << '<' << Print(I->Addr->getRegRef(P.G), P.G) << '>'; @@ -341,7 +342,7 @@ raw_ostream &operator<<(raw_ostream &OS, // There is a mapping scheme between node id and its location in a block, // and within that block is described in the header file. // -void NodeAllocator::startNewBlock() { +auto NodeAllocator::startNewBlock() -> void { void *T = MemPool.Allocate(NodesPerBlock * NodeMemSize, NodeMemSize); char *P = static_cast(T); Blocks.push_back(P); @@ -353,7 +354,7 @@ void NodeAllocator::startNewBlock() { ActiveEnd = P; } -bool NodeAllocator::needNewBlock() { +auto NodeAllocator::needNewBlock() -> bool { if (Blocks.empty()) return true; @@ -362,7 +363,7 @@ bool NodeAllocator::needNewBlock() { return Index >= NodesPerBlock; } -Node NodeAllocator::New() { +auto NodeAllocator::New() -> Node { if (needNewBlock()) startNewBlock(); @@ -373,7 +374,7 @@ Node NodeAllocator::New() { return NA; } -NodeId NodeAllocator::id(const NodeBase *P) const { +auto NodeAllocator::id(const NodeBase *P) const -> NodeId { uintptr_t A = reinterpret_cast(P); for (unsigned i = 0, n = Blocks.size(); i != n; ++i) { uintptr_t B = reinterpret_cast(Blocks[i]); @@ -385,14 +386,14 @@ NodeId NodeAllocator::id(const NodeBase *P) const { llvm_unreachable("Invalid node address"); } -void NodeAllocator::clear() { +auto NodeAllocator::clear() -> void { MemPool.Reset(); Blocks.clear(); ActiveEnd = nullptr; } // Insert node NA after "this" in the circular chain. -void NodeBase::append(Node NA) { +auto NodeBase::append(Node NA) -> void { NodeId Nx = Next; // If NA is already "next", do nothing. if (Next != NA.Id) { @@ -404,7 +405,7 @@ void NodeBase::append(Node NA) { // Fundamental node manipulator functions. // Obtain the register reference from a reference node. -RegisterRef RefNode::getRegRef(const DataFlowGraph &G) const { +auto RefNode::getRegRef(const DataFlowGraph &G) const -> RegisterRef { assert(NodeAttrs::type(Attrs) == NodeAttrs::Ref); if (NodeAttrs::flags(Attrs) & NodeAttrs::PhiRef) return G.unpack(RefData.PR); @@ -414,7 +415,7 @@ RegisterRef RefNode::getRegRef(const DataFlowGraph &G) const { // Set the register reference in the reference node directly (for references // in phi nodes). -void RefNode::setRegRef(RegisterRef RR, DataFlowGraph &G) { +auto RefNode::setRegRef(RegisterRef RR, DataFlowGraph &G) -> void { assert(NodeAttrs::type(Attrs) == NodeAttrs::Ref); assert(NodeAttrs::flags(Attrs) & NodeAttrs::PhiRef); RefData.PR = G.pack(RR); @@ -422,7 +423,7 @@ void RefNode::setRegRef(RegisterRef RR, DataFlowGraph &G) { // Set the register reference in the reference node based on a machine // operand (for references in statement nodes). -void RefNode::setRegRef(MachineOperand *Op, DataFlowGraph &G) { +auto RefNode::setRegRef(MachineOperand *Op, DataFlowGraph &G) -> void { assert(NodeAttrs::type(Attrs) == NodeAttrs::Ref); assert(!(NodeAttrs::flags(Attrs) & NodeAttrs::PhiRef)); (void)G; @@ -430,7 +431,7 @@ void RefNode::setRegRef(MachineOperand *Op, DataFlowGraph &G) { } // Get the owner of a given reference node. -Node RefNode::getOwner(const DataFlowGraph &G) { +auto RefNode::getOwner(const DataFlowGraph &G) -> Node { Node NA = G.addr(getNext()); while (NA.Addr != this) { @@ -442,35 +443,35 @@ Node RefNode::getOwner(const DataFlowGraph &G) { } // Connect the def node to the reaching def node. -void DefNode::linkToDef(NodeId Self, Def DA) { +auto DefNode::linkToDef(NodeId Self, Def DA) -> void { RefData.RD = DA.Id; RefData.Sib = DA.Addr->getReachedDef(); DA.Addr->setReachedDef(Self); } // Connect the use node to the reaching def node. -void UseNode::linkToDef(NodeId Self, Def DA) { +auto UseNode::linkToDef(NodeId Self, Def DA) -> void { RefData.RD = DA.Id; RefData.Sib = DA.Addr->getReachedUse(); DA.Addr->setReachedUse(Self); } // Get the first member of the code node. -Node CodeNode::getFirstMember(const DataFlowGraph &G) const { +auto CodeNode::getFirstMember(const DataFlowGraph &G) const -> Node { if (CodeData.FirstM == 0) return Node(); return G.addr(CodeData.FirstM); } // Get the last member of the code node. -Node CodeNode::getLastMember(const DataFlowGraph &G) const { +auto CodeNode::getLastMember(const DataFlowGraph &G) const -> Node { if (CodeData.LastM == 0) return Node(); return G.addr(CodeData.LastM); } // Add node NA at the end of the member list of the given code node. -void CodeNode::addMember(Node NA, const DataFlowGraph &G) { +auto CodeNode::addMember(Node NA, const DataFlowGraph &G) -> void { Node ML = getLastMember(G); if (ML.Id != 0) { ML.Addr->append(NA); @@ -483,14 +484,15 @@ void CodeNode::addMember(Node NA, const DataFlowGraph &G) { } // Add node NA after member node MA in the given code node. -void CodeNode::addMemberAfter(Node MA, Node NA, const DataFlowGraph &G) { +auto CodeNode::addMemberAfter(Node MA, Node NA, const DataFlowGraph &G) + -> void { MA.Addr->append(NA); if (CodeData.LastM == MA.Id) CodeData.LastM = NA.Id; } // Remove member node NA from the given code node. -void CodeNode::removeMember(Node NA, const DataFlowGraph &G) { +auto CodeNode::removeMember(Node NA, const DataFlowGraph &G) -> void { Node MA = getFirstMember(G); assert(MA.Id != 0); @@ -522,13 +524,13 @@ void CodeNode::removeMember(Node NA, const DataFlowGraph &G) { } // Return the list of all members of the code node. -NodeList CodeNode::members(const DataFlowGraph &G) const { +auto CodeNode::members(const DataFlowGraph &G) const -> NodeList { static auto True = [](Node) -> bool { return true; }; return members_if(True, G); } // Return the owner of the given instr node. -Node InstrNode::getOwner(const DataFlowGraph &G) { +auto InstrNode::getOwner(const DataFlowGraph &G) -> Node { Node NA = G.addr(getNext()); while (NA.Addr != this) { @@ -541,7 +543,7 @@ Node InstrNode::getOwner(const DataFlowGraph &G) { } // Add the phi node PA to the given block node. -void BlockNode::addPhi(Phi PA, const DataFlowGraph &G) { +auto BlockNode::addPhi(Phi PA, const DataFlowGraph &G) -> void { Node M = getFirstMember(G); if (M.Id == 0) { addMember(PA, G); @@ -571,8 +573,8 @@ void BlockNode::addPhi(Phi PA, const DataFlowGraph &G) { // Find the block node corresponding to the machine basic block BB in the // given func node. -Block FuncNode::findBlock(const MachineBasicBlock *BB, - const DataFlowGraph &G) const { +auto FuncNode::findBlock(const MachineBasicBlock *BB, + const DataFlowGraph &G) const -> Block { auto EqBB = [BB](Node NA) -> bool { return Block(NA).Addr->getCode() == BB; }; NodeList Ms = members_if(EqBB, G); if (!Ms.empty()) @@ -581,7 +583,7 @@ Block FuncNode::findBlock(const MachineBasicBlock *BB, } // Get the block node for the entry block in the given function. -Block FuncNode::getEntryBlock(const DataFlowGraph &G) { +auto FuncNode::getEntryBlock(const DataFlowGraph &G) -> Block { MachineBasicBlock *EntryB = &getCode()->front(); return findBlock(EntryB, G); } @@ -591,14 +593,14 @@ Block FuncNode::getEntryBlock(const DataFlowGraph &G) { // For a given instruction, check if there are any bits of RR that can remain // unchanged across this def. -bool TargetOperandInfo::isPreserving(const MachineInstr &In, - unsigned OpNum) const { +auto TargetOperandInfo::isPreserving(const MachineInstr &In, + unsigned OpNum) const -> bool { return TII.isPredicated(In); } // Check if the definition of RR produces an unspecified value. -bool TargetOperandInfo::isClobbering(const MachineInstr &In, - unsigned OpNum) const { +auto TargetOperandInfo::isClobbering(const MachineInstr &In, + unsigned OpNum) const -> bool { const MachineOperand &Op = In.getOperand(OpNum); if (Op.isRegMask()) return true; @@ -610,8 +612,8 @@ bool TargetOperandInfo::isClobbering(const MachineInstr &In, } // Check if the given instruction specifically requires -bool TargetOperandInfo::isFixedReg(const MachineInstr &In, - unsigned OpNum) const { +auto TargetOperandInfo::isFixedReg(const MachineInstr &In, unsigned OpNum) const + -> bool { if (In.isCall() || In.isReturn() || In.isInlineAsm()) return true; // Check for a tail call. @@ -676,7 +678,7 @@ DataFlowGraph::DefStack::Iterator::Iterator(const DataFlowGraph::DefStack &S, } // Return the size of the stack, including block delimiters. -unsigned DataFlowGraph::DefStack::size() const { +auto DataFlowGraph::DefStack::size() const -> unsigned { unsigned S = 0; for (auto I = top(), E = bottom(); I != E; I.down()) S++; @@ -686,14 +688,14 @@ unsigned DataFlowGraph::DefStack::size() const { // Remove the top entry from the stack. Remove all intervening delimiters // so that after this, the stack is either empty, or the top of the stack // is a non-delimiter. -void DataFlowGraph::DefStack::pop() { +auto DataFlowGraph::DefStack::pop() -> void { assert(!empty()); unsigned P = nextDown(Stack.size()); Stack.resize(P); } // Push a delimiter for block node N on the stack. -void DataFlowGraph::DefStack::start_block(NodeId N) { +auto DataFlowGraph::DefStack::start_block(NodeId N) -> void { assert(N != 0); Stack.push_back(Def(nullptr, N)); } @@ -701,7 +703,7 @@ void DataFlowGraph::DefStack::start_block(NodeId N) { // Remove all nodes from the top of the stack, until the delimited for // block node N is encountered. Remove the delimiter as well. In effect, // this will remove from the stack all definitions from block N. -void DataFlowGraph::DefStack::clear_block(NodeId N) { +auto DataFlowGraph::DefStack::clear_block(NodeId N) -> void { assert(N != 0); unsigned P = Stack.size(); while (P > 0) { @@ -715,7 +717,7 @@ void DataFlowGraph::DefStack::clear_block(NodeId N) { } // Move the stack iterator up by one. -unsigned DataFlowGraph::DefStack::nextUp(unsigned P) const { +auto DataFlowGraph::DefStack::nextUp(unsigned P) const -> unsigned { // Get the next valid position after P (skipping all delimiters). // The input position P does not have to point to a non-delimiter. unsigned SS = Stack.size(); @@ -730,7 +732,7 @@ unsigned DataFlowGraph::DefStack::nextUp(unsigned P) const { } // Move the stack iterator down by one. -unsigned DataFlowGraph::DefStack::nextDown(unsigned P) const { +auto DataFlowGraph::DefStack::nextDown(unsigned P) const -> unsigned { // Get the preceding valid position before P (skipping all delimiters). // The input position P does not have to point to a non-delimiter. assert(P > 0 && P <= Stack.size()); @@ -746,7 +748,7 @@ unsigned DataFlowGraph::DefStack::nextDown(unsigned P) const { // Register information. -RegisterAggr DataFlowGraph::getLandingPadLiveIns() const { +auto DataFlowGraph::getLandingPadLiveIns() const -> RegisterAggr { RegisterAggr LR(getPRI()); const Function &F = MF.getFunction(); const Constant *PF = F.hasPersonalityFn() ? F.getPersonalityFn() : nullptr; @@ -763,21 +765,21 @@ RegisterAggr DataFlowGraph::getLandingPadLiveIns() const { // Node management functions. // Get the pointer to the node with the id N. -NodeBase *DataFlowGraph::ptr(NodeId N) const { +auto DataFlowGraph::ptr(NodeId N) const -> NodeBase * { if (N == 0) return nullptr; return Memory.ptr(N); } // Get the id of the node at the address P. -NodeId DataFlowGraph::id(const NodeBase *P) const { +auto DataFlowGraph::id(const NodeBase *P) const -> NodeId { if (P == nullptr) return 0; return Memory.id(P); } // Allocate a new node and set the attributes to Attrs. -Node DataFlowGraph::newNode(uint16_t Attrs) { +auto DataFlowGraph::newNode(uint16_t Attrs) -> Node { Node P = Memory.New(); P.Addr->init(); P.Addr->setAttrs(Attrs); @@ -786,7 +788,7 @@ Node DataFlowGraph::newNode(uint16_t Attrs) { // Make a copy of the given node B, except for the data-flow links, which // are set to 0. -Node DataFlowGraph::cloneNode(const Node B) { +auto DataFlowGraph::cloneNode(const Node B) -> Node { Node NA = newNode(0); memcpy(NA.Addr, B.Addr, sizeof(NodeBase)); // Ref nodes need to have the data-flow links reset. @@ -805,14 +807,15 @@ Node DataFlowGraph::cloneNode(const Node B) { // Allocation routines for specific node types/kinds. -Use DataFlowGraph::newUse(Instr Owner, MachineOperand &Op, uint16_t Flags) { +auto DataFlowGraph::newUse(Instr Owner, MachineOperand &Op, uint16_t Flags) + -> Use { Use UA = newNode(NodeAttrs::Ref | NodeAttrs::Use | Flags); UA.Addr->setRegRef(&Op, *this); return UA; } -PhiUse DataFlowGraph::newPhiUse(Phi Owner, RegisterRef RR, Block PredB, - uint16_t Flags) { +auto DataFlowGraph::newPhiUse(Phi Owner, RegisterRef RR, Block PredB, + uint16_t Flags) -> PhiUse { PhiUse PUA = newNode(NodeAttrs::Ref | NodeAttrs::Use | Flags); assert(Flags & NodeAttrs::PhiRef); PUA.Addr->setRegRef(RR, *this); @@ -820,47 +823,48 @@ PhiUse DataFlowGraph::newPhiUse(Phi Owner, RegisterRef RR, Block PredB, return PUA; } -Def DataFlowGraph::newDef(Instr Owner, MachineOperand &Op, uint16_t Flags) { +auto DataFlowGraph::newDef(Instr Owner, MachineOperand &Op, uint16_t Flags) + -> Def { Def DA = newNode(NodeAttrs::Ref | NodeAttrs::Def | Flags); DA.Addr->setRegRef(&Op, *this); return DA; } -Def DataFlowGraph::newDef(Instr Owner, RegisterRef RR, uint16_t Flags) { +auto DataFlowGraph::newDef(Instr Owner, RegisterRef RR, uint16_t Flags) -> Def { Def DA = newNode(NodeAttrs::Ref | NodeAttrs::Def | Flags); assert(Flags & NodeAttrs::PhiRef); DA.Addr->setRegRef(RR, *this); return DA; } -Phi DataFlowGraph::newPhi(Block Owner) { +auto DataFlowGraph::newPhi(Block Owner) -> Phi { Phi PA = newNode(NodeAttrs::Code | NodeAttrs::Phi); Owner.Addr->addPhi(PA, *this); return PA; } -Stmt DataFlowGraph::newStmt(Block Owner, MachineInstr *MI) { +auto DataFlowGraph::newStmt(Block Owner, MachineInstr *MI) -> Stmt { Stmt SA = newNode(NodeAttrs::Code | NodeAttrs::Stmt); SA.Addr->setCode(MI); Owner.Addr->addMember(SA, *this); return SA; } -Block DataFlowGraph::newBlock(Func Owner, MachineBasicBlock *BB) { +auto DataFlowGraph::newBlock(Func Owner, MachineBasicBlock *BB) -> Block { Block BA = newNode(NodeAttrs::Code | NodeAttrs::Block); BA.Addr->setCode(BB); Owner.Addr->addMember(BA, *this); return BA; } -Func DataFlowGraph::newFunc(MachineFunction *MF) { +auto DataFlowGraph::newFunc(MachineFunction *MF) -> Func { Func FA = newNode(NodeAttrs::Code | NodeAttrs::Func); FA.Addr->setCode(MF); return FA; } // Build the data flow graph. -void DataFlowGraph::build(unsigned Options) { +auto DataFlowGraph::build(unsigned Options) -> void { reset(); TheFunc = newFunc(&MF); @@ -956,7 +960,8 @@ void DataFlowGraph::build(unsigned Options) { removeUnusedPhis(); } -RegisterRef DataFlowGraph::makeRegRef(unsigned Reg, unsigned Sub) const { +auto DataFlowGraph::makeRegRef(unsigned Reg, unsigned Sub) const + -> RegisterRef { assert(RegisterRef::isRegId(Reg) || RegisterRef::isMaskId(Reg)); assert(Reg != 0); if (Sub != 0) @@ -964,7 +969,7 @@ RegisterRef DataFlowGraph::makeRegRef(unsigned Reg, unsigned Sub) const { return RegisterRef(Reg); } -RegisterRef DataFlowGraph::makeRegRef(const MachineOperand &Op) const { +auto DataFlowGraph::makeRegRef(const MachineOperand &Op) const -> RegisterRef { assert(Op.isReg() || Op.isRegMask()); if (Op.isReg()) return makeRegRef(Op.getReg(), Op.getSubReg()); @@ -973,14 +978,14 @@ RegisterRef DataFlowGraph::makeRegRef(const MachineOperand &Op) const { } // For each stack in the map DefM, push the delimiter for block B on it. -void DataFlowGraph::markBlock(NodeId B, DefStackMap &DefM) { +auto DataFlowGraph::markBlock(NodeId B, DefStackMap &DefM) -> void { // Push block delimiters. for (auto &P : DefM) P.second.start_block(B); } // Remove all definitions coming from block B from each stack in DefM. -void DataFlowGraph::releaseBlock(NodeId B, DefStackMap &DefM) { +auto DataFlowGraph::releaseBlock(NodeId B, DefStackMap &DefM) -> void { // Pop all defs from this block from the definition stack. Defs that were // added to the map during the traversal of instructions will not have a // delimiter, but for those, the whole stack will be emptied. @@ -998,14 +1003,14 @@ void DataFlowGraph::releaseBlock(NodeId B, DefStackMap &DefM) { // Push all definitions from the instruction node IA to an appropriate // stack in DefM. -void DataFlowGraph::pushAllDefs(Instr IA, DefStackMap &DefM) { +auto DataFlowGraph::pushAllDefs(Instr IA, DefStackMap &DefM) -> void { pushClobbers(IA, DefM); pushDefs(IA, DefM); } // Push all definitions from the instruction node IA to an appropriate // stack in DefM. -void DataFlowGraph::pushClobbers(Instr IA, DefStackMap &DefM) { +auto DataFlowGraph::pushClobbers(Instr IA, DefStackMap &DefM) -> void { NodeSet Visited; std::set Defined; @@ -1049,7 +1054,7 @@ void DataFlowGraph::pushClobbers(Instr IA, DefStackMap &DefM) { // Push all definitions from the instruction node IA to an appropriate // stack in DefM. -void DataFlowGraph::pushDefs(Instr IA, DefStackMap &DefM) { +auto DataFlowGraph::pushDefs(Instr IA, DefStackMap &DefM) -> void { NodeSet Visited; #ifndef NDEBUG std::set Defined; @@ -1103,7 +1108,7 @@ void DataFlowGraph::pushDefs(Instr IA, DefStackMap &DefM) { // Return the list of all reference nodes related to RA, including RA itself. // See "getNextRelated" for the meaning of a "related reference". -NodeList DataFlowGraph::getRelatedRefs(Instr IA, Ref RA) const { +auto DataFlowGraph::getRelatedRefs(Instr IA, Ref RA) const -> NodeList { assert(IA.Id != 0 && RA.Id != 0); NodeList Refs; @@ -1116,7 +1121,7 @@ NodeList DataFlowGraph::getRelatedRefs(Instr IA, Ref RA) const { } // Clear all information in the graph. -void DataFlowGraph::reset() { +auto DataFlowGraph::reset() -> void { Memory.clear(); BlockNodes.clear(); TheFunc = Func(); @@ -1128,7 +1133,7 @@ void DataFlowGraph::reset() { // characteristics. Specific examples of related nodes are shadow reference // nodes. // Return the equivalent of nullptr if there are no more related references. -Ref DataFlowGraph::getNextRelated(Instr IA, Ref RA) const { +auto DataFlowGraph::getNextRelated(Instr IA, Ref RA) const -> Ref { assert(IA.Id != 0 && RA.Id != 0); auto Related = [this, RA](Ref TA) -> bool { @@ -1166,8 +1171,8 @@ Ref DataFlowGraph::getNextRelated(Instr IA, Ref RA) const { // first element is the element after which such a node should be inserted, // and the second element is a null-address. template -std::pair DataFlowGraph::locateNextRef(Instr IA, Ref RA, - Predicate P) const { +auto DataFlowGraph::locateNextRef(Instr IA, Ref RA, Predicate P) const + -> std::pair { assert(IA.Id != 0 && RA.Id != 0); Ref NA; @@ -1188,7 +1193,7 @@ std::pair DataFlowGraph::locateNextRef(Instr IA, Ref RA, // Get the next shadow node in IA corresponding to RA, and optionally create // such a node if it does not exist. -Ref DataFlowGraph::getNextShadow(Instr IA, Ref RA, bool Create) { +auto DataFlowGraph::getNextShadow(Instr IA, Ref RA, bool Create) -> Ref { assert(IA.Id != 0 && RA.Id != 0); uint16_t Flags = RA.Addr->getFlags() | NodeAttrs::Shadow; @@ -1208,7 +1213,7 @@ Ref DataFlowGraph::getNextShadow(Instr IA, Ref RA, bool Create) { // Get the next shadow node in IA corresponding to RA. Return null-address // if such a node does not exist. -Ref DataFlowGraph::getNextShadow(Instr IA, Ref RA) const { +auto DataFlowGraph::getNextShadow(Instr IA, Ref RA) const -> Ref { assert(IA.Id != 0 && RA.Id != 0); uint16_t Flags = RA.Addr->getFlags() | NodeAttrs::Shadow; auto IsShadow = [Flags](Ref TA) -> bool { @@ -1219,7 +1224,7 @@ Ref DataFlowGraph::getNextShadow(Instr IA, Ref RA) const { // Create a new statement node in the block node BA that corresponds to // the machine instruction MI. -void DataFlowGraph::buildStmt(Block BA, MachineInstr &In) { +auto DataFlowGraph::buildStmt(Block BA, MachineInstr &In) -> void { Stmt SA = newStmt(BA, &In); auto isCall = [](const MachineInstr &In) -> bool { @@ -1353,7 +1358,7 @@ void DataFlowGraph::buildStmt(Block BA, MachineInstr &In) { // Scan all defs in the block node BA and record in PhiM the locations of // phi nodes corresponding to these defs. -void DataFlowGraph::recordDefsForDF(BlockRefsMap &PhiM, Block BA) { +auto DataFlowGraph::recordDefsForDF(BlockRefsMap &PhiM, Block BA) -> void { // Check all defs from block BA and record them in each block in BA's // iterated dominance frontier. This information will later be used to // create phi nodes. @@ -1392,8 +1397,8 @@ void DataFlowGraph::recordDefsForDF(BlockRefsMap &PhiM, Block BA) { // Given the locations of phi nodes in the map PhiM, create the phi nodes // that are located in the block node BA. -void DataFlowGraph::buildPhis(BlockRefsMap &PhiM, RegisterSet &AllRefs, - Block BA) { +auto DataFlowGraph::buildPhis(BlockRefsMap &PhiM, RegisterSet &AllRefs, + Block BA) -> void { // Check if this blocks has any DF defs, i.e. if there are any defs // that this block is in the iterated dominance frontier of. auto HasDF = PhiM.find(BA.Id); @@ -1421,7 +1426,7 @@ void DataFlowGraph::buildPhis(BlockRefsMap &PhiM, RegisterSet &AllRefs, } // Remove any unneeded phi nodes that were created during the build process. -void DataFlowGraph::removeUnusedPhis() { +auto DataFlowGraph::removeUnusedPhis() -> void { // This will remove unused phis, i.e. phis where each def does not reach // any uses or other defs. This will not detect or remove circular phi // chains that are otherwise dead. Unused/dead phis are created during @@ -1475,7 +1480,7 @@ void DataFlowGraph::removeUnusedPhis() { // reaching def of TA to the appropriate def node. Create any shadow nodes // as appropriate. template -void DataFlowGraph::linkRefUp(Instr IA, NodeAddr TA, DefStack &DS) { +auto DataFlowGraph::linkRefUp(Instr IA, NodeAddr TA, DefStack &DS) -> void { if (DS.empty()) return; RegisterRef RR = TA.Addr->getRegRef(*this); @@ -1519,7 +1524,8 @@ void DataFlowGraph::linkRefUp(Instr IA, NodeAddr TA, DefStack &DS) { // Create data-flow links for all reference nodes in the statement node SA. template -void DataFlowGraph::linkStmtRefs(DefStackMap &DefM, Stmt SA, Predicate P) { +auto DataFlowGraph::linkStmtRefs(DefStackMap &DefM, Stmt SA, Predicate P) + -> void { #ifndef NDEBUG RegisterSet Defs(getPRI()); #endif @@ -1550,7 +1556,7 @@ void DataFlowGraph::linkStmtRefs(DefStackMap &DefM, Stmt SA, Predicate P) { // Create data-flow links for all instructions in the block node BA. This // will include updating any phi nodes in BA. -void DataFlowGraph::linkBlockRefs(DefStackMap &DefM, Block BA) { +auto DataFlowGraph::linkBlockRefs(DefStackMap &DefM, Block BA) -> void { // Push block delimiters. markBlock(BA.Id, DefM); @@ -1628,7 +1634,7 @@ void DataFlowGraph::linkBlockRefs(DefStackMap &DefM, Block BA) { } // Remove the use node UA from any data-flow and structural links. -void DataFlowGraph::unlinkUseDF(Use UA) { +auto DataFlowGraph::unlinkUseDF(Use UA) -> void { NodeId RD = UA.Addr->getReachingDef(); NodeId Sib = UA.Addr->getSibling(); @@ -1655,7 +1661,7 @@ void DataFlowGraph::unlinkUseDF(Use UA) { } // Remove the def node DA from any data-flow and structural links. -void DataFlowGraph::unlinkDefDF(Def DA) { +auto DataFlowGraph::unlinkDefDF(Def DA) -> void { // // RD // | reached