Exemple #1
0
        public Value BuildPhi(TypeRef type, string name, PhiIncoming incoming)
        {
            IntPtr[] valPointers   = incoming.GetValuePointers();
            IntPtr[] blockPointers = incoming.GetBlockPointers();

            LLVMValueRef *phi = Native.BuildPhi(m_builder, type.Handle, name);

            Native.AddIncoming(phi, valPointers, blockPointers, (uint)valPointers.Length);

            return(new Value(phi));
        }
Exemple #2
0
        public override Value CodeGen(IRBuilder builder)
        {
            Value condV = this.Cond.CodeGen(builder);
            if(condV.IsNull) return condV;

            condV = builder.BuildFCmp(condV, LLVMRealPredicate.RealONE, 
                                      Value.CreateConstDouble(0));
            
            BasicBlock startBlock = builder.GetInsertPoint();
            Function func = startBlock.GetParent();

            BasicBlock thenBB = func.AppendBasicBlock("then");
            builder.SetInsertPoint(thenBB);

            Value thenV = this.Then.CodeGen(builder);
            if(thenV.IsNull) return thenV;
      
            /* Codegen of 'then' can change the current block, update then_bb for the
            * phi. We create a new name because one is used for the phi node, and the
            * other is used for the conditional branch. */
            BasicBlock newThenBB = builder.GetInsertPoint();

            // Emit else block
            BasicBlock elseBB = func.AppendBasicBlock("else");
            func.AppendBasicBlock(elseBB);
            builder.SetInsertPoint(elseBB);

            Value elseV = this.Else.CodeGen(builder);
            if(elseV.IsNull) return elseV;

            // Codegen of 'Else' can change the current block, update ElseBB for the PHI.
            BasicBlock newElseBB = builder.GetInsertPoint();

            // Emit merge block
            BasicBlock mergeBB = func.AppendBasicBlock("ifcont");
            func.AppendBasicBlock(mergeBB);
            builder.SetInsertPoint(mergeBB);

            PhiIncoming incoming = new PhiIncoming();
            incoming.Add(thenV, thenBB);
            incoming.Add(elseV, elseBB);
            Value phi = builder.BuildPhi(TypeRef.CreateDouble(), "iftmp", incoming);

            builder.SetInsertPoint(startBlock);
            builder.BuildCondBr(condV, thenBB, elseBB);

            builder.SetInsertPoint(thenBB);
            builder.BuildBr(mergeBB);

            builder.SetInsertPoint(elseBB);
            builder.BuildBr(mergeBB);

            builder.SetInsertPoint(mergeBB);

            return phi;
        }
Exemple #3
0
        public Value BuildPhi(TypeRef type, string name, PhiIncoming incoming)
        {
            IntPtr[] valPointers = incoming.GetValuePointers();
            IntPtr[] blockPointers = incoming.GetBlockPointers();

            LLVMValueRef* phi = Native.BuildPhi(m_builder, type.Handle, name);
            Native.AddIncoming(phi, valPointers, blockPointers, (uint)valPointers.Length);

            return new Value(phi);
        }