Add an extra parameter to __smear functions to encode return type.

Now, the __smear* functions in generated C++ code have an unused first
parameter of the desired return type; this allows us to have headers
that include variants of __smear for multiple target widths.  (This
approach is necessary since we can't overload by return type in C++.)

Issue #256.
This commit is contained in:
Matt Pharr
2012-05-08 09:54:23 -07:00
parent 041ade66d5
commit c6241581a0
4 changed files with 49 additions and 39 deletions

View File

@@ -1464,6 +1464,8 @@ void CWriter::printConstant(Constant *CPV, bool Static) {
Constant *CZ = Constant::getNullValue(VT->getElementType());
Out << smearFunc << "(";
printType(Out, VT);
Out << "(), ";
printConstant(CZ, Static);
Out << ")";
}
@@ -1471,6 +1473,8 @@ void CWriter::printConstant(Constant *CPV, bool Static) {
llvm::Constant *splatValue = CV->getSplatValue();
if (splatValue != NULL && smearFunc != NULL) {
Out << smearFunc << "(";
printType(Out, VT);
Out << "(), ";
printConstant(splatValue, Static);
Out << ")";
}
@@ -1486,6 +1490,8 @@ void CWriter::printConstant(Constant *CPV, bool Static) {
llvm::Constant *splatValue = CDV->getSplatValue();
if (splatValue != NULL && smearFunc != NULL) {
Out << smearFunc << "(";
printType(Out, VT);
Out << "(), ";
printConstant(splatValue, Static);
Out << ")";
}
@@ -4392,16 +4398,17 @@ SmearCleanupPass::runOnBasicBlock(llvm::BasicBlock &bb) {
if (smearFunc == NULL) {
Constant *sf =
module->getOrInsertFunction(smearFuncName, iter->getType(),
matchType, NULL);
iter->getType(), matchType, NULL);
smearFunc = dyn_cast<Function>(sf);
assert(smearFunc != NULL);
smearFunc->setDoesNotThrow(true);
smearFunc->setDoesNotAccessMemory(true);
}
llvm::Value *undefResult = llvm::UndefValue::get(vt);
assert(smearFunc != NULL);
Value *args[1] = { toMatch };
ArrayRef<llvm::Value *> argArray(&args[0], &args[1]);
Value *args[2] = { undefResult, toMatch };
ArrayRef<llvm::Value *> argArray(&args[0], &args[2]);
Instruction *smearCall =
CallInst::Create(smearFunc, argArray, LLVMGetName(toMatch, "_smear"),
(Instruction *)NULL);