10b57cec5SDimitry Andric //===-- llvm/CodeGen/PseudoSourceValue.h ------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file contains the declaration of the PseudoSourceValue class.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_CODEGEN_PSEUDOSOURCEVALUE_H
140b57cec5SDimitry Andric #define LLVM_CODEGEN_PSEUDOSOURCEVALUE_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric namespace llvm {
170b57cec5SDimitry Andric 
185ffd83dbSDimitry Andric class GlobalValue;
190b57cec5SDimitry Andric class MachineFrameInfo;
200b57cec5SDimitry Andric class MachineMemOperand;
21480093f4SDimitry Andric class MIRFormatter;
225ffd83dbSDimitry Andric class PseudoSourceValue;
230b57cec5SDimitry Andric class raw_ostream;
2481ad6265SDimitry Andric class TargetMachine;
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric raw_ostream &operator<<(raw_ostream &OS, const PseudoSourceValue* PSV);
270b57cec5SDimitry Andric 
280b57cec5SDimitry Andric /// Special value supplied for machine level alias analysis. It indicates that
290b57cec5SDimitry Andric /// a memory access references the functions stack frame (e.g., a spill slot),
300b57cec5SDimitry Andric /// below the stack frame (e.g., argument space), or constant pool.
310b57cec5SDimitry Andric class PseudoSourceValue {
320b57cec5SDimitry Andric public:
330b57cec5SDimitry Andric   enum PSVKind : unsigned {
340b57cec5SDimitry Andric     Stack,
350b57cec5SDimitry Andric     GOT,
360b57cec5SDimitry Andric     JumpTable,
370b57cec5SDimitry Andric     ConstantPool,
380b57cec5SDimitry Andric     FixedStack,
390b57cec5SDimitry Andric     GlobalValueCallEntry,
400b57cec5SDimitry Andric     ExternalSymbolCallEntry,
410b57cec5SDimitry Andric     TargetCustom
420b57cec5SDimitry Andric   };
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric private:
450b57cec5SDimitry Andric   unsigned Kind;
460b57cec5SDimitry Andric   unsigned AddressSpace;
470b57cec5SDimitry Andric   friend raw_ostream &llvm::operator<<(raw_ostream &OS,
480b57cec5SDimitry Andric                                        const PseudoSourceValue* PSV);
490b57cec5SDimitry Andric 
500b57cec5SDimitry Andric   friend class MachineMemOperand; // For printCustom().
51480093f4SDimitry Andric   friend class MIRFormatter;      // For printCustom().
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric   /// Implement printing for PseudoSourceValue. This is called from
540b57cec5SDimitry Andric   /// Value::print or Value's operator<<.
550b57cec5SDimitry Andric   virtual void printCustom(raw_ostream &O) const;
560b57cec5SDimitry Andric 
570b57cec5SDimitry Andric public:
5881ad6265SDimitry Andric   explicit PseudoSourceValue(unsigned Kind, const TargetMachine &TM);
590b57cec5SDimitry Andric 
600b57cec5SDimitry Andric   virtual ~PseudoSourceValue();
610b57cec5SDimitry Andric 
kind()620b57cec5SDimitry Andric   unsigned kind() const { return Kind; }
630b57cec5SDimitry Andric 
isStack()640b57cec5SDimitry Andric   bool isStack() const { return Kind == Stack; }
isGOT()650b57cec5SDimitry Andric   bool isGOT() const { return Kind == GOT; }
isConstantPool()660b57cec5SDimitry Andric   bool isConstantPool() const { return Kind == ConstantPool; }
isJumpTable()670b57cec5SDimitry Andric   bool isJumpTable() const { return Kind == JumpTable; }
680b57cec5SDimitry Andric 
getAddressSpace()690b57cec5SDimitry Andric   unsigned getAddressSpace() const { return AddressSpace; }
700b57cec5SDimitry Andric 
getTargetCustom()710b57cec5SDimitry Andric   unsigned getTargetCustom() const {
720b57cec5SDimitry Andric     return (Kind >= TargetCustom) ? ((Kind+1) - TargetCustom) : 0;
730b57cec5SDimitry Andric   }
740b57cec5SDimitry Andric 
750b57cec5SDimitry Andric   /// Test whether the memory pointed to by this PseudoSourceValue has a
760b57cec5SDimitry Andric   /// constant value.
770b57cec5SDimitry Andric   virtual bool isConstant(const MachineFrameInfo *) const;
780b57cec5SDimitry Andric 
790b57cec5SDimitry Andric   /// Test whether the memory pointed to by this PseudoSourceValue may also be
800b57cec5SDimitry Andric   /// pointed to by an LLVM IR Value.
810b57cec5SDimitry Andric   virtual bool isAliased(const MachineFrameInfo *) const;
820b57cec5SDimitry Andric 
830b57cec5SDimitry Andric   /// Return true if the memory pointed to by this PseudoSourceValue can ever
840b57cec5SDimitry Andric   /// alias an LLVM IR Value.
850b57cec5SDimitry Andric   virtual bool mayAlias(const MachineFrameInfo *) const;
860b57cec5SDimitry Andric };
870b57cec5SDimitry Andric 
880b57cec5SDimitry Andric /// A specialized PseudoSourceValue for holding FixedStack values, which must
890b57cec5SDimitry Andric /// include a frame index.
900b57cec5SDimitry Andric class FixedStackPseudoSourceValue : public PseudoSourceValue {
910b57cec5SDimitry Andric   const int FI;
920b57cec5SDimitry Andric 
930b57cec5SDimitry Andric public:
FixedStackPseudoSourceValue(int FI,const TargetMachine & TM)9481ad6265SDimitry Andric   explicit FixedStackPseudoSourceValue(int FI, const TargetMachine &TM)
9581ad6265SDimitry Andric       : PseudoSourceValue(FixedStack, TM), FI(FI) {}
960b57cec5SDimitry Andric 
classof(const PseudoSourceValue * V)970b57cec5SDimitry Andric   static bool classof(const PseudoSourceValue *V) {
980b57cec5SDimitry Andric     return V->kind() == FixedStack;
990b57cec5SDimitry Andric   }
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric   bool isConstant(const MachineFrameInfo *MFI) const override;
1020b57cec5SDimitry Andric 
1030b57cec5SDimitry Andric   bool isAliased(const MachineFrameInfo *MFI) const override;
1040b57cec5SDimitry Andric 
1050b57cec5SDimitry Andric   bool mayAlias(const MachineFrameInfo *) const override;
1060b57cec5SDimitry Andric 
1070b57cec5SDimitry Andric   void printCustom(raw_ostream &OS) const override;
1080b57cec5SDimitry Andric 
getFrameIndex()1090b57cec5SDimitry Andric   int getFrameIndex() const { return FI; }
1100b57cec5SDimitry Andric };
1110b57cec5SDimitry Andric 
1120b57cec5SDimitry Andric class CallEntryPseudoSourceValue : public PseudoSourceValue {
1130b57cec5SDimitry Andric protected:
11481ad6265SDimitry Andric   CallEntryPseudoSourceValue(unsigned Kind, const TargetMachine &TM);
1150b57cec5SDimitry Andric 
1160b57cec5SDimitry Andric public:
1170b57cec5SDimitry Andric   bool isConstant(const MachineFrameInfo *) const override;
1180b57cec5SDimitry Andric   bool isAliased(const MachineFrameInfo *) const override;
1190b57cec5SDimitry Andric   bool mayAlias(const MachineFrameInfo *) const override;
1200b57cec5SDimitry Andric };
1210b57cec5SDimitry Andric 
1220b57cec5SDimitry Andric /// A specialized pseudo source value for holding GlobalValue values.
1230b57cec5SDimitry Andric class GlobalValuePseudoSourceValue : public CallEntryPseudoSourceValue {
1240b57cec5SDimitry Andric   const GlobalValue *GV;
1250b57cec5SDimitry Andric 
1260b57cec5SDimitry Andric public:
12781ad6265SDimitry Andric   GlobalValuePseudoSourceValue(const GlobalValue *GV, const TargetMachine &TM);
1280b57cec5SDimitry Andric 
classof(const PseudoSourceValue * V)1290b57cec5SDimitry Andric   static bool classof(const PseudoSourceValue *V) {
1300b57cec5SDimitry Andric     return V->kind() == GlobalValueCallEntry;
1310b57cec5SDimitry Andric   }
1320b57cec5SDimitry Andric 
getValue()1330b57cec5SDimitry Andric   const GlobalValue *getValue() const { return GV; }
1340b57cec5SDimitry Andric };
1350b57cec5SDimitry Andric 
1360b57cec5SDimitry Andric /// A specialized pseudo source value for holding external symbol values.
1370b57cec5SDimitry Andric class ExternalSymbolPseudoSourceValue : public CallEntryPseudoSourceValue {
1380b57cec5SDimitry Andric   const char *ES;
1390b57cec5SDimitry Andric 
1400b57cec5SDimitry Andric public:
14181ad6265SDimitry Andric   ExternalSymbolPseudoSourceValue(const char *ES, const TargetMachine &TM);
1420b57cec5SDimitry Andric 
classof(const PseudoSourceValue * V)1430b57cec5SDimitry Andric   static bool classof(const PseudoSourceValue *V) {
1440b57cec5SDimitry Andric     return V->kind() == ExternalSymbolCallEntry;
1450b57cec5SDimitry Andric   }
1460b57cec5SDimitry Andric 
getSymbol()1470b57cec5SDimitry Andric   const char *getSymbol() const { return ES; }
1480b57cec5SDimitry Andric };
1490b57cec5SDimitry Andric 
1500b57cec5SDimitry Andric } // end namespace llvm
1510b57cec5SDimitry Andric 
1520b57cec5SDimitry Andric #endif
153