Skip to content

Commit

Permalink
[Matrix] Add LowerMatrixIntrinsics to the NPM
Browse files Browse the repository at this point in the history
Pass LowerMatrixIntrinsics wasn't running yet running under the new pass
manager, and this adds LowerMatrixIntrinsics to the pipeline (to the
same place as where it is running in the old PM).

Differential Revision: https://reviews.llvm.org/D84180
  • Loading branch information
Sjoerd Meijer committed Jul 22, 2020
1 parent b96114c commit 5567c62
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
8 changes: 8 additions & 0 deletions clang/lib/CodeGen/BackendUtil.cpp
Expand Up @@ -74,6 +74,7 @@
#include "llvm/Transforms/ObjCARC.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "llvm/Transforms/Scalar/LowerMatrixIntrinsics.h"
#include "llvm/Transforms/Utils.h"
#include "llvm/Transforms/Utils/CanonicalizeAliases.h"
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
Expand Down Expand Up @@ -1372,6 +1373,13 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
}

if (CodeGenOpts.OptimizationLevel == 0) {
// FIXME: the backends do not handle matrix intrinsics currently. Make
// sure they are also lowered in O0. A lightweight version of the pass
// should run in the backend pipeline on demand.
if (LangOpts.MatrixTypes)
MPM.addPass(
createModuleToFunctionPassAdaptor(LowerMatrixIntrinsicsPass()));

addCoroutinePassesAtO0(MPM, LangOpts, CodeGenOpts);
addSanitizersAtO0(MPM, TargetTriple, LangOpts, CodeGenOpts);
}
Expand Down
28 changes: 28 additions & 0 deletions clang/test/CodeGen/matrix-lowering-opt-levels.c
@@ -0,0 +1,28 @@
// RUN: %clang -O0 -fenable-matrix -S -emit-llvm %s -o - | FileCheck %s
// RUN: %clang -O1 -fenable-matrix -S -emit-llvm %s -o - | FileCheck %s
// RUN: %clang -O2 -fenable-matrix -S -emit-llvm %s -o - | FileCheck %s
// RUN: %clang -O3 -fenable-matrix -S -emit-llvm %s -o - | FileCheck %s
// RUN: %clang -Ofast -fenable-matrix -S -emit-llvm %s -o - | FileCheck %s
// RUN: %clang -Os -fenable-matrix -S -emit-llvm %s -o - | FileCheck %s
// RUN: %clang -Oz -fenable-matrix -S -emit-llvm %s -o - | FileCheck %s

// RUN: %clang -O0 -fenable-matrix -fexperimental-new-pass-manager -S -emit-llvm %s -o - | FileCheck %s
// RUN: %clang -O1 -fenable-matrix -fexperimental-new-pass-manager -S -emit-llvm %s -o - | FileCheck %s
// RUN: %clang -O2 -fenable-matrix -fexperimental-new-pass-manager -S -emit-llvm %s -o - | FileCheck %s
// RUN: %clang -O3 -fenable-matrix -fexperimental-new-pass-manager -S -emit-llvm %s -o - | FileCheck %s
// RUN: %clang -Ofast -fenable-matrix -fexperimental-new-pass-manager -S -emit-llvm %s -o - | FileCheck %s
// RUN: %clang -Os -fenable-matrix -fexperimental-new-pass-manager -S -emit-llvm %s -o - | FileCheck %s
// RUN: %clang -Oz -fenable-matrix -fexperimental-new-pass-manager -S -emit-llvm %s -o - | FileCheck %s

// Smoke test that the matrix intrinsics are lowered at any optimisation level.

typedef float m4x4_t __attribute__((matrix_type(4, 4)));

m4x4_t f(m4x4_t a, m4x4_t b, m4x4_t c) {
//
// CHECK-LABEL: f(
// CHECK-NOT: @llvm.matrix
// CHECK: }
//
return a + b * c;
}
7 changes: 7 additions & 0 deletions llvm/lib/Passes/PassBuilder.cpp
Expand Up @@ -275,6 +275,8 @@ extern cl::opt<bool> FlattenedProfileUsed;
extern cl::opt<AttributorRunOption> AttributorRun;
extern cl::opt<bool> EnableKnowledgeRetention;

extern cl::opt<bool> EnableMatrix;

const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::O0 = {
/*SpeedLevel*/ 0,
/*SizeLevel*/ 0};
Expand Down Expand Up @@ -1093,6 +1095,11 @@ ModulePassManager PassBuilder::buildModuleOptimizationPipeline(
OptimizePM.addPass(Float2IntPass());
OptimizePM.addPass(LowerConstantIntrinsicsPass());

if (EnableMatrix) {
OptimizePM.addPass(LowerMatrixIntrinsicsPass());
OptimizePM.addPass(EarlyCSEPass());
}

// FIXME: We need to run some loop optimizations to re-rotate loops after
// simplify-cfg and others undo their rotation.

Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
Expand Up @@ -149,9 +149,9 @@ cl::opt<bool> EnableOrderFileInstrumentation(
"enable-order-file-instrumentation", cl::init(false), cl::Hidden,
cl::desc("Enable order file instrumentation (default = off)"));

static cl::opt<bool>
EnableMatrix("enable-matrix", cl::init(false), cl::Hidden,
cl::desc("Enable lowering of the matrix intrinsics"));
cl::opt<bool> EnableMatrix(
"enable-matrix", cl::init(false), cl::Hidden,
cl::desc("Enable lowering of the matrix intrinsics"));

cl::opt<AttributorRunOption> AttributorRun(
"attributor-enable", cl::Hidden, cl::init(AttributorRunOption::NONE),
Expand Down

0 comments on commit 5567c62

Please sign in to comment.