Stop using dynamic_cast for Types.

We now have a set of template functions CastType<AtomicType>, etc., that in
turn use a new typeId field in each Type instance, allowing them to be inlined
and to be quite efficient.

This improves front-end performance for a particular large program by 28%.
This commit is contained in:
Matt Pharr
2012-05-04 11:12:33 -07:00
parent c756c855ea
commit 944c53bff1
11 changed files with 539 additions and 425 deletions

View File

@@ -100,7 +100,7 @@ Function::Function(Symbol *s, Stmt *c) {
printf("\n\n\n");
}
const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type);
const FunctionType *type = CastType<FunctionType>(sym->type);
Assert(type != NULL);
for (int i = 0; i < type->GetNumParameters(); ++i) {
@@ -111,7 +111,7 @@ Function::Function(Symbol *s, Stmt *c) {
args.push_back(sym);
const Type *t = type->GetParameterType(i);
if (sym != NULL && dynamic_cast<const ReferenceType *>(t) == NULL)
if (sym != NULL && CastType<ReferenceType>(t) == NULL)
sym->parentFunction = this;
}
@@ -132,7 +132,7 @@ Function::Function(Symbol *s, Stmt *c) {
const Type *
Function::GetReturnType() const {
const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type);
const FunctionType *type = CastType<FunctionType>(sym->type);
Assert(type != NULL);
return type->GetReturnType();
}
@@ -140,7 +140,7 @@ Function::GetReturnType() const {
const FunctionType *
Function::GetType() const {
const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type);
const FunctionType *type = CastType<FunctionType>(sym->type);
Assert(type != NULL);
return type;
}
@@ -205,7 +205,7 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function,
#if 0
llvm::BasicBlock *entryBBlock = ctx->GetCurrentBasicBlock();
#endif
const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type);
const FunctionType *type = CastType<FunctionType>(sym->type);
Assert(type != NULL);
if (type->isTask == true) {
// For tasks, we there should always be three parmeters: the
@@ -431,7 +431,7 @@ Function::GenerateIR() {
// If the function is 'export'-qualified, emit a second version of
// it without a mask parameter and without name mangling so that
// the application can call it
const FunctionType *type = dynamic_cast<const FunctionType *>(sym->type);
const FunctionType *type = CastType<FunctionType>(sym->type);
Assert(type != NULL);
if (type->isExported) {
if (!type->isTask) {