aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNate Begeman <natebegeman@mac.com>2006-01-14 01:25:24 +0000
committerNate Begeman <natebegeman@mac.com>2006-01-14 01:25:24 +0000
commit6fb3bd6a658940287789198d3207b0da04c0a4e6 (patch)
tree7d3b9be2b6b00fd564f0b884de5c1999b1985890 /lib
parent6283760cd13fa3f41c7f6462456661ea54ded980 (diff)
downloadexternal_llvm-6fb3bd6a658940287789198d3207b0da04c0a4e6.zip
external_llvm-6fb3bd6a658940287789198d3207b0da04c0a4e6.tar.gz
external_llvm-6fb3bd6a658940287789198d3207b0da04c0a4e6.tar.bz2
Add bswap intrinsics as documented in the Language Reference
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25309 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Analysis/BasicAliasAnalysis.cpp3
-rw-r--r--lib/Analysis/ConstantFolding.cpp15
-rw-r--r--lib/Transforms/Utils/Local.cpp3
-rw-r--r--lib/VMCore/Function.cpp5
-rw-r--r--lib/VMCore/Verifier.cpp30
5 files changed, 55 insertions, 1 deletions
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index 86cc564..71bcbd2 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/lib/Analysis/BasicAliasAnalysis.cpp
@@ -708,7 +708,8 @@ namespace {
static const char *DoesntAccessMemoryTable[] = {
// LLVM intrinsics:
"llvm.frameaddress", "llvm.returnaddress", "llvm.readport",
- "llvm.isunordered", "llvm.sqrt", "llvm.ctpop", "llvm.ctlz", "llvm.cttz",
+ "llvm.isunordered", "llvm.sqrt", "llvm.bswap.i16", "llvm.bswap.i32",
+ "llvm.bswap.i64", "llvm.ctpop", "llvm.ctlz", "llvm.cttz",
"abs", "labs", "llabs", "imaxabs", "fabs", "fabsf", "fabsl",
"trunc", "truncf", "truncl", "ldexp",
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index 4022bdd..915a7cb 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/lib/Analysis/ConstantFolding.cpp
@@ -37,6 +37,13 @@ llvm::canConstantFoldCallTo(Function *F) {
switch (F->getIntrinsicID()) {
case Intrinsic::isunordered:
case Intrinsic::sqrt:
+ case Intrinsic::bswap_i16:
+ case Intrinsic::bswap_i32:
+ case Intrinsic::bswap_i64:
+ // FIXME: these should be constant folded as well
+ //case Intrinsic::ctpop:
+ //case Intrinsic::ctlz:
+ //case Intrinsic::cttz:
return true;
default: break;
}
@@ -142,6 +149,14 @@ llvm::ConstantFoldCall(Function *F, const std::vector<Constant*> &Operands) {
default:
break;
}
+ } else if (ConstantUInt *Op = dyn_cast<ConstantUInt>(Operands[0])) {
+ uint64_t V = Op->getValue();
+ if (Name == "llvm.bswap.i16")
+ return ConstantUInt::get(Ty, ByteSwap_16(V));
+ else if (Name == "llvm.bswap.i32")
+ return ConstantUInt::get(Ty, ByteSwap_32(V));
+ else if (Name == "llvm.bswap.i64")
+ return ConstantUInt::get(Ty, ByteSwap_64(V));
}
} else if (Operands.size() == 2) {
if (ConstantFP *Op1 = dyn_cast<ConstantFP>(Operands[0])) {
diff --git a/lib/Transforms/Utils/Local.cpp b/lib/Transforms/Utils/Local.cpp
index 4e3b3e9..c4b69a4 100644
--- a/lib/Transforms/Utils/Local.cpp
+++ b/lib/Transforms/Utils/Local.cpp
@@ -298,6 +298,9 @@ bool llvm::isInstructionTriviallyDead(Instruction *I) {
case Intrinsic::frameaddress:
case Intrinsic::stacksave:
case Intrinsic::isunordered:
+ case Intrinsic::bswap_i16:
+ case Intrinsic::bswap_i32:
+ case Intrinsic::bswap_i64:
case Intrinsic::ctpop:
case Intrinsic::ctlz:
case Intrinsic::cttz:
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 0cbe14c..3abfef9 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -207,6 +207,11 @@ unsigned Function::getIntrinsicID() const {
assert(getName().size() != 5 && "'llvm.' is an invalid intrinsic name!");
switch (getName()[5]) {
+ case 'b':
+ if (getName() == "llvm.bswap.i16") return Intrinsic::bswap_i16;
+ if (getName() == "llvm.bswap.i32") return Intrinsic::bswap_i32;
+ if (getName() == "llvm.bswap.i64") return Intrinsic::bswap_i64;
+ break;
case 'c':
if (getName() == "llvm.ctpop") return Intrinsic::ctpop;
if (getName() == "llvm.cttz") return Intrinsic::cttz;
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index 9dd7184..f67a497 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -749,6 +749,36 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
NumArgs = 0;
break;
+ case Intrinsic::bswap_i16:
+ Assert1(FT->getNumParams() == 1,
+ "Illegal # arguments for intrinsic function!", IF);
+ Assert1(FT->getReturnType() == FT->getParamType(0),
+ "Return type does not match source type", IF);
+ Assert1(FT->getReturnType() == Type::UShortTy,
+ "Return type is not ushort!", IF);
+ NumArgs = 1;
+ break;
+
+ case Intrinsic::bswap_i32:
+ Assert1(FT->getNumParams() == 1,
+ "Illegal # arguments for intrinsic function!", IF);
+ Assert1(FT->getReturnType() == FT->getParamType(0),
+ "Return type does not match source type", IF);
+ Assert1(FT->getReturnType() == Type::UIntTy,
+ "Return type is not uint!", IF);
+ NumArgs = 1;
+ break;
+
+ case Intrinsic::bswap_i64:
+ Assert1(FT->getNumParams() == 1,
+ "Illegal # arguments for intrinsic function!", IF);
+ Assert1(FT->getReturnType() == FT->getParamType(0),
+ "Return type does not match source type", IF);
+ Assert1(FT->getReturnType() == Type::ULongTy,
+ "Return type is not ulong!", IF);
+ NumArgs = 1;
+ break;
+
case Intrinsic::ctpop:
case Intrinsic::ctlz:
case Intrinsic::cttz: