45
45
#include " llvm/IR/Instruction.h"
46
46
#include " llvm/IR/Instructions.h"
47
47
#include " llvm/IR/IntrinsicInst.h"
48
+ #include " llvm/IR/IRBuilder.h"
48
49
#include " llvm/IR/OperandTraits.h"
49
50
#include " llvm/IR/Type.h"
50
51
#include " llvm/IR/Use.h"
@@ -95,8 +96,6 @@ class PPCBoolRetToInt : public FunctionPass {
95
96
Type *IntTy = ST->isPPC64 () ? Type::getInt64Ty (V->getContext ())
96
97
: Type::getInt32Ty (V->getContext ());
97
98
98
- if (auto *C = dyn_cast<Constant>(V))
99
- return ConstantExpr::getZExt (C, IntTy);
100
99
if (auto *P = dyn_cast<PHINode>(V)) {
101
100
// Temporarily set the operands to 0. We'll fix this later in
102
101
// runOnUse.
@@ -108,13 +107,12 @@ class PPCBoolRetToInt : public FunctionPass {
108
107
return Q;
109
108
}
110
109
111
- auto *A = dyn_cast<Argument>(V);
112
- auto *I = dyn_cast<Instruction>(V);
113
- assert ((A || I) && " Unknown value type" );
114
-
115
- auto InstPt =
116
- A ? &*A->getParent ()->getEntryBlock ().begin () : I->getNextNode ();
117
- return new ZExtInst (V, IntTy, " " , InstPt);
110
+ IRBuilder IRB (V->getContext ());
111
+ if (auto *I = dyn_cast<Instruction>(V))
112
+ IRB.SetInsertPoint (I->getNextNode ());
113
+ else
114
+ IRB.SetInsertPoint (&Func->getEntryBlock (), Func->getEntryBlock ().begin ());
115
+ return IRB.CreateZExt (V, IntTy);
118
116
}
119
117
120
118
typedef SmallPtrSet<const PHINode *, 8 > PHINodeSet;
@@ -196,6 +194,7 @@ class PPCBoolRetToInt : public FunctionPass {
196
194
197
195
auto &TM = TPC->getTM <PPCTargetMachine>();
198
196
ST = TM.getSubtargetImpl (F);
197
+ Func = &F;
199
198
200
199
PHINodeSet PromotablePHINodes = getPromotablePHINodes (F);
201
200
B2IMap Bool2IntMap;
@@ -277,6 +276,7 @@ class PPCBoolRetToInt : public FunctionPass {
277
276
278
277
private:
279
278
const PPCSubtarget *ST;
279
+ Function *Func;
280
280
};
281
281
282
282
} // end anonymous namespace
0 commit comments