2424
2525#include " WebAssembly.h"
2626#include " llvm/IR/Constants.h"
27+ #include " llvm/IR/IRBuilder.h"
2728#include " llvm/IR/Instructions.h"
2829#include " llvm/IR/Module.h"
2930#include " llvm/IR/Operator.h"
@@ -114,6 +115,7 @@ static Function *createWrapper(Function *F, FunctionType *Ty) {
114115 Wrapper->setAttributes (F->getAttributes ());
115116 BasicBlock *BB = BasicBlock::Create (M->getContext (), " body" , Wrapper);
116117 const DataLayout &DL = BB->getDataLayout ();
118+ IRBuilder<> Builder (BB);
117119
118120 // Determine what arguments to pass.
119121 SmallVector<Value *, 4 > Args;
@@ -140,10 +142,7 @@ static Function *createWrapper(Function *F, FunctionType *Ty) {
140142 Args.push_back (&*AI);
141143 } else {
142144 if (CastInst::isBitOrNoopPointerCastable (ArgType, ParamType, DL)) {
143- Instruction *PtrCast =
144- CastInst::CreateBitOrPointerCast (AI, ParamType, " cast" );
145- PtrCast->insertInto (BB, BB->end ());
146- Args.push_back (PtrCast);
145+ Args.push_back (Builder.CreateBitOrPointerCast (AI, ParamType, " cast" ));
147146 } else if (ArgType->isStructTy () || ParamType->isStructTy ()) {
148147 LLVM_DEBUG (dbgs () << " createWrapper: struct param type in bitcast: "
149148 << F->getName () << " \n " );
@@ -166,24 +165,19 @@ static Function *createWrapper(Function *F, FunctionType *Ty) {
166165 for (; AI != AE; ++AI)
167166 Args.push_back (&*AI);
168167
169- CallInst *Call = CallInst::Create (F, Args, " " , BB );
168+ CallInst *Call = Builder. CreateCall (F, Args);
170169
171- Type *ExpectedRtnType = F->getFunctionType ()->getReturnType ();
172- Type *RtnType = Ty->getReturnType ();
173170 // Determine what value to return.
174171 if (RtnType->isVoidTy ()) {
175- ReturnInst::Create (M-> getContext (), BB );
172+ Builder. CreateRetVoid ( );
176173 } else if (ExpectedRtnType->isVoidTy ()) {
177174 LLVM_DEBUG (dbgs () << " Creating dummy return: " << *RtnType << " \n " );
178- ReturnInst::Create (M-> getContext (), PoisonValue::get (RtnType), BB );
175+ Builder. CreateRet ( PoisonValue::get (RtnType));
179176 } else if (RtnType == ExpectedRtnType) {
180- ReturnInst::Create (M-> getContext (), Call, BB );
177+ Builder. CreateRet ( Call);
181178 } else if (CastInst::isBitOrNoopPointerCastable (ExpectedRtnType, RtnType,
182179 DL)) {
183- Instruction *Cast =
184- CastInst::CreateBitOrPointerCast (Call, RtnType, " cast" );
185- Cast->insertInto (BB, BB->end ());
186- ReturnInst::Create (M->getContext (), Cast, BB);
180+ Builder.CreateRet (Builder.CreateBitOrPointerCast (Call, RtnType, " cast" ));
187181 } else if (RtnType->isStructTy () || ExpectedRtnType->isStructTy ()) {
188182 LLVM_DEBUG (dbgs () << " createWrapper: struct return type in bitcast: "
189183 << F->getName () << " \n " );
@@ -203,9 +197,8 @@ static Function *createWrapper(Function *F, FunctionType *Ty) {
203197 Wrapper = Function::Create (Ty, Function::PrivateLinkage,
204198 F->getName () + " _bitcast_invalid" , M);
205199 Wrapper->setAttributes (F->getAttributes ());
206- BasicBlock *BB = BasicBlock::Create (M->getContext (), " body" , Wrapper);
207- new UnreachableInst (M->getContext (), BB);
208- Wrapper->setName (F->getName () + " _bitcast_invalid" );
200+ IRBuilder<> Builder (BasicBlock::Create (M->getContext (), " body" , Wrapper));
201+ Builder.CreateUnreachable ();
209202 } else if (!WrapperNeeded) {
210203 LLVM_DEBUG (dbgs () << " createWrapper: no wrapper needed: " << F->getName ()
211204 << " \n " );
0 commit comments