Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright 2011 Christoph Bumiller
  3.  *
  4.  * Permission is hereby granted, free of charge, to any person obtaining a
  5.  * copy of this software and associated documentation files (the "Software"),
  6.  * to deal in the Software without restriction, including without limitation
  7.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8.  * and/or sell copies of the Software, and to permit persons to whom the
  9.  * Software is furnished to do so, subject to the following conditions:
  10.  *
  11.  * The above copyright notice and this permission notice shall be included in
  12.  * all copies or substantial portions of the Software.
  13.  *
  14.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  17.  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18.  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19.  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20.  * OTHER DEALINGS IN THE SOFTWARE.
  21.  */
  22.  
  23. #include <tr1/unordered_set>
  24.  
  25. #include "codegen/nv50_ir.h"
  26. #include "codegen/nv50_ir_build_util.h"
  27.  
  28. namespace nv50_ir {
  29.  
  30. class NVC0LegalizeSSA : public Pass
  31. {
  32. private:
  33.    virtual bool visit(BasicBlock *);
  34.    virtual bool visit(Function *);
  35.  
  36.    // we want to insert calls to the builtin library only after optimization
  37.    void handleDIV(Instruction *); // integer division, modulus
  38.    void handleRCPRSQ(Instruction *); // double precision float recip/rsqrt
  39.    void handleFTZ(Instruction *);
  40.  
  41. private:
  42.    BuildUtil bld;
  43. };
  44.  
  45. class NVC0LegalizePostRA : public Pass
  46. {
  47. public:
  48.    NVC0LegalizePostRA(const Program *);
  49.  
  50. private:
  51.    virtual bool visit(Function *);
  52.    virtual bool visit(BasicBlock *);
  53.  
  54.    void replaceZero(Instruction *);
  55.    bool tryReplaceContWithBra(BasicBlock *);
  56.    void propagateJoin(BasicBlock *);
  57.  
  58.    struct TexUse
  59.    {
  60.       TexUse(Instruction *use, const Instruction *tex)
  61.          : insn(use), tex(tex), level(-1) { }
  62.       Instruction *insn;
  63.       const Instruction *tex; // or split / mov
  64.       int level;
  65.    };
  66.    struct Limits
  67.    {
  68.       Limits() { }
  69.       Limits(int min, int max) : min(min), max(max) { }
  70.       int min, max;
  71.    };
  72.    bool insertTextureBarriers(Function *);
  73.    inline bool insnDominatedBy(const Instruction *, const Instruction *) const;
  74.    void findFirstUses(const Instruction *tex, const Instruction *def,
  75.                       std::list<TexUse>&,
  76.                       std::tr1::unordered_set<const Instruction *>&);
  77.    void findOverwritingDefs(const Instruction *tex, Instruction *insn,
  78.                             const BasicBlock *term,
  79.                             std::list<TexUse>&);
  80.    void addTexUse(std::list<TexUse>&, Instruction *, const Instruction *);
  81.    const Instruction *recurseDef(const Instruction *);
  82.  
  83. private:
  84.    LValue *rZero;
  85.    LValue *carry;
  86.    const bool needTexBar;
  87. };
  88.  
  89. class NVC0LoweringPass : public Pass
  90. {
  91. public:
  92.    NVC0LoweringPass(Program *);
  93.  
  94. protected:
  95.    bool handleRDSV(Instruction *);
  96.    bool handleWRSV(Instruction *);
  97.    bool handleEXPORT(Instruction *);
  98.    bool handleOUT(Instruction *);
  99.    bool handleDIV(Instruction *);
  100.    bool handleMOD(Instruction *);
  101.    bool handleSQRT(Instruction *);
  102.    bool handlePOW(Instruction *);
  103.    bool handleTEX(TexInstruction *);
  104.    bool handleTXD(TexInstruction *);
  105.    bool handleTXQ(TexInstruction *);
  106.    virtual bool handleManualTXD(TexInstruction *);
  107.    bool handleTXLQ(TexInstruction *);
  108.    bool handleATOM(Instruction *);
  109.    bool handleCasExch(Instruction *, bool needCctl);
  110.    void handleSurfaceOpNVE4(TexInstruction *);
  111.  
  112.    void checkPredicate(Instruction *);
  113.  
  114. private:
  115.    virtual bool visit(Function *);
  116.    virtual bool visit(BasicBlock *);
  117.    virtual bool visit(Instruction *);
  118.  
  119.    void readTessCoord(LValue *dst, int c);
  120.  
  121.    Value *loadResInfo32(Value *ptr, uint32_t off);
  122.    Value *loadMsInfo32(Value *ptr, uint32_t off);
  123.    Value *loadTexHandle(Value *ptr, unsigned int slot);
  124.  
  125.    void adjustCoordinatesMS(TexInstruction *);
  126.    void processSurfaceCoordsNVE4(TexInstruction *);
  127.  
  128. protected:
  129.    BuildUtil bld;
  130.  
  131. private:
  132.    const Target *const targ;
  133.  
  134.    Symbol *gMemBase;
  135.    LValue *gpEmitAddress;
  136. };
  137.  
  138. } // namespace nv50_ir
  139.