[llvm-commits] [127733] Simplify code by using Intrinsic::getDeclaration.
clattner at apple.com
clattner at apple.com
Sun May 27 08:27:26 PDT 2007
Revision: 127733
Author: clattner
Date: 2007-05-27 08:27:26 -0700 (Sun, 27 May 2007)
Log Message:
-----------
Simplify code by using Intrinsic::getDeclaration.
Modified Paths:
--------------
apple-local/branches/llvm/gcc/config/i386/llvm-i386.cpp
Modified: apple-local/branches/llvm/gcc/config/i386/llvm-i386.cpp
===================================================================
--- apple-local/branches/llvm/gcc/config/i386/llvm-i386.cpp
2007-05-27 15:11:20 UTC (rev 127732)
+++ apple-local/branches/llvm/gcc/config/i386/llvm-i386.cpp
2007-05-27 15:27:26 UTC (rev 127733)
@@ -101,11 +101,8 @@
return true;
}
case IX86_BUILTIN_PSLLDI128: {
- VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
- static Constant *pslld = 0;
- if (pslld == 0)
- pslld = TheModule->getOrInsertFunction("llvm.x86.sse2.psll.d",
- v4i32, v4i32, v4i32,
NULL);
+ Function *pslld
+ = Intrinsic::getDeclaration(TheModule,
Intrinsic::x86_sse2_psll_d);
Value *Undef = UndefValue::get(Type::Int32Ty);
Ops[1] = BuildVector(Ops[1], Undef, Undef, Undef, NULL);
Result = Builder.CreateCall(pslld, Ops[0], Ops[1], "tmp");
@@ -113,24 +110,16 @@
return true;
}
case IX86_BUILTIN_PSLLQI: {
- VectorType *v2i32 = VectorType::get(Type::Int32Ty, 2);
- static Constant *psllq = 0;
- if (psllq == 0)
- psllq = TheModule->getOrInsertFunction("llvm.x86.mmx.psll.q",
- v2i32, v2i32, v2i32,
NULL);
- Value *Undef = UndefValue::get(Type::Int32Ty);
- Ops[1] = BuildVector(Ops[1], Undef, NULL);
+ Function *psllq =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_mmx_psll_q);
+ Ops[1] = BuildVector(Ops[1], UndefValue::get(Type::Int32Ty), NULL);
Result = Builder.CreateCall(psllq, Ops[0], Ops[1], "tmp");
Result = Builder.CreateBitCast(Result, ResultType, "tmp");
return true;
}
case IX86_BUILTIN_PSLLQI128: {
- VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
- VectorType *v2i64 = VectorType::get(Type::Int64Ty, 2);
- static Constant *psllq = 0;
- if (psllq == 0)
- psllq = TheModule->getOrInsertFunction("llvm.x86.sse2.psll.q",
- v2i64, v2i64, v4i32,
NULL);
+ Function *psllq =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_sse2_psll_q);
Value *Undef = UndefValue::get(Type::Int32Ty);
Ops[1] = BuildVector(Ops[1], Undef, Undef, Undef, NULL);
Result = Builder.CreateCall(psllq, Ops[0], Ops[1], "tmp");
@@ -138,25 +127,16 @@
return true;
}
case IX86_BUILTIN_PSRLWI: {
- VectorType *v2i32 = VectorType::get(Type::Int32Ty, 2);
- VectorType *v4i16 = VectorType::get(Type::Int16Ty, 4);
- static Constant *psrlw = 0;
- if (psrlw == 0)
- psrlw = TheModule->getOrInsertFunction("llvm.x86.mmx.psrl.w",
- v4i16, v4i16, v2i32,
NULL);
- Value *Undef = UndefValue::get(Type::Int32Ty);
- Ops[1] = BuildVector(Ops[1], Undef, NULL);
+ Function *psrlw =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_mmx_psrl_w);
+ Ops[1] = BuildVector(Ops[1], UndefValue::get(Type::Int32Ty), NULL);
Result = Builder.CreateCall(psrlw, Ops[0], Ops[1], "tmp");
Result = Builder.CreateBitCast(Result, ResultType, "tmp");
return true;
}
case IX86_BUILTIN_PSRLWI128: {
- VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
- VectorType *v8i16 = VectorType::get(Type::Int16Ty, 8);
- static Constant *psrlw = 0;
- if (psrlw == 0)
- psrlw = TheModule->getOrInsertFunction("llvm.x86.sse2.psrl.w",
- v8i16, v8i16, v4i32,
NULL);
+ Function *psrlw =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_sse2_psrl_w);
Value *Undef = UndefValue::get(Type::Int32Ty);
Ops[1] = BuildVector(Ops[1], Undef, Undef, Undef, NULL);
Result = Builder.CreateCall(psrlw, Ops[0], Ops[1], "tmp");
@@ -164,23 +144,16 @@
return true;
}
case IX86_BUILTIN_PSRLDI: {
- VectorType *v2i32 = VectorType::get(Type::Int32Ty, 2);
- static Constant *psrld = 0;
- if (psrld == 0)
- psrld = TheModule->getOrInsertFunction("llvm.x86.mmx.psrl.d",
- v2i32, v2i32, v2i32,
NULL);
- Value *Undef = UndefValue::get(Type::Int32Ty);
- Ops[1] = BuildVector(Ops[1], Undef, NULL);
+ Function *psrld =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_mmx_psrl_d);
+ Ops[1] = BuildVector(Ops[1], UndefValue::get(Type::Int32Ty), NULL);
Result = Builder.CreateCall(psrld, Ops[0], Ops[1], "tmp");
Result = Builder.CreateBitCast(Result, ResultType, "tmp");
return true;
}
case IX86_BUILTIN_PSRLDI128: {
- VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
- static Constant *psrld = 0;
- if (psrld == 0)
- psrld = TheModule->getOrInsertFunction("llvm.x86.sse2.psrl.d",
- v4i32, v4i32, v4i32,
NULL);
+ Function *psrld =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_sse2_psrl_d);
Value *Undef = UndefValue::get(Type::Int32Ty);
Ops[1] = BuildVector(Ops[1], Undef, Undef, Undef, NULL);
Result = Builder.CreateCall(psrld, Ops[0], Ops[1], "tmp");
@@ -188,24 +161,16 @@
return true;
}
case IX86_BUILTIN_PSRLQI: {
- VectorType *v2i32 = VectorType::get(Type::Int32Ty, 2);
- static Constant *psrlq = 0;
- if (psrlq == 0)
- psrlq = TheModule->getOrInsertFunction("llvm.x86.mmx.psrl.q",
- v2i32, v2i32, v2i32,
NULL);
- Value *Undef = UndefValue::get(Type::Int32Ty);
- Ops[1] = BuildVector(Ops[1], Undef, NULL);
+ Function *psrlq =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_mmx_psrl_q);
+ Ops[1] = BuildVector(Ops[1], UndefValue::get(Type::Int32Ty), NULL);
Result = Builder.CreateCall(psrlq, Ops[0], Ops[1], "tmp");
Result = Builder.CreateBitCast(Result, ResultType, "tmp");
return true;
}
case IX86_BUILTIN_PSRLQI128: {
- VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
- VectorType *v2i64 = VectorType::get(Type::Int64Ty, 2);
- static Constant *psrlq = 0;
- if (psrlq == 0)
- psrlq = TheModule->getOrInsertFunction("llvm.x86.sse2.psrl.q",
- v2i64, v2i64, v4i32,
NULL);
+ Function *psrlq =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_sse2_psrl_q);
Value *Undef = UndefValue::get(Type::Int32Ty);
Ops[1] = BuildVector(Ops[1], Undef, Undef, Undef, NULL);
Result = Builder.CreateCall(psrlq, Ops[0], Ops[1], "tmp");
@@ -213,25 +178,16 @@
return true;
}
case IX86_BUILTIN_PSRAWI: {
- VectorType *v2i32 = VectorType::get(Type::Int32Ty, 2);
- VectorType *v4i16 = VectorType::get(Type::Int16Ty, 4);
- static Constant *psraw = 0;
- if (psraw == 0)
- psraw = TheModule->getOrInsertFunction("llvm.x86.mmx.psra.w",
- v4i16, v4i16, v2i32,
NULL);
- Value *Undef = UndefValue::get(Type::Int32Ty);
- Ops[1] = BuildVector(Ops[1], Undef, NULL);
+ Function *psraw =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_mmx_psra_w);
+ Ops[1] = BuildVector(Ops[1], UndefValue::get(Type::Int32Ty), NULL);
Result = Builder.CreateCall(psraw, Ops[0], Ops[1], "tmp");
Result = Builder.CreateBitCast(Result, ResultType, "tmp");
return true;
}
case IX86_BUILTIN_PSRAWI128: {
- VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
- VectorType *v8i16 = VectorType::get(Type::Int16Ty, 8);
- static Constant *psraw = 0;
- if (psraw == 0)
- psraw = TheModule->getOrInsertFunction("llvm.x86.sse2.psra.w",
- v8i16, v8i16, v4i32,
NULL);
+ Function *psraw =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_sse2_psra_w);
Value *Undef = UndefValue::get(Type::Int32Ty);
Ops[1] = BuildVector(Ops[1], Undef, Undef, Undef, NULL);
Result = Builder.CreateCall(psraw, Ops[0], Ops[1], "tmp");
@@ -239,23 +195,16 @@
return true;
}
case IX86_BUILTIN_PSRADI: {
- VectorType *v2i32 = VectorType::get(Type::Int32Ty, 2);
- static Constant *psrad = 0;
- if (psrad == 0)
- psrad = TheModule->getOrInsertFunction("llvm.x86.mmx.psra.d",
- v2i32, v2i32, v2i32,
NULL);
- Value *Undef = UndefValue::get(Type::Int32Ty);
- Ops[1] = BuildVector(Ops[1], Undef, NULL);
+ Function *psrad =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_mmx_psra_d);
+ Ops[1] = BuildVector(Ops[1], UndefValue::get(Type::Int32Ty), NULL);
Result = Builder.CreateCall(psrad, Ops[0], Ops[1], "tmp");
Result = Builder.CreateBitCast(Result, ResultType, "tmp");
return true;
}
case IX86_BUILTIN_PSRADI128: {
- VectorType *v4i32 = VectorType::get(Type::Int32Ty, 4);
- static Constant *psrad = 0;
- if (psrad == 0)
- psrad = TheModule->getOrInsertFunction("llvm.x86.sse2.psra.d",
- v4i32, v4i32, v4i32,
NULL);
+ Function *psrad =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_sse2_psra_d);
Value *Undef = UndefValue::get(Type::Int32Ty);
Ops[1] = BuildVector(Ops[1], Undef, Undef, Undef, NULL);
Result = Builder.CreateCall(psrad, Ops[0], Ops[1], "tmp");
@@ -507,12 +456,8 @@
case IX86_BUILTIN_CMPNGEPS:
case IX86_BUILTIN_CMPORDPS:
case IX86_BUILTIN_CMPUNORDPS: {
- VectorType *v4f32 = VectorType::get(Type::FloatTy, 4);
- static Constant *cmpps = 0;
- if (cmpps == 0)
- cmpps = TheModule->getOrInsertFunction("llvm.x86.sse.cmp.ps",
- v4f32, v4f32, v4f32,
Type::Int8Ty,
- NULL);
+ Function *cmpps =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_sse_cmp_ps);
bool flip = false;
unsigned PredCode;
switch (FnCode) {
@@ -531,8 +476,8 @@
case IX86_BUILTIN_CMPORDPS: PredCode = 7; break;
}
Value *Pred = ConstantInt::get(Type::Int8Ty, PredCode);
- Value *Arg0 = Builder.CreateBitCast(Ops[0], v4f32, "tmp");
- Value *Arg1 = Builder.CreateBitCast(Ops[1], v4f32, "tmp");
+ Value *Arg0 = Ops[0];
+ Value *Arg1 = Ops[1];
if (flip) std::swap(Arg0, Arg1);
Value *CallOps[3] = { Arg0, Arg1, Pred };
Result = Builder.CreateCall(cmpps, CallOps, 3, "tmp");
@@ -549,12 +494,8 @@
case IX86_BUILTIN_CMPNGESS:
case IX86_BUILTIN_CMPORDSS:
case IX86_BUILTIN_CMPUNORDSS: {
- VectorType *v4f32 = VectorType::get(Type::FloatTy, 4);
- static Constant *cmpss = 0;
- if (cmpss == 0)
- cmpss = TheModule->getOrInsertFunction("llvm.x86.sse.cmp.ss",
- v4f32, v4f32, v4f32,
Type::Int8Ty,
- NULL);
+ Function *cmpss =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_sse_cmp_ss);
Value *Pred = 0;
switch (FnCode) {
case IX86_BUILTIN_CMPEQSS:
@@ -582,10 +523,7 @@
Pred = ConstantInt::get(Type::Int8Ty, 7);
break;
}
- Value *Arg0 = Builder.CreateBitCast(Ops[0], v4f32, "tmp");
- Value *Arg1 = Builder.CreateBitCast(Ops[1], v4f32, "tmp");
-
- Value *CallOps[3] = { Arg0, Arg1, Pred };
+ Value *CallOps[3] = { Ops[0], Ops[1], Pred };
Result = Builder.CreateCall(cmpss, CallOps, 3, "tmp");
Result = Builder.CreateBitCast(Result, ResultType, "tmp");
return true;
@@ -602,13 +540,8 @@
case IX86_BUILTIN_CMPNGEPD:
case IX86_BUILTIN_CMPORDPD:
case IX86_BUILTIN_CMPUNORDPD: {
- VectorType *v2f64 = VectorType::get(Type::DoubleTy, 2);
- static Constant *cmpps = 0;
- if (cmpps == 0) {
- Module *M = Builder.GetInsertBlock()->getParent()->getParent();
- cmpps = M->getOrInsertFunction("llvm.x86.sse2.cmp.pd",
- v2f64, v2f64, v2f64,
Type::Int8Ty, NULL);
- }
+ Function *cmppd =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_sse2_cmp_pd);
bool flip = false;
Value *Pred = 0;
switch (FnCode) {
@@ -653,12 +586,12 @@
Pred = ConstantInt::get(Type::Int8Ty, 7);
break;
}
- Value *Arg0 = Builder.CreateBitCast(Ops[0], v2f64, "tmp");
- Value *Arg1 = Builder.CreateBitCast(Ops[1], v2f64, "tmp");
+ Value *Arg0 = Ops[0];
+ Value *Arg1 = Ops[1];
if (flip) std::swap(Arg0, Arg1);
Value *CallOps[3] = { Arg0, Arg1, Pred };
- Result = Builder.CreateCall(cmpps, CallOps, 3, "tmp");
+ Result = Builder.CreateCall(cmppd, CallOps, 3, "tmp");
Result = Builder.CreateBitCast(Result, ResultType, "tmp");
return true;
}
@@ -670,13 +603,8 @@
case IX86_BUILTIN_CMPNLESD:
case IX86_BUILTIN_CMPORDSD:
case IX86_BUILTIN_CMPUNORDSD: {
- VectorType *v2f64 = VectorType::get(Type::DoubleTy, 2);
- static Constant *cmpss = 0;
- if (cmpss == 0) {
- Module *M = Builder.GetInsertBlock()->getParent()->getParent();
- cmpss = M->getOrInsertFunction("llvm.x86.sse2.cmp.sd",
- v2f64, v2f64, v2f64,
Type::Int8Ty, NULL);
- }
+ Function *cmpsd =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_sse2_cmp_sd);
Value *Pred = 0;
switch (FnCode) {
case IX86_BUILTIN_CMPEQSD:
@@ -705,30 +633,24 @@
break;
}
- Value *Arg0 = Builder.CreateBitCast(Ops[0], v2f64, "tmp");
- Value *Arg1 = Builder.CreateBitCast(Ops[1], v2f64, "tmp");
+ Value *Arg0 = Ops[0];
+ Value *Arg1 = Ops[1];
Value *CallOps[3] = { Arg0, Arg1, Pred };
- Result = Builder.CreateCall(cmpss, CallOps, 3, "tmp");
+ Result = Builder.CreateCall(cmpsd, CallOps, 3, "tmp");
Result = Builder.CreateBitCast(Result, ResultType, "tmp");
return true;
}
case IX86_BUILTIN_LDMXCSR: {
- PointerType *u32Ptr = PointerType::get(Type::Int32Ty);
- static Constant *ldmxcsr = 0;
- if (ldmxcsr == 0)
- ldmxcsr = TheModule->getOrInsertFunction("llvm.x86.sse.ldmxcsr",
- Type::VoidTy, u32Ptr,
NULL);
+ Function *ldmxcsr =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_sse_ldmxcsr);
Value *Ptr = CreateTemporary(Type::Int32Ty);
Builder.CreateStore(Ops[0], Ptr);
Result = Builder.CreateCall(ldmxcsr, Ptr);
return true;
}
case IX86_BUILTIN_STMXCSR: {
- PointerType *u32Ptr = PointerType::get(Type::Int32Ty);
- static Constant *stmxcsr = 0;
- if (stmxcsr == 0)
- stmxcsr = TheModule->getOrInsertFunction("llvm.x86.sse.stmxcsr",
- Type::VoidTy, u32Ptr,
NULL);
+ Function *stmxcsr =
+ Intrinsic::getDeclaration(TheModule, Intrinsic::x86_sse_stmxcsr);
Value *Ptr = CreateTemporary(Type::Int32Ty);
Builder.CreateCall(stmxcsr, Ptr);
Result = Builder.CreateLoad(Ptr, "tmp");
More information about the llvm-commits
mailing list